-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
663 lines (629 loc) · 17.1 KB
/
Copy pathdocker-compose.yml
File metadata and controls
663 lines (629 loc) · 17.1 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
services:
# Authentication & Identity Management
# PostgreSQL for Keycloak shared database
postgres:
image: postgres:15.3-alpine
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: keycloak
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-keycloak}
# Security hardening
POSTGRES_HOST_AUTH_METHOD: md5
POSTGRES_INITDB_ARGS: "--auth-host=md5 --auth-local=md5"
volumes:
- postgres-data:/var/lib/postgresql/data
- ./auth/postgres-init.sql:/docker-entrypoint-initdb.d/init.sql:ro
- ssl-certs:/certs:ro
ports:
- "127.0.0.1:5432:5432" # Bind to localhost only
networks:
internal:
aliases:
- postgres
backend:
aliases:
- postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U keycloak"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
memory: 512M
cpus: '1'
reservations:
memory: 256M
cpus: '0.5'
# Security: Run as non-root user
user: postgres
# Infinispan for distributed caching
# infinispan:
# image: infinispan/server:14.0.21.Final
# user: "1000:1000"
# environment:
# USER: admin
# PASS: admin
# ports:
# - "11222:11222"
# volumes:
# - infinispan-data:/opt/infinispan/server/data
# networks:
# backend:
# aliases:
# - infinispan
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:11222/rest/v2/cache-managers"]
# interval: 30s
# timeout: 10s
# retries: 3
# Keycloak instances (horizontally scalable)
keycloak-1:
image: quay.io/keycloak/keycloak:22.0.1
environment:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak
KC_HOSTNAME_STRICT: false
KC_HOSTNAME_STRICT_HTTPS: false
KC_HTTP_ENABLED: true
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KC_PROXY: edge
KC_HOSTNAME_URL: https://localhost:8443
KC_HOSTNAME_ADMIN_URL: https://localhost:8443
KC_SPI_TRUSTSTORE_FILE_FILE: ""
KC_SPI_TRUSTSTORE_FILE_PASSWORD: ""
ports:
- "8090:8080"
volumes:
- ./auth/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro
command: ["start", "--import-realm"]
depends_on:
postgres:
condition: service_healthy
networks:
backend:
aliases:
- keycloak-1
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/realms/master || exit 1"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '2'
reservations:
memory: 512M
cpus: '1'
keycloak-2:
image: quay.io/keycloak/keycloak:22.0.1
environment:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak
KC_HOSTNAME_STRICT: false
KC_HOSTNAME_STRICT_HTTPS: false
KC_HTTP_ENABLED: true
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KC_PROXY: edge
KC_HOSTNAME_URL: https://localhost:8443
KC_HOSTNAME_ADMIN_URL: https://localhost:8443
KC_SPI_TRUSTSTORE_FILE_FILE: ""
KC_SPI_TRUSTSTORE_FILE_PASSWORD: ""
ports:
- "8091:8080"
command: ["start"]
depends_on:
postgres:
condition: service_healthy
keycloak-1:
condition: service_started
networks:
backend:
aliases:
- keycloak-2
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/realms/master || exit 1"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '2'
reservations:
memory: 512M
cpus: '1'
# Prometheus for monitoring
prometheus:
image: prom/prometheus:v2.45.0
ports:
- "9090:9090"
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./monitoring/alert-rules.yml:/etc/prometheus/alert-rules.yml:ro
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--storage.tsdb.retention.time=200h'
- '--web.enable-lifecycle'
- '--web.enable-admin-api'
networks:
backend:
aliases:
- prometheus
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9090/-/healthy"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 2G
cpus: '2'
reservations:
memory: 512M
cpus: '0.5'
# Grafana for visualization
grafana:
image: grafana/grafana:10.0.0
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_INSTALL_PLUGINS=grafana-piechart-panel
volumes:
- grafana-data:/var/lib/grafana
- ./monitoring/grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
- ./monitoring/grafana-dashboards.yml:/etc/grafana/provisioning/dashboards/dashboards.yml:ro
- ./monitoring/dashboards:/var/lib/grafana/dashboards:ro
depends_on:
- prometheus
networks:
- backend
- grafana
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 512M
cpus: '1'
reservations:
memory: 256M
cpus: '0.5'
# Jaeger - Distributed Tracing
jaeger:
image: jaegertracing/all-in-one:1.50
ports:
- "16686:16686" # Jaeger UI
- "14268:14268" # Jaeger collector HTTP endpoint
- "9411:9411" # Zipkin collector HTTP endpoint (for Spring Boot compatibility)
- "6831:6831/udp" # Jaeger agent UDP endpoint
- "6832:6832/udp" # Jaeger agent UDP endpoint
- "5778:5778" # Jaeger agent HTTP endpoint
environment:
- COLLECTOR_OTLP_ENABLED=true
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
- SPAN_STORAGE_TYPE=memory
networks:
- backend
- grafana
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:16686/"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '1'
reservations:
memory: 256M
cpus: '0.25'
# Alertmanager for alert handling
alertmanager:
image: prom/alertmanager:v0.26.0
ports:
- "9093:9093"
volumes:
- ./monitoring/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
- alertmanager-data:/alertmanager
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
- '--web.external-url=http://localhost:9093'
- '--cluster.advertise-address=0.0.0.0:9093'
networks:
- backend
depends_on:
- prometheus
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9093/-/healthy"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 256M
cpus: '0.5'
reservations:
memory: 128M
cpus: '0.25'
# pgBackRest for database backup and replication (commented out for initial testing)
# pgbackrest:
# image: woblerr/pgbackrest:latest
# environment:
# PGBACKREST_CONFIG: /etc/pgbackrest/pgbackrest.conf
# POSTGRES_PASSWORD: keycloak
# volumes:
# - ./auth/pgbackrest.conf:/etc/pgbackrest/pgbackrest.conf:ro
# - pgbackrest-data:/var/lib/pgbackrest
# - postgres-data:/var/lib/postgresql/data:ro
# depends_on:
# - postgres
# networks:
# backend:
# aliases:
# - pgbackrest
message-queue:
image: rabbitmq:3.11.16-management-alpine
ports:
- "127.0.0.1:5672:5672" # Bind to localhost only
- "127.0.0.1:15672:15672" # Management UI localhost only
- "127.0.0.1:15692:15692" # Prometheus metrics port
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER:-admin}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS:-admin}
RABBITMQ_CONFIG_FILE: /etc/rabbitmq/rabbitmq
volumes:
- rabbitmq-data:/var/lib/rabbitmq
- ./monitoring/rabbitmq_prometheus.conf:/etc/rabbitmq/conf.d/20-prometheus.conf:ro
- ./config/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
networks:
backend:
aliases:
- message-queue
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '2'
reservations:
memory: 512M
cpus: '0.5'
write-layer:
build:
context: .
dockerfile: write_layer/Dockerfile
ports:
- "8081:8081"
environment:
SPRING_RABBITMQ_HOST: message-queue
RABBITMQ_USERNAME: admin
RABBITMQ_PASSWORD: admin
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
SPRING_REDIS_PASSWORD: ${REDIS_PASSWORD:-secure_redis_password}
SERVER_PORT: 8081
KEYCLOAK_URL: https://haproxy:8443
KEYCLOAK_REALM: event-system
KEYCLOAK_CLIENT_ID: event-system-api
depends_on:
- message-queue
- redis
- keycloak-1
networks:
backend:
aliases:
- write-layer
write-layer-2:
build:
context: .
dockerfile: write_layer/Dockerfile
ports:
- "8083:8081"
environment:
SPRING_RABBITMQ_HOST: message-queue
RABBITMQ_USERNAME: admin
RABBITMQ_PASSWORD: admin
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
SPRING_REDIS_PASSWORD: ${REDIS_PASSWORD:-secure_redis_password}
SERVER_PORT: 8081
KEYCLOAK_URL: https://haproxy:8443
KEYCLOAK_REALM: event-system
KEYCLOAK_CLIENT_ID: event-system-api
depends_on:
- message-queue
- redis
- keycloak-1
networks:
backend:
aliases:
- write-layer-2
public-api:
build:
context: .
dockerfile: public_api/Dockerfile
ports:
- "8082:8082"
environment:
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
SERVER_PORT: 8082
depends_on:
- redis
networks:
backend:
aliases:
- public-api
cache-sync:
build:
context: .
dockerfile: cache-sync-service/Dockerfile
environment:
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
depends_on:
- redis
- kafka
networks:
backend:
aliases:
- cache-sync
coupon-service:
build:
context: .
dockerfile: coupon_service/Dockerfile
ports:
- "8086:8086"
environment:
SPRING_RABBITMQ_HOST: message-queue
RABBITMQ_USERNAME: admin
RABBITMQ_PASSWORD: admin
AWS_ACCESS_KEY_ID: dummy
AWS_SECRET_ACCESS_KEY: dummy
AWS_REGION: us-east-1
AWS_DYNAMODB_ENDPOINT: http://dynamodb-local:8000
KAFKA_BOOTSTRAP_SERVERS: kafka:9092
SPRING_REDIS_HOST: redis
SPRING_REDIS_PORT: 6379
SERVER_PORT: 8086
depends_on:
- message-queue
- dynamodb-local
- dynamodb-init
- kafka
- redis
networks:
backend:
aliases:
- coupon-service
# Web application (React)
web-app:
build:
context: ./web_app
dockerfile: Dockerfile
ports:
- "3001:80"
environment:
- REACT_APP_API_URL=https://localhost:8443
- REACT_APP_KEYCLOAK_URL=https://localhost:8443
- REACT_APP_JAEGER_ENDPOINT=http://localhost:16686
depends_on:
- haproxy
- write-layer
networks:
backend:
aliases:
- web-app
extra_hosts:
- "app.eventualconsistent.local:127.0.0.1"
redis:
image: redis:7.0.11-alpine
ports:
- "127.0.0.1:6379:6379" # Bind to localhost only
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD:-secure_redis_password}
volumes:
- redis-data:/data
- ssl-certs:/certs:ro
- ./config/redis.conf:/usr/local/etc/redis/redis.conf:ro
command: redis-server /usr/local/etc/redis/redis.conf --requirepass ${REDIS_PASSWORD:-secure_redis_password}
networks:
backend:
aliases:
- redis
internal:
aliases:
- redis
healthcheck:
test: ["CMD", "redis-cli", "--no-auth-warning", "-a", "${REDIS_PASSWORD:-secure_redis_password}", "ping"]
interval: 30s
timeout: 5s
retries: 3
restart: unless-stopped
deploy:
resources:
limits:
memory: 256M
cpus: '0.5'
reservations:
memory: 128M
cpus: '0.25'
dynamodb-local:
image: amazon/dynamodb-local:1.21.0
command: -jar DynamoDBLocal.jar -sharedDb -inMemory
ports:
- "8000:8000"
networks:
backend:
aliases:
- dynamodb-local
dynamodb-init:
build:
context: .
dockerfile: scripts/Dockerfile.init
depends_on:
- dynamodb-local
networks:
backend:
restart: "no"
zookeeper:
image: confluentinc/cp-zookeeper:7.3.2
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
networks:
backend:
aliases:
- zookeeper
kafka:
image: confluentinc/cp-kafka:7.3.2
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
networks:
backend:
aliases:
- kafka
haproxy:
image: haproxy:2.7.3-alpine
ports:
- "8080:8080" # HTTP port (will redirect to HTTPS)
- "8443:8443" # HTTPS port
volumes:
- ./load_balancer/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
- ssl-certs:/certs:ro
depends_on:
- ssl-cert-generator
- write-layer
- public-api
- keycloak-1
- keycloak-2
networks:
backend:
aliases:
- haproxy
internal:
aliases:
- haproxy
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "8443"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
# SSL/TLS Certificate Generation Service
ssl-cert-generator:
image: alpine:latest
volumes:
- ssl-certs:/certs
- ./scripts/generate-backend-ssl.sh:/generate-ssl.sh:ro
command: >
sh -c "
apk add --no-cache openssl &&
if [ ! -f /certs/backend.pem ]; then
echo 'Generating SSL certificates for backend services...' &&
# Generate private key
openssl genrsa -out /certs/backend.key 2048 &&
# Create OpenSSL config for SAN
cat > /certs/openssl.conf << 'EOF'
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = State
L = City
O = EventualConsistent
CN = localhost
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = app.eventualconsistent.local
DNS.3 = haproxy
IP.1 = 127.0.0.1
IP.2 = ::1
EOF
# Generate certificate with SAN
openssl req -new -key /certs/backend.key -out /certs/backend.csr -config /certs/openssl.conf &&
openssl x509 -req -in /certs/backend.csr -signkey /certs/backend.key -out /certs/backend.crt -extensions v3_req -extfile /certs/openssl.conf -days 365 &&
# Combine certificate and key for HAProxy
cat /certs/backend.crt /certs/backend.key > /certs/backend.pem &&
# Set proper permissions
chmod 644 /certs/*.crt /certs/*.pem &&
chmod 600 /certs/*.key &&
echo 'SSL certificates generated successfully!'
else
echo 'SSL certificates already exist, skipping generation.'
fi
"
networks:
- internal
restart: "no"
volumes:
dynamodb-data:
postgres-data:
infinispan-data:
prometheus-data:
grafana-data:
pgbackrest-data:
rabbitmq-data:
alertmanager-data:
ssl-certs:
redis-data:
networks:
backend:
driver: bridge
grafana:
driver: bridge
internal:
driver: bridge