-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
387 lines (369 loc) · 11.6 KB
/
Copy pathdocker-compose.yml
File metadata and controls
387 lines (369 loc) · 11.6 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
# PayFlow — Distributed Payment Processing System
# Docker Compose Orchestration for all services
# Owner: Member 5 (Monitoring, Testing & Infrastructure)
#
# Usage:
# docker compose up --build — start all services
# docker compose down --volumes — stop and clean up
# docker compose logs <service> — view service logs
x-coordinator-base: &coordinator-base
build:
context: ./payflow
dockerfile: coordinator/Dockerfile
cap_add:
- NET_ADMIN
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
restart: unless-stopped
networks:
- payflow-net
depends_on:
payment-log:
condition: service_healthy
healthcheck:
interval: 10s
timeout: 5s
retries: 3
start_period: 20s
x-worker-base: &worker-base
build:
context: ./payflow/worker
dockerfile: Dockerfile
cap_add:
- NET_ADMIN
deploy:
resources:
limits:
cpus: "0.5"
memory: "128M"
restart: unless-stopped
networks:
- payflow-net
depends_on:
coordinator-1:
condition: service_healthy
coordinator-2:
condition: service_healthy
coordinator-3:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:2112/metrics"]
interval: 10s
timeout: 5s
retries: 3
start_period: 15s
x-worker-env: &worker-env
METRICS_PORT: "2112"
COORDINATOR_ADDR: "coordinator-3:50053"
LOG_SERVICE_ADDR: "payment-log:50054"
HEARTBEAT_INTERVAL: "2s"
BANK_API_ADDR: "http://mock-bank:9999"
BANK_LATENCY_MIN_MS: "50"
BANK_LATENCY_MAX_MS: "500"
BANK_FAIL_RATE: "0.10"
WORKER_TOKEN: "secret-token"
OUTBOX_DB_PATH: "/tmp/outbox"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
services:
# ─────────────────────────────────────────────────────────
# C1: API Gateway — REST + gRPC entry point
# ─────────────────────────────────────────────────────────
api-gateway:
build:
context: ./payflow
dockerfile: gateway/Dockerfile
cap_add:
- NET_ADMIN
ports:
- "8080:8080"
- "9090:9090"
environment:
PORT: "8080"
METRICS_PORT: "2112"
GRPC_PORT: "9090"
JWT_SECRET: "dev-secret-change-in-prod"
COORDINATOR_ADDRS: "coordinator-1:50051,coordinator-2:50052,coordinator-3:50053"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "api-gateway"
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 15s
depends_on:
coordinator-1:
condition: service_healthy
coordinator-2:
condition: service_healthy
coordinator-3:
condition: service_healthy
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
restart: unless-stopped
networks:
- payflow-net
# ─────────────────────────────────────────────────────────
# C2: Coordinator Cluster — Bully Election + Task Dispatch
# ─────────────────────────────────────────────────────────
coordinator-1:
<<: *coordinator-base
command: ["--id=coordinator-1", "--port=:50051"]
ports:
- "50051:50051"
- "2112:2112"
environment:
NODE_ID: "1"
PORT: "50051"
GRPC_PORT: "50051"
METRICS_PORT: "2112"
PEERS: "coordinator-2:50052,coordinator-3:50053"
PAYMENT_LOG_ADDR: "payment-log:50054"
HEARTBEAT_INTERVAL: "2s"
ELECTION_TIMEOUT: "5s"
ELECTION_TIMEOUT_MS: "5000"
HEARTBEAT_INTERVAL_MS: "2000"
HEARTBEAT_MISS_THRESHOLD: "3"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "coordinator-1"
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 50051 || exit 1"]
coordinator-2:
<<: *coordinator-base
command: ["--id=coordinator-2", "--port=:50052"]
ports:
- "50052:50052"
- "2153:2112"
environment:
NODE_ID: "2"
PORT: "50052"
GRPC_PORT: "50052"
METRICS_PORT: "2112"
PEERS: "coordinator-1:50051,coordinator-3:50053"
PAYMENT_LOG_ADDR: "payment-log:50054"
HEARTBEAT_INTERVAL: "2s"
ELECTION_TIMEOUT: "5s"
ELECTION_TIMEOUT_MS: "5000"
HEARTBEAT_INTERVAL_MS: "2000"
HEARTBEAT_MISS_THRESHOLD: "3"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "coordinator-2"
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 50052 || exit 1"]
coordinator-3:
<<: *coordinator-base
command: ["--id=coordinator-3", "--port=:50053"]
ports:
- "50053:50053"
- "2154:2112"
environment:
NODE_ID: "3"
PORT: "50053"
GRPC_PORT: "50053"
METRICS_PORT: "2112"
PEERS: "coordinator-1:50051,coordinator-2:50052"
PAYMENT_LOG_ADDR: "payment-log:50054"
HEARTBEAT_INTERVAL: "2s"
ELECTION_TIMEOUT: "5s"
ELECTION_TIMEOUT_MS: "5000"
HEARTBEAT_INTERVAL_MS: "2000"
HEARTBEAT_MISS_THRESHOLD: "3"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "coordinator-3"
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 50053 || exit 1"]
# ─────────────────────────────────────────────────────────
# C3: Worker Services — Payment Execution + Heartbeat
# ─────────────────────────────────────────────────────────
worker-1:
<<: *worker-base
environment:
<<: *worker-env
WORKER_ID: "1"
PORT: "8080"
OTEL_SERVICE_NAME: "worker-1"
worker-2:
<<: *worker-base
environment:
<<: *worker-env
WORKER_ID: "2"
PORT: "8080"
OTEL_SERVICE_NAME: "worker-2"
worker-3:
<<: *worker-base
environment:
<<: *worker-env
WORKER_ID: "3"
PORT: "8080"
OTEL_SERVICE_NAME: "worker-3"
worker-4:
<<: *worker-base
environment:
<<: *worker-env
WORKER_ID: "4"
PORT: "8080"
OTEL_SERVICE_NAME: "worker-4"
worker-5:
<<: *worker-base
environment:
<<: *worker-env
WORKER_ID: "5"
PORT: "8080"
OTEL_SERVICE_NAME: "worker-5"
# ─────────────────────────────────────────────────────────
# C4: Payment Log Service — BoltDB append-only log
# ─────────────────────────────────────────────────────────
payment-log:
build:
context: ./payflow
dockerfile: payment-log/Dockerfile
cap_add:
- NET_ADMIN
ports:
- "50054:50054"
- "2113:2113"
environment:
PORT: "2113"
GRPC_PORT: "50054"
METRICS_PORT: "2112"
HEALTH_PORT: "2113"
BOLT_PATH: "/data/payments.db"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "payment-log"
volumes:
- payflow-bolt:/data
healthcheck:
test: ["CMD-SHELL", "nc -z localhost 50054 || exit 1"]
interval: 10s
timeout: 5s
retries: 3
start_period: 20s
deploy:
resources:
limits:
cpus: "1.0"
memory: "512M"
restart: unless-stopped
networks:
- payflow-net
# ─────────────────────────────────────────────────────────
# C5: Monitoring Service — Prometheus + WebSocket Dashboard
# ─────────────────────────────────────────────────────────
monitor:
build:
context: ./payflow/monitor
cap_add:
- NET_ADMIN
ports:
- "3000:3000"
- "9091:9091"
environment:
HTTP_PORT: "3000"
PROMETHEUS_PORT: "9091"
SCRAPE_INTERVAL: "15s"
SCALING_ENABLED: "true"
SCALING_QUEUE_THRESHOLD: "50"
SCALING_MAX_WORKERS: "10"
SCALING_COOLDOWN: "30s"
SCALING_TEMPLATE_WORKER: "worker-1"
SCRAPE_TARGETS: >-
http://api-gateway:8080/metrics,
http://coordinator-1:2112/metrics,
http://coordinator-2:2112/metrics,
http://coordinator-3:2112/metrics,
http://payment-log:2112/metrics,
http://worker-1:2112/metrics,
http://worker-2:2112/metrics,
http://worker-3:2112/metrics,
http://worker-4:2112/metrics,
http://worker-5:2112/metrics
OTEL_EXPORTER_OTLP_ENDPOINT: "http://jaeger:4318"
OTEL_SERVICE_NAME: "monitor"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 15s
depends_on:
api-gateway:
condition: service_healthy
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
restart: unless-stopped
networks:
- payflow-net
# ─────────────────────────────────────────────────────────
# Supporting: Mock Bank API (simulates external payment gateway)
# Uses placeholder service - workers call /v1/payments endpoint
# ─────────────────────────────────────────────────────────
mock-bank:
build:
context: ./payflow/placeholder
dockerfile: Dockerfile
ports:
- "9999:9999"
environment:
PORT: "9999"
METRICS_PORT: "2113"
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:9999/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: "0.25"
memory: "64M"
restart: unless-stopped
networks:
- payflow-net
# ─────────────────────────────────────────────────────────
# Supporting: Jaeger Distributed Tracing
# ─────────────────────────────────────────────────────────
jaeger:
image: jaegertracing/all-in-one:1.55
ports:
- "16686:16686"
- "14268:14268"
- "4318:4318"
environment:
COLLECTOR_OTLP_ENABLED: "true"
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:16686/"]
interval: 10s
timeout: 5s
retries: 3
start_period: 20s
deploy:
resources:
limits:
cpus: "0.5"
memory: "256M"
restart: unless-stopped
networks:
- payflow-net
volumes:
payflow-bolt:
driver: local
labels:
com.payflow.description: "BoltDB persistent store for C4 payment-log"
networks:
payflow-net:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16