-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.swarm.ha.yml
More file actions
1483 lines (1429 loc) · 54.8 KB
/
docker-compose.swarm.ha.yml
File metadata and controls
1483 lines (1429 loc) · 54.8 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
# Obiente Cloud - High Availability Docker Swarm Configuration
# This setup supports distributed deployments across multiple nodes
# This file requires docker-compose.base.yml to be merged before use
# Usage: cat docker-compose.base.yml docker-compose.swarm.ha.yml | docker stack deploy -c - obiente
services:
# ============================================================================
# DISTRIBUTED DATABASE CLUSTER (PostgreSQL + Patroni)
# ============================================================================
# etcd - Distributed consensus for Patroni
etcd:
image: quay.io/coreos/etcd:v3.5.12
command:
- /usr/local/bin/etcd
- --name=etcd
- --initial-advertise-peer-urls=http://etcd:2380
- --listen-peer-urls=http://0.0.0.0:2380
- --listen-client-urls=http://0.0.0.0:2379
- --advertise-client-urls=http://etcd:2379
- --initial-cluster=etcd=http://etcd:2380
- --initial-cluster-state=new
- --initial-cluster-token=obiente-cluster
deploy:
replicas: 3
placement:
max_replicas_per_node: 1
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
volumes:
- etcd_data:/etcd-data
networks:
- obiente-network
# HAProxy - PostgreSQL connection pooler and load balancer
pgpool:
image: bitnami/pgpool:4
environment:
PGPOOL_BACKEND_NODES: 0:patroni-1:5432,1:patroni-2:5432,2:patroni-3:5432
PGPOOL_SR_CHECK_USER: ${POSTGRES_USER:-obiente_postgres}
PGPOOL_SR_CHECK_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
PGPOOL_ENABLE_LDAP: "no"
PGPOOL_POSTGRES_USERNAME: ${POSTGRES_USER:-obiente_postgres}
PGPOOL_POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
PGPOOL_ADMIN_USERNAME: admin
PGPOOL_ADMIN_PASSWORD: ${PGPOOL_ADMIN_PASSWORD:-adminpassword}
PGPOOL_ENABLE_LOAD_BALANCING: "yes"
PGPOOL_MAX_POOL: 100
deploy:
replicas: 2
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
healthcheck:
test: ["CMD", "/opt/bitnami/scripts/pgpool/healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 5
networks:
- obiente-network
# Patroni PostgreSQL - Node 1 (Leader)
patroni-1:
image: patroni/patroni:3.2.2
hostname: patroni-1
environment:
PATRONI_NAME: patroni-1
PATRONI_SCOPE: obiente-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: patroni-1:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: patroni-1:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${POSTGRES_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: replicator
PATRONI_REPLICATION_PASSWORD: ${REPLICATION_PASSWORD:-replicator-password}
PATRONI_admin_PASSWORD: ${PATRONI_ADMIN_PASSWORD:-admin}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- patroni_1_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.postgres.replica == 1
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 2G
networks:
- obiente-network
# Patroni PostgreSQL - Node 2 (Replica)
patroni-2:
image: patroni/patroni:3.2.2
hostname: patroni-2
environment:
PATRONI_NAME: patroni-2
PATRONI_SCOPE: obiente-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: patroni-2:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: patroni-2:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${POSTGRES_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: replicator
PATRONI_REPLICATION_PASSWORD: ${REPLICATION_PASSWORD:-replicator-password}
PATRONI_admin_PASSWORD: ${PATRONI_ADMIN_PASSWORD:-admin}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- patroni_2_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.postgres.replica == 2
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 2G
networks:
- obiente-network
# Patroni PostgreSQL - Node 3 (Replica)
patroni-3:
image: patroni/patroni:3.2.2
hostname: patroni-3
environment:
PATRONI_NAME: patroni-3
PATRONI_SCOPE: obiente-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: patroni-3:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: patroni-3:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${POSTGRES_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: replicator
PATRONI_REPLICATION_PASSWORD: ${REPLICATION_PASSWORD:-replicator-password}
PATRONI_admin_PASSWORD: ${PATRONI_ADMIN_PASSWORD:-admin}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- patroni_3_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.postgres.replica == 3
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 2G
networks:
- obiente-network
# ============================================================================
# METRICS DATABASE CLUSTER (TimescaleDB + Patroni)
# ============================================================================
# PgPool for TimescaleDB - Connection pooler and load balancer
metrics-pgpool:
image: bitnami/pgpool:4
environment:
PGPOOL_BACKEND_NODES: 0:metrics-patroni-1:5432,1:metrics-patroni-2:5432,2:metrics-patroni-3:5432
PGPOOL_SR_CHECK_USER: ${METRICS_DB_USER:-obiente_postgres}
PGPOOL_SR_CHECK_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
PGPOOL_ENABLE_LDAP: "no"
PGPOOL_POSTGRES_USERNAME: ${METRICS_DB_USER:-obiente_postgres}
PGPOOL_POSTGRES_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
PGPOOL_ADMIN_USERNAME: admin
PGPOOL_ADMIN_PASSWORD: ${METRICS_PGPOOL_ADMIN_PASSWORD:-${PGPOOL_ADMIN_PASSWORD:-adminpassword}}
PGPOOL_ENABLE_LOAD_BALANCING: "yes"
PGPOOL_MAX_POOL: 100
deploy:
replicas: 2
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
healthcheck:
test: ["CMD", "/opt/bitnami/scripts/pgpool/healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 5
networks:
- obiente-network
# Patroni TimescaleDB - Node 1 (Leader)
metrics-patroni-1:
image: timescale/timescaledb:latest-pg16
hostname: metrics-patroni-1
environment:
PATRONI_NAME: metrics-patroni-1
PATRONI_SCOPE: metrics-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: metrics-patroni-1:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: metrics-patroni-1:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${METRICS_DB_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: metrics-replicator
PATRONI_REPLICATION_PASSWORD: ${METRICS_REPLICATION_PASSWORD:-${REPLICATION_PASSWORD:-metrics-replicator-password}}
PATRONI_admin_PASSWORD: ${METRICS_PATRONI_ADMIN_PASSWORD:-${PATRONI_ADMIN_PASSWORD:-admin}}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- metrics_patroni_1_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.metrics.replica == 1
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 4G
networks:
- obiente-network
# Patroni TimescaleDB - Node 2 (Replica)
metrics-patroni-2:
image: timescale/timescaledb:latest-pg16
hostname: metrics-patroni-2
environment:
PATRONI_NAME: metrics-patroni-2
PATRONI_SCOPE: metrics-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: metrics-patroni-2:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: metrics-patroni-2:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${METRICS_DB_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: metrics-replicator
PATRONI_REPLICATION_PASSWORD: ${METRICS_REPLICATION_PASSWORD:-${REPLICATION_PASSWORD:-metrics-replicator-password}}
PATRONI_admin_PASSWORD: ${METRICS_PATRONI_ADMIN_PASSWORD:-${PATRONI_ADMIN_PASSWORD:-admin}}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- metrics_patroni_2_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.metrics.replica == 2
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 4G
networks:
- obiente-network
# Patroni TimescaleDB - Node 3 (Replica)
metrics-patroni-3:
image: timescale/timescaledb:latest-pg16
hostname: metrics-patroni-3
environment:
PATRONI_NAME: metrics-patroni-3
PATRONI_SCOPE: metrics-cluster
PATRONI_ETCD3_HOSTS: etcd:2379
PATRONI_RESTAPI_CONNECT_ADDRESS: metrics-patroni-3:8008
PATRONI_RESTAPI_LISTEN: 0.0.0.0:8008
PATRONI_POSTGRESQL_CONNECT_ADDRESS: metrics-patroni-3:5432
PATRONI_POSTGRESQL_LISTEN: 0.0.0.0:5432
PATRONI_POSTGRESQL_DATA_DIR: /var/lib/postgresql/data
PATRONI_POSTGRESQL_PGPASS: /tmp/pgpass
PATRONI_SUPERUSER_USERNAME: ${METRICS_DB_USER:-obiente_postgres}
PATRONI_SUPERUSER_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
PATRONI_REPLICATION_USERNAME: metrics-replicator
PATRONI_REPLICATION_PASSWORD: ${METRICS_REPLICATION_PASSWORD:-${REPLICATION_PASSWORD:-metrics-replicator-password}}
PATRONI_admin_PASSWORD: ${METRICS_PATRONI_ADMIN_PASSWORD:-${PATRONI_ADMIN_PASSWORD:-admin}}
PATRONI_admin_OPTIONS: "createdb,createrole"
volumes:
- metrics_patroni_3_data:/var/lib/postgresql/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.metrics.replica == 3
resources:
limits:
cpus: "4"
memory: 4G
reservations:
cpus: "2"
memory: 4G
networks:
- obiente-network
# ============================================================================
# REDIS CLUSTER (for caching, sessions, job queues)
# ============================================================================
redis-1:
image: redis:8-alpine
command: >
redis-server
--appendonly yes
--cluster-enabled yes
--cluster-config-file nodes.conf
--cluster-node-timeout 5000
--port 6379
volumes:
- redis_1_data:/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.redis == 1
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 512M
networks:
- obiente-network
redis-2:
image: redis:8-alpine
command: >
redis-server
--appendonly yes
--cluster-enabled yes
--cluster-config-file nodes.conf
--cluster-node-timeout 5000
--port 6379
volumes:
- redis_2_data:/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.redis == 2
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 512M
networks:
- obiente-network
redis-3:
image: redis:8-alpine
command: >
redis-server
--appendonly yes
--cluster-enabled yes
--cluster-config-file nodes.conf
--cluster-node-timeout 5000
--port 6379
volumes:
- redis_3_data:/data
deploy:
replicas: 1
placement:
constraints:
- node.labels.redis == 3
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 512M
networks:
- obiente-network
# ============================================================================
# SERVICE DISCOVERY & ROUTING
# ============================================================================
# Traefik - Dynamic reverse proxy with service discovery
traefik:
image: traefik:v3.6.1
command:
- --api.dashboard=true
- --api.insecure=false # Use secure API (HTTPS only)
- --providers.swarm=true # Use Swarm provider for Docker Swarm mode (v3.0)
- --providers.swarm.exposedbydefault=false
- --providers.swarm.network=__STACK_NAME___obiente-network
- --providers.swarm.watch=true # Watch for service changes
- --providers.swarm.refreshSeconds=5 # Poll Docker Swarm every 5 seconds for faster service discovery
- --providers.swarm.constraints=Label(`cloud.obiente.traefik`,`true`) # Only discover services with this label
# Timeout configuration to fail faster on unreachable backends
# dialTimeout: time to establish connection (increased to 10s to handle network delays)
- --serversTransport.forwardingTimeouts.dialTimeout=10s
# responseHeaderTimeout: time to wait for response headers
- --serversTransport.forwardingTimeouts.responseHeaderTimeout=15s
# idleConnTimeout: time to keep idle connections open
- --serversTransport.forwardingTimeouts.idleConnTimeout=90s
- --providers.etcd.endpoints=etcd:2379
- --providers.etcd.rootkey=traefik
- --entryPoints.web.address=:80
- --entryPoints.web.forwardedHeaders.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
- --entryPoints.websecure.address=:443
- --entryPoints.websecure.forwardedHeaders.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
- --entryPoints.deployments.address=:8000
- --entryPoints.deployments.forwardedHeaders.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
- --entryPoints.ssh.address=:${SSH_PROXY_PORT:-2222}
- --entryPoints.ssh.proxyProtocol.trustedIPs=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
# Database TCP entrypoints
- --entryPoints.postgres.address=:5432
- --entryPoints.mysql.address=:3306
- --entryPoints.mongodb.address=:27017
- --entryPoints.redis.address=:6379
- --certificatesresolvers.letsencrypt.acme.email=${ACME_EMAIL}
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
- --certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web
# Use Let's Encrypt staging environment if ACME_CA_SERVER is set to staging URL
# Set ACME_CA_SERVER=https://acme-staging-v02.api.letsencrypt.org/directory to avoid rate limits during testing
# Default: production (https://acme-v02.api.letsencrypt.org/directory)
- --certificatesresolvers.letsencrypt.acme.caserver=${ACME_CA_SERVER:-https://acme-v02.api.letsencrypt.org/directory}
- --metrics.prometheus=true
- --accesslog=true
- --log.level=INFO
ports:
- target: 80
published: 80
protocol: tcp
mode: host # host mode preserves real client IPs (ingress mode causes SNAT)
- target: 443
published: 443
protocol: tcp
mode: host # host mode preserves real client IPs (ingress mode causes SNAT)
- target: 8000
published: 8000
protocol: tcp
mode: host # host mode preserves real client IPs (ingress mode causes SNAT)
- target: 8080
published: 8080
protocol: tcp
mode: host # Traefik dashboard accessible on port 8080
- target: ${SSH_PROXY_PORT:-2222}
published: ${SSH_PROXY_PORT:-2222}
protocol: tcp
mode: host # host mode preserves real client IPs for SSH connections
# Database ports
- target: 5432
published: 5432
protocol: tcp
mode: ingress
- target: 3306
published: 3306
protocol: tcp
mode: ingress
- target: 27017
published: 27017
protocol: tcp
mode: ingress
- target: 6379
published: 6379
protocol: tcp
mode: ingress
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- traefik_letsencrypt:/letsencrypt
depends_on:
- etcd
deploy:
mode: global # Run on all nodes for HA and DNS to resolve properly
update_config:
parallelism: 1
order: start-first
placement:
constraints:
- node.labels.traefik.exclude != true # Exclude nodes labeled with traefik.exclude=true
resources:
limits:
cpus: "2"
memory: 512M
reservations:
cpus: "1"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.${DOMAIN}`)"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
# API routing
- "traefik.http.routers.api.rule=Host(`api.${DOMAIN}`)"
- "traefik.http.routers.api.entrypoints=websecure"
- "traefik.http.routers.api.tls.certresolver=letsencrypt"
# Note: Forwarded headers are configured at entrypoint level in Traefik command
# This ensures real client IPs are forwarded from Docker network IPs
- "traefik.http.services.api.loadbalancer.server.port=3001"
networks:
- obiente-network
# ============================================================================
# MONITORING & OBSERVABILITY
# ============================================================================
# Prometheus - Metrics collection
prometheus:
image: prom/prometheus:latest
user: "0:0" # Run as root to access Docker socket for Swarm service discovery
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention.time=15d"
volumes:
- prometheus_data:/prometheus
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- /var/run/docker.sock:/var/run/docker.sock:ro # Required for Docker Swarm service discovery
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
resources:
limits:
cpus: "2"
memory: 2G
reservations:
cpus: "1"
memory: 512M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.prometheus.rule=Host(`prometheus.${DOMAIN}`)"
- "traefik.http.routers.prometheus.entrypoints=websecure"
- "traefik.http.routers.prometheus.tls.certresolver=letsencrypt"
- "traefik.http.services.prometheus.loadbalancer.server.port=9090"
networks:
- obiente-network
# Grafana - Visualization
grafana:
image: grafana/grafana:latest
user: "0:0" # Run as root for entrypoint script to write provisioning files
entrypoint: ["/bin/sh", "/etc/grafana/entrypoint.sh"]
command: ["/run.sh"]
environment:
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin}
GF_SERVER_ROOT_URL: https://grafana.${DOMAIN}
# Disable strict provisioning validation to avoid conflicts in HA setup
GF_PROVISIONING_DATASOURCES_ALLOW_DELETION: "true"
# Allow unsigned plugins (for lokiexplore-app and other community plugins)
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: "grafana-lokiexplore-app"
# Pass database credentials as environment variables for datasource provisioning
POSTGRES_USER: ${POSTGRES_USER:-obiente_postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-obiente_postgres}
METRICS_DB_USER: ${METRICS_DB_USER:-obiente_postgres}
METRICS_DB_PASSWORD: ${METRICS_DB_PASSWORD:-obiente_postgres}
# Datasource host configuration (for HA, use pgpool service names)
GRAFANA_POSTGRES_HOST: ${GRAFANA_POSTGRES_HOST:-pgpool}
GRAFANA_METRICS_DB_HOST: ${GRAFANA_METRICS_DB_HOST:-metrics-pgpool}
# Alerting configuration
ALERT_EMAIL: ${ALERT_EMAIL:-admin@example.com}
# SMTP configuration for Grafana email notifications (only set if SMTP_HOST is configured)
# These will be conditionally set by the entrypoint script
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-587}
SMTP_USERNAME: ${SMTP_USERNAME:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
SMTP_FROM_ADDRESS: ${SMTP_FROM_ADDRESS:-}
SMTP_FROM_NAME: ${SMTP_FROM_NAME:-Grafana}
SMTP_SKIP_TLS_VERIFY: ${SMTP_SKIP_TLS_VERIFY:-false}
SMTP_USE_STARTTLS: ${SMTP_USE_STARTTLS:-true}
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:rw
- ./monitoring/grafana/dashboards:/etc/grafana/dashboards:ro
- ./monitoring/grafana/entrypoint.sh:/etc/grafana/entrypoint.sh:ro
depends_on:
- prometheus
- pgpool
- metrics-pgpool
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.grafana.rule=Host(`grafana.${DOMAIN}`)"
- "traefik.http.routers.grafana.entrypoints=web"
- "traefik.http.routers.grafana.service=grafana"
- "traefik.http.services.grafana.loadbalancer.server.port=3000"
# Route Grafana on HTTPS for production access
- "traefik.http.routers.grafana-secure.rule=Host(`grafana.${DOMAIN}`)"
- "traefik.http.routers.grafana-secure.entrypoints=websecure"
- "traefik.http.routers.grafana-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.grafana-secure.service=grafana"
networks:
- obiente-network
# Docker Registry - Host images for Swarm deployments
registry:
image: registry:2
environment:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
REGISTRY_HTTP_ADDR: 0.0.0.0:5000
# Allow deletion of images (useful for cleanup)
REGISTRY_STORAGE_DELETE_ENABLED: "true"
# Enable basic auth for private repositories
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: "Obiente Cloud Registry"
volumes:
- registry_data:/var/lib/registry
# Use bind mount for auth directory to allow easy setup from host
- /var/lib/obiente/registry-auth:/auth:ro
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 5000 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 5000 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
resources:
limits:
cpus: "2"
memory: 512M
reservations:
cpus: "0.5"
memory: 512M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.registry.rule=Host(`registry.${DOMAIN:-localhost}`)"
- "traefik.http.routers.registry.entrypoints=websecure"
- "traefik.http.routers.registry.tls.certresolver=letsencrypt"
- "traefik.http.routers.registry.service=registry"
- "traefik.http.services.registry.loadbalancer.server.port=5000"
networks:
- obiente-network
# ============================================================================
# MICROSERVICES
# ============================================================================
# All functionality has been moved from the monolithic API to microservices
# API Gateway (port 3001) is the primary entry point and routes to microservices
# Note: In HA setup, services connect to pgpool/metrics-pgpool instead of direct postgres/timescaledb
# Note: Redis cluster connection - services should use redis-1, redis-2, or redis-3, or a Redis proxy
# API Gateway - Routes requests to all microservices
api-gateway:
image: ghcr.io/obiente/cloud-api-gateway:latest
environment:
PORT: 3001
<<: [*common-auth]
ports:
- target: 3001
published: 3001
protocol: tcp
mode: ingress
deploy:
mode: replicated
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.api-gateway.rule=Host(`api.${DOMAIN}`)"
- "traefik.http.routers.api-gateway.entrypoints=web"
- "traefik.http.routers.api-gateway.service=api-gateway"
# Retry middleware for transient failures
- "traefik.http.middlewares.api-gateway-retry.retry.attempts=3"
- "traefik.http.middlewares.api-gateway-retry.retry.initialInterval=100ms"
# Circuit breaker removed from API gateway - gateway should always be accessible
- "traefik.http.routers.api-gateway.middlewares=api-gateway-retry"
- "traefik.http.services.api-gateway.loadbalancer.server.port=3001"
- "traefik.http.services.api-gateway.loadbalancer.passHostHeader=true"
- "traefik.http.services.api-gateway.loadbalancer.healthcheck.path=/health"
- "traefik.http.services.api-gateway.loadbalancer.healthcheck.interval=10s"
- "traefik.http.services.api-gateway.loadbalancer.healthcheck.timeout=8s"
- "traefik.http.services.api-gateway.loadbalancer.healthcheck.scheme=http"
- "traefik.http.services.api-gateway.loadbalancer.healthcheck.followRedirects=true"
- "traefik.http.routers.api-gateway-secure.rule=Host(`api.${DOMAIN}`)"
- "traefik.http.routers.api-gateway-secure.entrypoints=websecure"
- "traefik.http.routers.api-gateway-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.api-gateway-secure.service=api-gateway"
- "traefik.http.routers.api-gateway-secure.middlewares=api-gateway-retry"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3001 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3001 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
dns_search: []
networks:
- obiente-network
# Auth Service - Microservice for authentication
auth-service:
image: ghcr.io/obiente/cloud-auth-service:latest
environment:
PORT: 3002
<<: [*common-database, *common-metrics-db, *common-auth, *common-dashboard]
DB_HOST: pgpool
METRICS_DB_HOST: metrics-pgpool
deploy:
mode: replicated
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.auth-service.rule=Host(`auth-service.${DOMAIN}`)"
- "traefik.http.routers.auth-service.entrypoints=web"
- "traefik.http.services.auth-service.loadbalancer.server.port=3002"
- "traefik.http.routers.auth-service-secure.rule=Host(`auth-service.${DOMAIN}`)"
- "traefik.http.routers.auth-service-secure.entrypoints=websecure"
- "traefik.http.routers.auth-service-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.auth-service-secure.service=auth-service"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3002 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3002 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
dns_search: []
networks:
- obiente-network
# Organizations Service - Microservice for organization management
organizations-service:
image: ghcr.io/obiente/cloud-organizations-service:latest
environment:
PORT: 3003
<<: [*common-database, *common-metrics-db, *common-auth, *common-smtp, *common-dashboard, *common-notifications]
DB_HOST: pgpool
METRICS_DB_HOST: metrics-pgpool
deploy:
mode: replicated
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.organizations-service.rule=Host(`organizations-service.${DOMAIN}`)"
- "traefik.http.routers.organizations-service.entrypoints=web"
- "traefik.http.services.organizations-service.loadbalancer.server.port=3003"
- "traefik.http.routers.organizations-service-secure.rule=Host(`organizations-service.${DOMAIN}`)"
- "traefik.http.routers.organizations-service-secure.entrypoints=websecure"
- "traefik.http.routers.organizations-service-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.organizations-service-secure.service=organizations-service"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3003 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3003 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
dns_search: []
networks:
- obiente-network
# Billing Service - Microservice for billing and Stripe integration
billing-service:
image: ghcr.io/obiente/cloud-billing-service:latest
environment:
PORT: 3004
<<: [*common-database, *common-metrics-db, *common-auth, *common-stripe, *common-dashboard, *common-notifications]
DB_HOST: pgpool
METRICS_DB_HOST: metrics-pgpool
deploy:
mode: replicated
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.billing-service.rule=Host(`billing-service.${DOMAIN}`)"
- "traefik.http.routers.billing-service.entrypoints=web"
- "traefik.http.services.billing-service.loadbalancer.server.port=3004"
- "traefik.http.routers.billing-service-secure.rule=Host(`billing-service.${DOMAIN}`)"
- "traefik.http.routers.billing-service-secure.entrypoints=websecure"
- "traefik.http.routers.billing-service-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.billing-service-secure.service=billing-service"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3004 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3004 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
dns_search: []
networks:
- obiente-network
# Deployments Service - Microservice for deployment management
deployments-service:
image: ghcr.io/obiente/cloud-deployments-service:latest
environment:
PORT: 3005
<<: [*common-database, *common-metrics-db, *common-auth, *common-redis, *common-orchestrator, *common-dns-delegation, *common-notifications]
DB_HOST: pgpool
METRICS_DB_HOST: metrics-pgpool
REDIS_URL: ${REDIS_URL:-redis://redis-1:6379}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/obiente:/var/lib/obiente
- /var/obiente/tmp/obiente-volumes:/tmp/obiente-volumes
- /var/obiente/tmp/obiente-deployments:/tmp/obiente-deployments
deploy:
mode: global # One instance per node for local Docker access
update_config:
parallelism: 1
delay: 10s
order: start-first
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "2"
memory: 2G
reservations:
cpus: "1"
memory: 512M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.deployments-service.rule=Host(`deployments-service.${DOMAIN}`)"
- "traefik.http.routers.deployments-service.entrypoints=web"
- "traefik.http.services.deployments-service.loadbalancer.server.port=3005"
- "traefik.http.routers.deployments-service-secure.rule=Host(`deployments-service.${DOMAIN}`)"
- "traefik.http.routers.deployments-service-secure.entrypoints=websecure"
- "traefik.http.routers.deployments-service-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.deployments-service-secure.service=deployments-service"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3005 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3005 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
dns_search: []
networks:
- obiente-network
# Game Servers Service - Microservice for game server management
gameservers-service:
image: ghcr.io/obiente/cloud-gameservers-service:latest
environment:
PORT: 3006
<<: [*common-database, *common-metrics-db, *common-auth, *common-notifications, *common-redis]
DB_HOST: pgpool
METRICS_DB_HOST: metrics-pgpool
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/obiente/volumes:/var/lib/obiente/volumes
deploy:
mode: replicated
replicas: 3
update_config:
parallelism: 1
delay: 10s
order: start-first
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 10
window: 60s
resources:
limits:
cpus: "1"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
labels:
- "cloud.obiente.traefik=true"
- "traefik.enable=true"
- "traefik.http.routers.gameservers-service.rule=Host(`gameservers-service.${DOMAIN}`)"
- "traefik.http.routers.gameservers-service.entrypoints=web"
- "traefik.http.services.gameservers-service.loadbalancer.server.port=3006"
- "traefik.http.routers.gameservers-service-secure.rule=Host(`gameservers-service.${DOMAIN}`)"
- "traefik.http.routers.gameservers-service-secure.entrypoints=websecure"
- "traefik.http.routers.gameservers-service-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.gameservers-service-secure.service=gameservers-service"
healthcheck:
test: ["CMD-SHELL", "sh -c 'if command -v nc >/dev/null 2>&1; then nc -z localhost 3006 || exit 1; else (apk add --no-cache netcat-openbsd >/dev/null 2>&1 || apt-get update -qq && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 || yum install -y -q nc >/dev/null 2>&1) && nc -z localhost 3006 || exit 1; fi'"]
interval: 30s
timeout: 10s
retries: 3