-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
676 lines (648 loc) · 20.2 KB
/
docker-compose.yml
File metadata and controls
676 lines (648 loc) · 20.2 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
services:
# ========================================
# ZOOKEEPER (required for Kafka)
# ========================================
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
container_name: ecommerce-zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
volumes:
- zookeeper_data:/var/lib/zookeeper/data
- zookeeper_log:/var/lib/zookeeper/log
networks:
- ecommerce-network
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "2181" ]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# KAFKA
# ========================================
kafka:
image: confluentinc/cp-kafka:7.5.0
container_name: ecommerce-kafka
depends_on:
zookeeper:
condition: service_healthy
ports:
- "9092:9092"
- "9093:9093"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,PLAINTEXT_HOST://0.0.0.0:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
volumes:
- kafka_data:/var/lib/kafka/data
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "kafka-broker-api-versions", "--bootstrap-server", "localhost:9092"]
interval: 10s
timeout: 10s
retries: 10
start_period: 40s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
# ========================================
# KAFKA INIT (Creates topics automatically)
# ========================================
kafka-init:
image: confluentinc/cp-kafka:7.5.0
container_name: ecommerce-kafka-init
restart: "no" # Run once only
depends_on:
kafka:
condition: service_healthy
networks:
- ecommerce-network
entrypoint: ["/bin/sh", "-c"]
command: |
"
echo '⏳ Waiting for Kafka to be ready...'
sleep 10
echo '📋 Creating Kafka topics...'
# Outbox Pattern - Debezium will publish to this topic
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic outbox.event.Order --partitions 3 --replication-factor 1
# Product Service topics (direct publishing)
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic product-created --partitions 3 --replication-factor 1
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic product-updated --partitions 3 --replication-factor 1
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic product-deleted --partitions 3 --replication-factor 1
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic stock-changed --partitions 3 --replication-factor 1
# Other service topics
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic notification-events --partitions 2 --replication-factor 1
kafka-topics --create --if-not-exists --bootstrap-server kafka:9092 --topic authentication-email --partitions 2 --replication-factor 1
echo '✅ Kafka topics created successfully!'
kafka-topics --list --bootstrap-server kafka:9092
"
# ========================================
# KAFKA CONNECT (Debezium for CDC)
# ========================================
kafka-connect:
image: debezium/connect:2.5
container_name: ecommerce-kafka-connect
ports:
- "8084:8083"
environment:
BOOTSTRAP_SERVERS: kafka:9092
GROUP_ID: kafka-connect-cluster
CONFIG_STORAGE_TOPIC: connect-configs
OFFSET_STORAGE_TOPIC: connect-offsets
STATUS_STORAGE_TOPIC: connect-status
CONFIG_STORAGE_REPLICATION_FACTOR: 1
OFFSET_STORAGE_REPLICATION_FACTOR: 1
STATUS_STORAGE_REPLICATION_FACTOR: 1
# Connector configuration
CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
CONNECT_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: "false"
networks:
- ecommerce-network
depends_on:
kafka:
condition: service_healthy
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8083/"]
interval: 10s
timeout: 5s
retries: 10
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
# ========================================
# KAFKA CONNECT INIT (Register Debezium Connector)
# ========================================
kafka-connect-init:
image: alpine:3.19
container_name: ecommerce-kafka-connect-init
restart: "no" # Run once only
depends_on:
kafka-connect:
condition: service_healthy
order-service:
condition: service_started
networks:
- ecommerce-network
environment:
# Pass PostgreSQL credentials to substitute in connector config
POSTGRES_HOSTNAME: postgres
POSTGRES_PORT: 5432
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- ./order-service/debezium-connector-config.json:/config/connector-template.json:ro
entrypoint: ["/bin/sh", "-c"]
command:
- |
# Install required tools
apk add --no-cache curl gettext jq
echo '⏳ Waiting for Kafka Connect to be ready...'
until curl -s http://kafka-connect:8083/connectors > /dev/null 2>&1; do
echo 'Kafka Connect not ready, retrying in 5s...'
sleep 5
done
echo '✅ Kafka Connect is ready!'
echo '🔧 Preparing connector configuration with environment variables...'
# Use envsubst ONLY for specific variables (preserve ${routedByValue} for Debezium)
envsubst '$$POSTGRES_HOSTNAME $$POSTGRES_PORT $$POSTGRES_USER $$POSTGRES_PASSWORD $$POSTGRES_DB' < /config/connector-template.json > /tmp/connector.json
echo '📋 Checking if connector exists and deleting if found...'
EXISTING=$$(curl -s http://kafka-connect:8083/connectors)
if echo "$$EXISTING" | grep -q 'order-service-outbox-connector'; then
echo '🗑️ Deleting existing connector...'
curl -s -X DELETE http://kafka-connect:8083/connectors/order-service-outbox-connector
sleep 3
fi
echo '🔧 Registering Debezium outbox connector...'
echo ''
# Register connector
HTTP_CODE=$$(curl -s -o /tmp/response.json -w "%{http_code}" -X POST http://kafka-connect:8083/connectors \
-H "Content-Type: application/json" \
-d @/tmp/connector.json)
echo "HTTP Status: [$$HTTP_CODE]"
echo "Response:"
cat /tmp/response.json | jq '.' 2>/dev/null || cat /tmp/response.json
echo ''
if [ "$$HTTP_CODE" != "201" ]; then
echo "❌ Failed to register connector (HTTP $$HTTP_CODE)"
exit 1
fi
echo "✅ Connector registered successfully!"
# Clean up
rm -f /tmp/connector.json /tmp/response.json
echo ''
echo '📊 Connector status:'
sleep 2
curl -s http://kafka-connect:8083/connectors/order-service-outbox-connector/status | jq '.'
# ========================================
# POSTGRESQL (Order Service)
# ========================================
postgres:
image: postgres:16-alpine
container_name: ecommerce-postgres
ports:
- "5432:5432"
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
# Enable logical replication for Debezium CDC (Change Data Capture)
command:
- "postgres"
- "-c"
- "wal_level=logical"
- "-c"
- "max_replication_slots=4"
- "-c"
- "max_wal_senders=4"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- ecommerce-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
# ========================================
# POSTGRESQL (Authentication Service)
# ========================================
postgres-auth:
image: postgres:16-alpine
container_name: ecommerce-postgres-auth
ports:
- "5433:5432"
environment:
POSTGRES_DB: ${AUTH_POSTGRES_DB}
POSTGRES_USER: ${AUTH_POSTGRES_USER}
POSTGRES_PASSWORD: ${AUTH_POSTGRES_PASSWORD}
volumes:
- postgres_auth_data:/var/lib/postgresql/data
networks:
- ecommerce-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${AUTH_POSTGRES_USER} -d ${AUTH_POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
# ========================================
# MONGODB (Product Service)
# ========================================
mongodb:
image: mongo:7.0
container_name: ecommerce-mongodb
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
volumes:
- mongodb_data:/data/db
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
# ========================================
# REDIS (Cache)
# ========================================
redis:
image: redis:7-alpine
container_name: ecommerce-redis
ports:
- "6379:6379"
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# PROMETHEUS (Metrics)
# ========================================
prometheus:
image: prom/prometheus:v2.48.0
container_name: ecommerce-prometheus
ports:
- "9090:9090"
volumes:
- ./observability/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=15d'
- '--web.enable-lifecycle'
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "wget", "--tries=1", "--spider", "http://localhost:9090/-/healthy"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# GRAFANA (Dashboards)
# ========================================
grafana:
image: grafana/grafana:10.2.2
container_name: ecommerce-grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_USER: ${GF_SECURITY_ADMIN_USER}
GF_SECURITY_ADMIN_PASSWORD: ${GF_SECURITY_ADMIN_PASSWORD}
GF_USERS_ALLOW_SIGN_UP: false
volumes:
- grafana_data:/var/lib/grafana
- ./observability/grafana/provisioning:/etc/grafana/provisioning
networks:
- ecommerce-network
depends_on:
- prometheus
healthcheck:
test: ["CMD", "wget", "--tries=1", "--spider", "http://localhost:3000/api/health"]
interval: 10s
timeout: 5s
retries: 10
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# JAEGER (Tracing)
# ========================================
jaeger:
image: jaegertracing/all-in-one:latest
container_name: ecommerce-jaeger
ports:
- "16686:16686"
- "4318:4318"
environment:
COLLECTOR_OTLP_ENABLED: true
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "wget", "--tries=1", "--spider", "http://localhost:16686"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# ORDER SERVICE
# ========================================
order-service:
build:
context: ./order-service
dockerfile: src/main/docker/Dockerfile.native-micro-multistage
image: ecommerce/order-service:native-micro
container_name: ecommerce-order-service
ports:
- "8081:8080"
environment:
QUARKUS_DATASOURCE_JDBC_URL: ${ORDER_SERVICE_DB_URL}
QUARKUS_DATASOURCE_USERNAME: ${ORDER_SERVICE_DB_USER}
QUARKUS_DATASOURCE_PASSWORD: ${ORDER_SERVICE_DB_PASSWORD}
KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_BOOTSTRAP_SERVERS}
QUARKUS_LOG_CONSOLE_JSON: ${LOG_JSON_ENABLED}
QUARKUS_LOG_LEVEL: ${LOG_LEVEL}
QUARKUS_HTTP_PORT: 8080
QUARKUS_HTTP_HOST: 0.0.0.0
networks:
- ecommerce-network
depends_on:
postgres:
condition: service_healthy
restart: true
kafka:
condition: service_started
kafka-init:
condition: service_completed_successfully
healthcheck:
test: ["CMD-SHELL", "true"] # ← Simplificado (UBI Micro não tem wget/curl)
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
restart: on-failure
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
# ========================================
# PRODUCT SERVICE
# ========================================
product-service:
build:
context: ./product-service
dockerfile: src/main/docker/Dockerfile.native-micro-multistage
image: ecommerce/product-service:native-micro
container_name: ecommerce-product-service
ports:
- "8082:8080"
environment:
QUARKUS_MONGODB_CONNECTION_STRING: ${PRODUCT_SERVICE_MONGODB_URI}
QUARKUS_MONGODB_DATABASE: ${PRODUCT_SERVICE_MONGODB_DATABASE}
QUARKUS_REDIS_HOSTS: ${PRODUCT_SERVICE_REDIS_URI}
KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_BOOTSTRAP_SERVERS}
JWT_PUBLIC_KEY_LOCATION: /work/publicKey.pem
QUARKUS_LOG_CONSOLE_JSON: ${LOG_JSON_ENABLED}
QUARKUS_LOG_LEVEL: ${LOG_LEVEL}
QUARKUS_HTTP_PORT: 8080
QUARKUS_HTTP_HOST: 0.0.0.0
volumes:
- ./publicKey.pem:/work/publicKey.pem
networks:
- ecommerce-network
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
kafka:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "true"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
# ========================================
# NOTIFICATION SERVICE
# ========================================
notification-service:
build:
context: ./notification-service
dockerfile: src/main/docker/Dockerfile.native-micro-multistage
image: ecommerce/notification-service:native-micro
container_name: ecommerce-notification-service
ports:
- "8083:8080"
environment:
KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_BOOTSTRAP_SERVERS}
DISCORD_WEBHOOK_URL: ${DISCORD_WEBHOOK_URL}
DISCORD_WEBHOOK_ENABLED: ${DISCORD_WEBHOOK_ENABLED}
NOTIFICATION_DISCORD_ENABLED: ${NOTIFICATION_DISCORD_ENABLED}
BREVO_API_KEY: ${BREVO_API_KEY}
BREVO_SENDER_NAME: ${BREVO_SENDER_NAME}
BREVO_SENDER_EMAIL: ${BREVO_SENDER_EMAIL}
NOTIFICATION_EMAIL_ENABLED: ${NOTIFICATION_EMAIL_ENABLED}
QUARKUS_LOG_CONSOLE_JSON: ${LOG_JSON_ENABLED}
QUARKUS_LOG_LEVEL: ${LOG_LEVEL}
QUARKUS_HTTP_PORT: 8080
QUARKUS_HTTP_HOST: 0.0.0.0
networks:
- ecommerce-network
depends_on:
kafka:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "true"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
# ========================================
# AUTHENTICATION SERVICE
# ========================================
authentication-service:
build:
context: ./authentication-service
dockerfile: src/main/docker/Dockerfile.native-micro-multistage
image: ecommerce/authentication-service:native-micro
container_name: ecommerce-authentication-service
ports:
- "8080:8080"
environment:
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-admin123}
DB_URL: ${AUTH_SERVICE_DB_URL}
DB_USERNAME: ${AUTH_SERVICE_DB_USER}
DB_PASSWORD: ${AUTH_SERVICE_DB_PASSWORD}
JWT_KEY_LOCATION: /work/privateKey.pem
JWT_PUBLIC_KEY_LOCATION: /work/publicKey.pem
ENCRYPTION_KEY: ${ENCRYPTION_KEY}
FRONTEND_BASE_URL: ${FRONTEND_BASE_URL}
KAFKA_BOOTSTRAP_SERVERS: ${KAFKA_BOOTSTRAP_SERVERS}
QUARKUS_LOG_CONSOLE_JSON: ${LOG_JSON_ENABLED}
QUARKUS_LOG_LEVEL: ${LOG_LEVEL}
QUARKUS_HTTP_PORT: 8080
QUARKUS_HTTP_HOST: 0.0.0.0
volumes:
- ./privateKey.pem:/work/privateKey.pem
- ./publicKey.pem:/work/publicKey.pem
networks:
- ecommerce-network
depends_on:
postgres-auth:
condition: service_healthy
kafka:
condition: service_started
healthcheck:
test: ["CMD-SHELL", "true"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
# ========================================
# VOLUMES
# ========================================
volumes:
postgres_data:
driver: local
mongodb_data:
driver: local
redis_data:
driver: local
kafka_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
zookeeper_data:
driver: local
zookeeper_log:
driver: local
postgres_auth_data:
driver: local
# ========================================
# NETWORKS
# ========================================
networks:
ecommerce-network:
driver: bridge