Repository navigation
Expand file tree
/
Copy pathdocker-compose.dev.yml
More file actions
1963 lines (1911 loc) · 82.5 KB
/
Copy pathdocker-compose.dev.yml
File metadata and controls
1963 lines (1911 loc) · 82.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
services:
# ONE instance, six logical databases — crm_db, allocation_key_local,
# simulation_key_local, news_board_local, billing_local and
# administrative_document_local — each owned by its own login role.
#
# NOT one database with six schemas. Every service in the platform documents
# "cross-DB references are plain columns, never foreign keys", and separate
# databases are what enforce that by physics; merge them and someone
# eventually adds a real FK across a service boundary and the separation rots
# silently. Consolidating the INSTANCES keeps the boundary and still gives
# back five postmasters and five host ports.
#
# keycloak-db below stays its own container: Keycloak manages its own schema
# and runs its own migrations at boot, and it is the one blast radius we are
# not merging into the application's.
#
# See postgres/README.md.
postgres:
profiles: ["dev"]
image: postgres:18-alpine@sha256:4da1a4828be12604092fa55311276f08f9224a74a62dcb4708bd7439e2a03911
restart: unless-stopped
# max_connections=300. The configured pools now all point at ONE instance:
# 9 Python processes x (CRM 5+5 + LOCAL 5+5) = 180
# notification-dispatch (CRM only, 5+5) = 10
# crm-backend (node-postgres default max) = 10
# ---
# 200
# Seven instances each had their own default max_connections=100, so the
# ceiling was never met anywhere and nobody noticed. One instance meets all
# of it at once, and 100 is not enough. 300 = 200 + 3 superuser-reserved +
# headroom for postgres-init, the verify scripts, a human psql, and the
# overlap while compose recreates a container.
#
# shared_buffers=256MB — the seven instances reserved 7 x 128 MB between
# them; one at 256 MB is under a third of that.
command:
- "postgres"
- "-c"
- "max_connections=300"
- "-c"
- "shared_buffers=256MB"
environment:
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
- POSTGRES_PASSWORD=${POSTGRES_SUPERUSER_PASSWORD}
# Parallel query allocates its dynamic shared memory in /dev/shm. Docker's
# 64 MB default is what turns a large allocation-key run into "could not
# resize shared memory segment".
shm_size: 256mb
# NOTHING is mounted into /docker-entrypoint-initdb.d, deliberately: those
# scripts run only on an empty data directory and only against POSTGRES_DB,
# so they can neither converge a rotated password nor reach a second
# database. postgres-init below is the single provisioning path.
#
# No volume either, deliberately — dev databases stay ephemeral exactly as
# they were, re-seeded from the mounted SQL on a fresh container.
ports:
- "8080:5432"
networks:
- backend
healthcheck:
# -h localhost (TCP) on purpose: the image entrypoint runs its bootstrap
# phase with listen_addresses='', so only a TCP probe is correctly red
# until the FINAL server is accepting. That is what makes
# `service_healthy` meaningful for the sidecar.
test:
[
"CMD-SHELL",
"pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB -h localhost || exit 1",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
# Roles, databases, schemas, seeds and grants — converged on EVERY `up`,
# mirroring minio-init. Same pinned image as the server, so psql matches the
# server version exactly and there is no extra image to pull.
#
# profiles: ["dev"] only, NOT ["init", "dev"]: docker-stack.sh's init pass
# ends with `--profile init ... down`, which would tear the server back down.
#
# If this container exits non-zero the whole stack refuses to start, by
# design — a missing CRM grant produces no application error at all (the
# annexes swallow it), so a half-provisioned instance would be invisible.
postgres-init:
profiles: ["dev"]
image: postgres:18-alpine@sha256:4da1a4828be12604092fa55311276f08f9224a74a62dcb4708bd7439e2a03911
depends_on:
postgres:
condition: service_healthy
environment:
- PGHOST=postgres
- PGPORT=5432
- PGUSER=postgres
- PGDATABASE=postgres
- PGPASSWORD=${POSTGRES_SUPERUSER_PASSWORD}
- CRM_DB_PASSWORD=${CRM_DB_PASSWORD}
- ALLOCATION_KEY_DB_PASSWORD=${ALLOCATION_KEY_DB_PASSWORD}
- SIMULATION_KEY_DB_PASSWORD=${SIMULATION_KEY_DB_PASSWORD}
- NEWS_BOARD_DB_PASSWORD=${NEWS_BOARD_DB_PASSWORD}
- BILLING_DB_PASSWORD=${BILLING_DB_PASSWORD}
- ADMINISTRATIVE_DOCUMENT_DB_PASSWORD=${ADMINISTRATIVE_DOCUMENT_DB_PASSWORD}
- NOTIFICATION_DISPATCH_DB_PASSWORD=${NOTIFICATION_DISPATCH_DB_PASSWORD}
- LIVE_DATA_DB_PASSWORD=${LIVE_DATA_DB_PASSWORD}
- SIGNATURE_DB_PASSWORD=${SIGNATURE_DB_PASSWORD}
entrypoint: ["/bin/sh", "/postgres/provision/provision.sh"]
volumes:
- ./postgres:/postgres:ro
# One mount per database, named by DATABASE and never by repo path — that
# indirection is what lets production run the same provision.sh against a
# different source (database_script/init.sql, or nothing at all before a
# pg_restore) with no edit. Every file is reused verbatim; this workstream
# forks none of them.
#
# NOTE: crm_db.sql opens with `DROP SCHEMA IF EXISTS public CASCADE` and
# carries the demo seed data. provision.sh applies it ONLY when the
# database has no tables — remove that guard and a restart wipes your
# local CRM data.
- ./crm-backend/tests/sql/init.sql:/schemas/crm_db.sql:ro
- ./allocation-key-generation/scripts/sql/schema.sql:/schemas/allocation_key_local.sql:ro
- ./simulation-key/scripts/sql/schema.sql:/schemas/simulation_key_local.sql:ro
- ./news-board/scripts/sql/schema.sql:/schemas/news_board_local.sql:ro
- ./billing/scripts/sql/schema.sql:/schemas/billing_local.sql:ro
- ./administrative-document/scripts/sql/schema.sql:/schemas/administrative_document_local.sql:ro
# If this path is missing, Docker CREATES AN EMPTY DIRECTORY here and
# provision.sh logs "schema skipped" and exits 0 - leaving a
# health-green service over a database with no tables. live-data's
# /health/readiness reads schema_version rather than SELECT 1 so that
# this fails loudly instead.
- ./live-data/scripts/sql/schema.sql:/schemas/live_data_local.sql:ro
- ./signature/scripts/sql/schema.sql:/schemas/signature_local.sql:ro
# Whole directory, applied in filename order AFTER the schema and on every
# run: these are region reference data (deadline rules + the template
# catalogue), idempotent by construction, and 0003 updates rows 0002
# creates.
- ./administrative-document/scripts/sql/seeds:/seeds/administrative_document_local:ro
networks:
- backend
# The one database instance that is NOT consolidated. Keycloak manages its own
# schema and runs its own migrations at boot, so its blast radius stays its
# own. A useful side effect: the six service roles above cannot even resolve a
# network route to this instance, which is a stronger guarantee than any
# REVOKE inside a shared server.
keycloak-db:
profiles: ["dev"]
image: postgres:18-alpine@sha256:4da1a4828be12604092fa55311276f08f9224a74a62dcb4708bd7439e2a03911
restart: unless-stopped
environment:
- POSTGRES_USER=postgres
- POSTGRES_DB=keycloak
- POSTGRES_PASSWORD=${KEYCLOAK_DB_PASSWORD}
ports:
- "8081:5432"
networks:
- backend
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB -h localhost || exit 1",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
keycloak:
profiles: ["dev"]
build:
context: keycloak
dockerfile: Dockerfile
restart: unless-stopped
command:
[
"start-dev",
"--import-realm",
"--verbose",
"--proxy-headers=xforwarded",
"--http-relative-path=/keycloak",
]
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD}
- KEYCLOAK_IMPORT=/opt/keycloak/data/import/realm-config.json
- KC_DB=postgres
- KC_DB_URL=jdbc:postgresql://keycloak-db:5432/keycloak
- KC_DB_USERNAME=postgres
- KC_DB_PASSWORD=${KEYCLOAK_DB_PASSWORD}
- KC_HOSTNAME=${KEYCLOAK_HOSTNAME}
- KC_HOSTNAME_PORT=8087
- KC_HTTP_ENABLED=true
- KC_BOOTSTRAP_ADMIN_USERNAME=admin
- KC_BOOTSTRAP_ADMIN_PASSWORD=${KEYCLOAK_BOOTSTRAP_ADMIN_PASSWORD}
ports:
- "8082:8080"
networks:
- backend
- reverse-proxy
depends_on:
keycloak-db:
condition: service_healthy
keycloak-config:
condition: service_completed_successfully
volumes:
- ./keycloak/realm/dev-config.json:/opt/keycloak/data/import/realm-config.json
minio:
profiles: ["dev"]
image: pgsty/minio:latest
command: server /data --console-address ":9001"
restart: unless-stopped
environment:
- MINIO_ROOT_USER=${MINIO_ROOT_USER:-minioadmin}
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD:-minioadmin}
ports:
- "8091:9000"
- "8092:9001"
volumes:
- minio_data:/data
networks:
- backend
- reverse-proxy
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
minio-init:
profiles: ["dev"]
image: pgsty/mc:latest
depends_on:
minio:
condition: service_healthy
environment:
- MINIO_ROOT_USER=${MINIO_ROOT_USER:-minioadmin}
- MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD:-minioadmin}
- STORAGE_BUCKET=${STORAGE_BUCKET:-crm-files}
- TEMPLATES_BUCKET=${TEMPLATES_BUCKET:-optimce-templates}
- OUTPUT_BUCKET=${OUTPUT_BUCKET:-optimce-documents}
entrypoint: >
/bin/sh -c "
sleep 5;
mc alias set local ${STORAGE_API_URL} $${MINIO_ROOT_USER:-minioadmin} $${MINIO_ROOT_PASSWORD:-minioadmin};
mc mb --ignore-existing local/$${STORAGE_BUCKET:-crm-files};
mc mb --ignore-existing local/$${TEMPLATES_BUCKET:-optimce-templates};
mc mb --ignore-existing local/$${OUTPUT_BUCKET:-optimce-documents};
mc cp --recursive /templates/billing local/$${TEMPLATES_BUCKET:-optimce-templates}/;
mc cp --recursive /templates-admin/administrative-document local/$${TEMPLATES_BUCKET:-optimce-templates}/;
mc cp --recursive /templates-signature/signature local/$${TEMPLATES_BUCKET:-optimce-templates}/;
exit 0;
"
volumes:
# One mount per owning service: each ships the bundles for its own
# documents, and the directory name inside becomes the key prefix
# (`mc cp` of a directory preserves it), which is what
# document_template.file_ref / *_TEMPLATE_URI point at.
#
# NOTE: this is `cp`, not `sync` — and document-generation caches bundles
# on disk keyed by URI with no invalidation. Re-uploading to an existing
# versioned prefix therefore has no effect until you
# `up --force-recreate document-generation`. Bump the version directory
# instead.
- ./billing/document-templates:/templates:ro
- ./administrative-document/document-templates:/templates-admin:ro
- ./signature/document-templates:/templates-signature:ro
networks:
- backend
nats:
profiles: ["dev"]
image: nats:2.10-alpine
restart: unless-stopped
command: ["-js", "-m", "8222", "-sd", "/data"]
ports:
- "8094:4222"
- "8095:8222"
volumes:
- nats_data:/data
networks:
- backend
healthcheck:
test:
[
"CMD-SHELL",
"wget -q -O - 'http://localhost:8222/healthz?js-enabled-only=true' || exit 1",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
# Realtime fan-out ONLY: SSE pub/sub on `notify:v1:*` plus the single-use SSE
# tickets. Deliberately NOT the JetStream broker above — job dispatch must not
# lose messages, realtime is ALLOWED to. A separate container makes "realtime
# may drop" structurally true and stops anyone making it durable later.
#
# No volume, no AOF, no RDB: every key here is either a <=30s ticket or an
# in-flight PUBLISH, so losing everything on restart is CORRECT behaviour.
# `--save ""` also removes the fork-on-BGSAVE latency spike.
#
# --requirepass is NOT hygiene. Redis has no auth by default, this sits on the
# `backend` network alongside nine services, and the LIVE TICKET STORE lives in
# it: unauthenticated, anything on that network could read every in-flight
# ticket with its channel list and impersonate any connecting user.
#
# env_file is load-bearing: the healthcheck's `$$REDIS_PASSWORD` expands inside
# the container, so without it redis-cli authenticates with an empty password,
# never returns PONG, and crm-backend (which gates on service_healthy) never
# starts.
redis:
profiles: ["dev"]
image: redis:8-alpine@sha256:978f0e01593e65eed801f2402944efcd936d43b5027e4908a7897baf88ed6241
restart: unless-stopped
env_file:
- .env.dev
command:
- "redis-server"
- "--save"
- ""
- "--appendonly"
- "no"
- "--maxmemory"
- "128mb"
- "--maxmemory-policy"
- "allkeys-lru"
- "--requirepass"
- "${REDIS_PASSWORD}"
# Loopback-only: published solely so the redis-cli verification recipes in
# docs/runbooks work from the host. Nothing outside the host needs it.
ports:
- "127.0.0.1:8093:6379"
networks:
- backend
healthcheck:
test:
[
"CMD-SHELL",
"redis-cli --no-auth-warning -a \"$$REDIS_PASSWORD\" ping | grep -q PONG",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
jaeger:
profiles: ["dev"]
image: jaegertracing/jaeger:latest@sha256:bf7f805da4c2bc8d58a6c81ee650fdb6b8e4287698f95fbe231c09c865bc397f
restart: unless-stopped
ports:
- "8084:6831/udp"
- "8085:16686"
environment:
- COLLECTOR_OTLP_ENABLED=true
networks:
- backend
# The federal BeSt Address register (FPS BOSA), self-contained.
#
# Part of the dev profile, so ./docker-stack.sh start brings it up with
# everything else. Budget for it: the image is 1.6 GB and the container settles
# around 1.7 GB resident. On Docker Desktop that usually means raising the WSL2
# ceiling first (%UserProfile%\.wslconfig -> memory=12GB, then wsl --shutdown).
#
# There is deliberately NO depends_on from crm-backend, even though both are
# now in the same profile. The healthcheck below waits for the address table to
# be paged in, which takes ~45 s on a cold start — making the backend wait for
# that would add three quarters of a minute to every single stack start, to
# gate a feature that degrades to "no suggestions" on its own. crm-backend
# discovers this service at runtime: with BEST_ADDRESS_URL blank, or the
# container down, the picker is unbound and every form behaves as it did
# before the feature existed.
#
# Data is baked into the image, so a `docker pull` IS the address-data refresh
# — which is exactly why the reference below is pinned by digest. An unpinned
# tag would mean the addresses under you change silently on someone else's
# pull, and this dataset is what the map and the picker are BUILT on.
# Renovate raises the refresh as an ordinary reviewable dependency PR instead:
# .github/renovate.json extends docker:pinDigests, and carries the versioning
# rule that teaches it to read this publisher's YYYY-WW tags.
#
# Licence: the address data is CC-BY 4.0. Attribution is required — Service
# public de Wallonie, Paradigm.Brussels, Digitaal Vlaanderen.
best-address:
profiles: ["dev"]
# 2026-35 = the ISO week-35 2026 extract, published 2026-08-31. `latest`
# pointed at this same digest when it was pinned, verified against the
# registry with `docker buildx imagetools inspect`.
image: bosa/opendata-best-webapi:2026-35@sha256:371165f3e370e3d8476202bacea4c74bcbc8a02f944671b968826bcd64b6cf18
restart: unless-stopped
environment:
- SERVER_PORT=8080
# Do NOT set PGOPTIONS here. The image's CMD is
# pg_ctl start -D $$PGDATA $$PGOPTIONS && java -jar best-webapi.jar
# with the variable UNQUOTED, so the value is word-split into raw pg_ctl
# arguments — not server settings. `-c shared_buffers=512MB` makes pg_ctl
# exit with "too many command-line arguments" and, with restart:
# unless-stopped and nothing depending on this service, the container then
# crash-loops in silence. Server tuning would have to go through `-o`, and
# the unquoted expansion means `-o` can carry exactly one space-free
# argument. The image's own defaults are fine: measured at ~1.65 GB
# resident and sub-100 ms queries once warm.
# Loopback-only, like crm-backend: this is reference data with no auth of
# its own, and nothing outside the host has any business reaching it.
ports:
- "127.0.0.1:8096:8080"
networks:
- backend
healthcheck:
# NOT just /health. The first /addresses read after a cold start took 56
# SECONDS (Postgres paging the address table in) against 0.09 s once warm,
# and KrakenD's global timeout is 3000 ms — so a box that answers /health
# but has never touched the address table is not ready in any useful
# sense, and the first person to type an address would get a 504.
#
# curl, not wget: this image has no wget, and a probe that can never pass
# leaves the container `starting` forever and then permanently unhealthy,
# while the service underneath works perfectly. --max-time stays under the
# `timeout` below so curl gives up before Docker kills it.
test:
[
"CMD-SHELL",
"curl -fsS --max-time 85 -o /dev/null 'http://localhost:8080/belgianAddress/v2/addresses?postCode=1000&page=1'",
]
interval: 30s
timeout: 90s
retries: 5
start_period: 120s
# The internal GRD lookup: which network operator (GRD/DSO) serves a Belgian
# address, for the GRD prefill of the meter form. Built from ./dso-lookup, a
# FastAPI service on billing's conventions that is NOT an annex:
# - only crm-backend calls it, over `backend`, the way it calls best-address;
# - it has no *-doc-gen, no krakend-builder.yaml entry and no place in
# krakend-config's depends_on. The gateway only sees crm-backend's own
# /dso/* routes, which travel in crm-backend's swagger like any CRM route;
# - it must NEVER be named in ANNEX_CATALOG_ENABLE/DISABLE: a name the
# catalogue does not contain refuses crm-backend's boot.
#
# There is deliberately NO depends_on from crm-backend, as for best-address.
# POST /meters never calls it: with DSO_LOOKUP_URL blank or this container
# down, GET /dso/resolve answers `status: unavailable` and the meter form keeps
# its plain GRD select. Nothing is ever blocked on it.
#
# The data (a pinned belgian-dso-map release, dso-lookup/data/) is baked into
# the image, so a rebuild IS the data refresh. A new release arrives as the
# weekly bump PR in OptimCE/dso-lookup, reviewed there like any code change.
#
# Loopback-only, like best-address: it has no authentication of its own. The
# port is for curl checks (/health/readiness, /dso/meta) from the host.
dso-lookup:
profiles: ["dev"]
build:
context: dso-lookup
dockerfile: Dockerfile
restart: unless-stopped
environment:
- ENV=local
ports:
- "127.0.0.1:8097:8000"
networks:
- backend
healthcheck:
# Readiness is red until the CSV data has loaded and checked out; a bad
# data directory fails the boot outright rather than serving nothing.
test:
- "CMD-SHELL"
- "python -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/health/readiness', timeout=3).status==200 else 1)\""
interval: 15s
timeout: 5s
retries: 5
start_period: 20s
swagger-doc-gen:
profiles: ["init", "dev"]
build:
context: crm-backend
dockerfile: Dockerfile.dev
volumes:
- ./krakend/config:/app/docs/openapi
# No `sleep` between the two: swagger-autogen writes with fs.writeFileSync, so the
# file is closed before the promise settles, and the `mv` runs in THIS container
# through the same mount — there is no flush to wait on. A sleep here also could
# never have helped krakend-config see the result, since it precedes the rename.
# It used to be `&& sleep 3 &&`, and those three seconds were the window the init
# profile's abort cascade used to SIGKILL this container in. See docker-stack.sh.
command: sh -c "npm run swagger && mv /app/docs/openapi/swagger.yaml /app/docs/openapi/root.yaml"
generation-doc-gen:
profiles: ["init", "dev"]
build:
context: allocation-key-generation
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint: ["python", "scripts/export_openapi.py", "/output/generation.json"]
simulation-doc-gen:
profiles: ["init", "dev"]
build:
context: simulation-key
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint: ["python", "scripts/export_openapi.py", "/output/simulation.json"]
news-doc-gen:
profiles: ["init", "dev"]
build:
context: news-board
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint: ["python", "scripts/export_openapi.py", "/output/news.json"]
billing-doc-gen:
profiles: ["init", "dev"]
build:
context: billing
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint: ["python", "scripts/export_openapi.py", "/output/billing.json"]
administrative-document-doc-gen:
profiles: ["init", "dev"]
build:
context: administrative-document
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint:
["python", "scripts/export_openapi.py", "/output/administrative-document.json"]
# TWO OpenAPI files out of ONE app, because KrakenD gates its JWT validator
# per SERVICE ENTRY and never per endpoint - so the public enrol route needs
# its own `services:` key with `auth: false`, and that needs its own swagger.
#
# `--split` refuses to write EITHER file unless the public operation set
# equals the literal declared in api/live_public/routes.py, and it unlinks
# both targets before writing: ./krakend/config is a gitignored bind mount
# that is never cleaned, so a half-finished run would otherwise leave a stale
# live-public.json for krakend-config to merge while printing "Success!".
signature-doc-gen:
profiles: ["init", "dev"]
build:
context: signature
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint: ["python", "scripts/export_openapi.py", "/output/signature.json"]
live-data-doc-gen:
profiles: ["init", "dev"]
build:
context: live-data
dockerfile: Dockerfile
volumes:
- ./krakend/config:/output
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- LOCAL_DATABASE_URL=postgresql+asyncpg://placeholder:placeholder@placeholder:5432/placeholder
- ALLOW_ORIGIN=*
entrypoint:
[
"python",
"scripts/export_openapi.py",
"--split",
"/output/live.json",
"/output/live-public.json",
]
krakend-config:
profiles: ["init", "dev"]
build:
context: krakend/swagger2krakend
dockerfile: Dockerfile
volumes:
- ./krakend/config:/config
environment:
- CONFIG_FILE=/config/krakend-builder.yaml
- OUTPUT_FILE=/config/krakend.json
depends_on:
swagger-doc-gen:
condition: service_completed_successfully
generation-doc-gen:
condition: service_completed_successfully
simulation-doc-gen:
condition: service_completed_successfully
news-doc-gen:
condition: service_completed_successfully
billing-doc-gen:
condition: service_completed_successfully
administrative-document-doc-gen:
condition: service_completed_successfully
live-data-doc-gen:
condition: service_completed_successfully
signature-doc-gen:
condition: service_completed_successfully
krakend:
profiles: ["dev"]
image: krakend:latest@sha256:bd392b692271209927da6c62f1b42d7f8f7bd0cd60b00d97c93bb5b8d42b4999
# Without a restart policy the gateway, and with it every /api route,
# stayed down after a host reboot, a Docker daemon restart or a crash.
restart: unless-stopped
ports:
- "8086:8080"
volumes:
- ./krakend/config:/etc/krakend
networks:
- backend
- reverse-proxy
depends_on:
crm-backend:
condition: service_started
allocation-key-generation:
condition: service_started
simulation-key:
condition: service_started
optimce-news-board:
condition: service_started
billing:
condition: service_started
administrative-document:
condition: service_started
live-data:
condition: service_started
signature:
condition: service_started
keycloak:
condition: service_started
reverse-proxy:
profiles: ["dev"]
image: nginx:latest@sha256:7150b3a39203cb5bee612ff4a9d18774f8c7caf6399d6e8985e97e28eb751c18
# Without a restart policy the public entry point stayed down after a host
# reboot, a Docker daemon restart or a crash. nginx resolves its upstreams
# (crm-backend, krakend, keycloak, ...) at start: started before them, it
# exits and is restarted until they resolve.
restart: unless-stopped
ports:
- "8087:80"
- "8088:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/certs:/etc/nginx/certs
networks:
- reverse-proxy
# For `location = /realtime/stream` only — see the `sse` network comment.
- sse
depends_on:
nginx-config:
condition: service_completed_successfully
krakend:
condition: service_started
crm-backend:
profiles: ["dev"]
build:
context: crm-backend
dockerfile: Dockerfile.dev
command: npm run dev
restart: unless-stopped
environment:
- NODE_ENV=production
- PORT=80
- MICROSERVICE_NAME=crm-backend
- ALLOWED_ORIGIN=${APP_CORS_ALLOWED_ORIGIN}
- SERVER_HOST=0.0.0.0
- SERVER_PORT=80
- IAM_SERVICE_NAME=KEYCLOAK
- IAM_REALM=optimce-realm
- IAM_REALM_NAME=optimce-realm
- IAM_BASE_URL=http://keycloak:8080/keycloak
- IAM_CLIENT_ID=optimce-backend
- IAM_GRANT_TYPE=client_credentials
- IAM_CLIENT_SECRET=${AUTH_CLIENT_SECRET}
- STORAGE_SERVICE_NAME=S3
- STORAGE_ENDPOINT=${STORAGE_API_URL}
- STORAGE_REGION=us-east-1
- STORAGE_BUCKET=${STORAGE_BUCKET:-crm-files}
- STORAGE_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
- STORAGE_SECRET_KEY=${MINIO_ROOT_PASSWORD:-minioadmin}
- STORAGE_PUBLIC_ENDPOINT=${MINIO_PUBLIC_ENDPOINT}
- REMOTE_LOGGING=${REMOTE_LOGGING}
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT}
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
# The only service that configures its database with discrete variables
# rather than a DSN: config/{development,production}.cjs map these five and
# there is no url: option on the TypeORM DataSource. (Which of the two
# applies is decided by `npm run dev`, which forces NODE_ENV=development
# over the value set above — they read the same five variables, so it makes
# no difference here beyond the unused fallbacks.)
#
# DB_TYPE used to be on this list and was read by nothing:
# database.connector.ts hardcodes type: "postgres".
#
# crm_svc OWNS crm_db, its `public` schema and every table in it — the
# sidecar applies the schema under SET ROLE crm_svc. That is what keeps the
# hand-applied database_script/*.sql migrations working, and what makes
# ALTER DEFAULT PRIVILEGES in 30-crm-grants.sql attach to the right role.
- DB_HOST=postgres
- DB_PORT=5432
- DB_USERNAME=crm_svc
- DB_PASSWORD=${CRM_DB_PASSWORD}
- DB_NAME=crm_db
- REGULATORS_CONFIG_PATH=/app/reference/regulators.json
# Realtime (SSE). db 1 on purpose: db 0 stays reserved for the currently
# dormant cache_service, which is a DIFFERENT switch — see
# src/container/factory/realtime.factory.ts. With REALTIME_ENABLED=false
# nothing is bound, no connection is opened, and clients stay on polling.
- REALTIME_ENABLED=${REALTIME_ENABLED}
- REALTIME_REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/1
- REALTIME_TICKET_TTL_SECONDS=${REALTIME_TICKET_TTL_SECONDS}
- REALTIME_MAX_CONNECTION_SECONDS=${REALTIME_MAX_CONNECTION_SECONDS}
- REALTIME_MAX_CONNECTIONS_PER_USER=${REALTIME_MAX_CONNECTIONS_PER_USER}
# Address geocoding + the BeSt Address picker. These keys were read by the
# code from the day geocoding shipped but never surfaced here, so the
# service ran on its compiled-in defaults and GEOCODING_MODE=REMOTE could
# only be set by editing the file.
#
# BEST_ADDRESS_URL blank == the picker is OFF. It defaults to the
# `best-address` service, which now starts with the rest of the stack, so
# the feature works out of the box. The `-` (not `:-`) form fills in only
# when the variable is UNSET, which is what lets a deliberately blank value
# in .env.dev still turn the feature off.
- GEOCODING_MODE=${GEOCODING_MODE:-LOCAL}
- GEOCODING_TIMEOUT_MS=${GEOCODING_TIMEOUT_MS:-2000}
- GEOCODING_BATCH_MAX=${GEOCODING_BATCH_MAX:-1000}
- GEOCODING_BACKFILL_OPERATORS=${GEOCODING_BACKFILL_OPERATORS:-}
- BEST_ADDRESS_URL=${BEST_ADDRESS_URL-http://best-address:8080/belgianAddress/v2}
- BEST_ADDRESS_TIMEOUT_MS=${BEST_ADDRESS_TIMEOUT_MS:-1500}
# The internal GRD lookup (the `dso-lookup` service above). Same `-` form
# and same contract as BEST_ADDRESS_URL: blank == OFF (GET /dso/resolve
# answers `status: unavailable` and the meter form keeps its plain GRD
# select), and a deleted line falls back to this default. No depends_on,
# for the reasons given on the service. 1000 ms because one resolve makes
# at most two sequential calls, and both must fit KrakenD's 3000 ms.
- DSO_LOOKUP_URL=${DSO_LOOKUP_URL-http://dso-lookup:8000}
- DSO_LOOKUP_TIMEOUT_MS=${DSO_LOOKUP_TIMEOUT_MS:-1000}
# Annex catalogue. config/annexes-services.json is baked into the image and
# shared with production, so an annex whose service is not deployed
# everywhere ships "defaultEnabled": false and a deployment opts in here.
# DISABLE wins over ENABLE. A name the image's catalogue does not contain
# refuses the boot; under `tsx watch` only the log says so (operation
# annexes_services:catalog_overrides). The set served is logged once at
# boot as annexes_services:catalog_loaded. Values: see .env.dev.
- ANNEX_CATALOG_ENABLE=${ANNEX_CATALOG_ENABLE:-}
- ANNEX_CATALOG_DISABLE=${ANNEX_CATALOG_DISABLE:-}
volumes:
- ./reference:/app/reference:ro
# Loopback-only. crm-backend performs NO authentication of its own — it
# trusts x-user-id blindly (shared/middlewares/context.ts) — so a port
# reachable off-host is an unauthenticated, cross-tenant read/write API.
# Reach it through the reverse proxy (8087) instead.
ports:
- "127.0.0.1:8089:80"
# `sse` exists solely so reverse-proxy can reach this service for
# `location = /realtime/stream`. Deliberately NOT the `reverse-proxy`
# network: that also holds crm-frontend, and a compromised static frontend
# must not be able to call this API with forged x-user-id headers.
networks:
- backend
- sse
depends_on:
postgres-init:
condition: service_completed_successfully
minio-init:
condition: service_completed_successfully
jaeger:
condition: service_started
redis:
condition: service_healthy
# The core's outbox relay (crm-backend/src/outbox-relay.ts): publishes the
# rows crm-backend writes to outbox_event, in the same transaction as the CRM
# change, onto JetStream `core.evt.<type>` (stream CORE_EVENTS, which this
# service creates and owns). Same image as crm-backend, its own process: an
# API restart never stalls the relay, and the relay never competes with
# requests. The administrative annexe's worker consumes the stream.
#
# Same DB variables and role as crm-backend: the relay only reads and stamps
# crm_db.outbox_event. The healthcheck reads the heartbeat the loop touches on
# every turn (also while idle), so a wedged loop shows as unhealthy.
crm-outbox-relay:
profiles: ["dev"]
build:
context: crm-backend
dockerfile: Dockerfile.dev
command: npm run relay:dev
restart: unless-stopped
environment:
- MICROSERVICE_NAME=crm-outbox-relay
- REMOTE_LOGGING=${REMOTE_LOGGING}
- OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT}
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
- DB_HOST=postgres
- DB_PORT=5432
- DB_USERNAME=crm_svc
- DB_PASSWORD=${CRM_DB_PASSWORD}
- DB_NAME=crm_db
- REGULATORS_CONFIG_PATH=/app/reference/regulators.json
- NATS_URL=nats://nats:4222
- OUTBOX_RELAY_POLL_INTERVAL_MS=${OUTBOX_RELAY_POLL_INTERVAL_MS:-500}
- OUTBOX_STREAM_MAX_AGE_DAYS=${OUTBOX_STREAM_MAX_AGE_DAYS:-30}
volumes:
- ./reference:/app/reference:ro
networks:
- backend
healthcheck:
test: ["CMD-SHELL", "find /tmp/outbox-relay.alive -mmin -1 | grep -q . || exit 1"]
interval: 15s
timeout: 5s
retries: 4
start_period: 30s
depends_on:
postgres-init:
condition: service_completed_successfully
nats:
condition: service_healthy
allocation-key-generation:
profiles: ["dev"]
build:
context: allocation-key-generation
dockerfile: Dockerfile
restart: unless-stopped
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://allocation_key_svc:${ALLOCATION_KEY_DB_PASSWORD}@postgres:5432/crm_db
- LOCAL_DATABASE_URL=postgresql+asyncpg://allocation_key_svc:${ALLOCATION_KEY_DB_PASSWORD}@postgres:5432/allocation_key_local
- NATS_URL=nats://nats:4222
- ALLOW_ORIGIN=*
- CRM_DB_POOL_SIZE=5
- CRM_DB_MAX_OVERFLOW=5
- LOCAL_DB_POOL_SIZE=5
- LOCAL_DB_MAX_OVERFLOW=5
- STORAGE_ENDPOINT=${STORAGE_API_URL}
- STORAGE_BUCKET=${STORAGE_BUCKET:-crm-files}
- STORAGE_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
- STORAGE_SECRET_KEY=${MINIO_ROOT_PASSWORD:-minioadmin}
- STORAGE_REGION=us-east-1
# Realtime (SSE hints) — fire-and-forget. An empty/unreachable URL is a
# silent no-op: core/realtime/bus.py never raises and never blocks a write.
- REALTIME_ENABLED=${REALTIME_ENABLED}
- REALTIME_REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/1
ports:
- "8002:8000"
networks:
- backend
depends_on:
postgres-init:
condition: service_completed_successfully
nats:
condition: service_healthy
minio-init:
condition: service_completed_successfully
healthcheck:
test:
- "CMD-SHELL"
- "python -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/health/readiness', timeout=3).status==200 else 1)\""
interval: 15s
timeout: 5s
retries: 5
start_period: 45s
allocation-key-generation-worker:
profiles: ["dev"]
build:
context: allocation-key-generation
dockerfile: Dockerfile.worker
restart: unless-stopped
cpus: "2.0"
# One solver process (cpus - 1). OLAGSA refuses generations over 400,000
# participants x timesteps, which keeps a solve near 1 GB, plus ~0.3 GB for
# the worker itself; brute_force peaks near 0.2 GB at that limit. A solver
# killed for memory is retried a bounded number of times. Swap capped at
# the same value so a runaway solve is killed instead of thrashing the
# host. See allocation-key-generation's README, "Resource sizing".
mem_limit: 2g
memswap_limit: 2g
# 60 s to stop, not Docker's default 10. On SIGTERM the worker waits up to
# 25 s for in-flight runs to finish and ack, then drains its subscription
# and the NATS connection and flushes telemetry. At 10 s every
# `docker-stack.sh stop` / `restart` SIGKILLed it mid-drain, and an
# interrupted run was redelivered and solved again after its ack_wait.
# Same on the four other NATS workers below.
stop_grace_period: 60s
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://allocation_key_svc:${ALLOCATION_KEY_DB_PASSWORD}@postgres:5432/crm_db
- LOCAL_DATABASE_URL=postgresql+asyncpg://allocation_key_svc:${ALLOCATION_KEY_DB_PASSWORD}@postgres:5432/allocation_key_local
- NATS_URL=nats://nats:4222
- ALLOW_ORIGIN=*
- CRM_DB_POOL_SIZE=5
- CRM_DB_MAX_OVERFLOW=5
- LOCAL_DB_POOL_SIZE=5
- LOCAL_DB_MAX_OVERFLOW=5
- STORAGE_ENDPOINT=${STORAGE_API_URL}
- STORAGE_BUCKET=${STORAGE_BUCKET:-crm-files}
- STORAGE_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
- STORAGE_SECRET_KEY=${MINIO_ROOT_PASSWORD:-minioadmin}
- STORAGE_REGION=us-east-1
- OMP_NUM_THREADS=1
- OPENBLAS_NUM_THREADS=1
- MKL_NUM_THREADS=1
# Realtime (SSE hints) — fire-and-forget. An empty/unreachable URL is a
# silent no-op: core/realtime/bus.py never raises and never blocks a write.
- REALTIME_ENABLED=${REALTIME_ENABLED}
- REALTIME_REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/1
networks:
- backend
depends_on:
postgres-init:
condition: service_completed_successfully
nats:
condition: service_healthy
minio-init:
condition: service_completed_successfully
simulation-key:
profiles: ["dev"]
build:
context: simulation-key
dockerfile: Dockerfile
restart: unless-stopped
environment:
- ENV=local
- CRM_DATABASE_URL=postgresql+asyncpg://simulation_key_svc:${SIMULATION_KEY_DB_PASSWORD}@postgres:5432/crm_db
- LOCAL_DATABASE_URL=postgresql+asyncpg://simulation_key_svc:${SIMULATION_KEY_DB_PASSWORD}@postgres:5432/simulation_key_local
- NATS_URL=nats://nats:4222
- ALLOW_ORIGIN=*
- CRM_DB_POOL_SIZE=5
- CRM_DB_MAX_OVERFLOW=5
- LOCAL_DB_POOL_SIZE=5
- LOCAL_DB_MAX_OVERFLOW=5
- STORAGE_ENDPOINT=${STORAGE_API_URL}
- STORAGE_BUCKET=${STORAGE_BUCKET:-crm-files}
- STORAGE_ACCESS_KEY=${MINIO_ROOT_USER:-minioadmin}
- STORAGE_SECRET_KEY=${MINIO_ROOT_PASSWORD:-minioadmin}
- STORAGE_REGION=us-east-1
# Realtime (SSE hints) — fire-and-forget. An empty/unreachable URL is a
# silent no-op: core/realtime/bus.py never raises and never blocks a write.
- REALTIME_ENABLED=${REALTIME_ENABLED}
- REALTIME_REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/1
ports:
- "8003:8000"
networks:
- backend
depends_on:
postgres-init:
condition: service_completed_successfully
nats:
condition: service_healthy
minio-init:
condition: service_completed_successfully
healthcheck:
test:
- "CMD-SHELL"
- "python -c \"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/health/readiness', timeout=3).status==200 else 1)\""
interval: 15s
timeout: 5s
retries: 5
start_period: 45s