-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
510 lines (494 loc) · 11.5 KB
/
docker-compose.prod.yml
File metadata and controls
510 lines (494 loc) · 11.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
version: '3.8'
services:
# Database Services
mongodb:
image: mongo:7.0
container_name: msa-mongodb-prod
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME_FILE: /run/secrets/mongodb_root_username
MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/mongodb_root_password
MONGO_INITDB_DATABASE: admin
volumes:
- mongodb_data:/data/db
- mongodb_config:/data/configdb
- ./database/mongo-init:/docker-entrypoint-initdb.d:ro
networks:
- msa-backend
secrets:
- mongodb_root_username
- mongodb_root_password
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
reservations:
memory: 512M
cpus: '0.25'
redis:
image: redis:7.2-alpine
container_name: msa-redis-prod
restart: always
command: redis-server /usr/local/etc/redis/redis.conf
volumes:
- redis_data:/data
- ./config/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
networks:
- msa-backend
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 3s
retries: 3
deploy:
resources:
limits:
memory: 512M
cpus: '0.25'
reservations:
memory: 256M
cpus: '0.1'
# Backend Services
auth-service:
image: msa-auth-service:latest
container_name: msa-auth-service-prod
restart: always
environment:
NODE_ENV: production
PORT: 4002
env_file:
- ./backend-services/auth-service/.env.prod
volumes:
- auth_logs:/app/logs
secrets:
- jwt_secret
- refresh_token_secret
- mongodb_uri
- redis_password
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
networks:
- msa-backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4002/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
posts-service:
image: msa-posts-service:latest
container_name: msa-posts-service-prod
restart: always
environment:
NODE_ENV: production
PORT: 4000
env_file:
- ./backend-services/posts-service/.env.prod
volumes:
- posts_logs:/app/logs
- posts_uploads:/app/uploads
secrets:
- jwt_secret
- mongodb_uri
- redis_password
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
auth-service:
condition: service_healthy
networks:
- msa-backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
comments-service:
image: msa-comments-service:latest
container_name: msa-comments-service-prod
restart: always
environment:
NODE_ENV: production
PORT: 4001
env_file:
- ./backend-services/comments-service/.env.prod
volumes:
- comments_logs:/app/logs
secrets:
- jwt_secret
- mongodb_uri
- redis_password
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
auth-service:
condition: service_healthy
posts-service:
condition: service_healthy
networks:
- msa-backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4001/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
api-gateway:
image: msa-api-gateway:latest
container_name: msa-api-gateway-prod
restart: always
environment:
NODE_ENV: production
PORT: 5000
env_file:
- ./backend-services/api-gateway/.env.prod
volumes:
- gateway_logs:/app/logs
secrets:
- jwt_secret
- redis_password
depends_on:
redis:
condition: service_healthy
auth-service:
condition: service_healthy
posts-service:
condition: service_healthy
comments-service:
condition: service_healthy
networks:
- msa-backend
- msa-frontend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
# Load Balancer
nginx:
image: nginx:1.25-alpine
container_name: msa-nginx-prod
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./config/nginx/sites-available:/etc/nginx/sites-available:ro
- ./ssl/certs:/etc/nginx/ssl:ro
- nginx_logs:/var/log/nginx
depends_on:
- api-gateway
- client
networks:
- msa-frontend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 5s
retries: 3
deploy:
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
# Frontend Service
client:
image: msa-client:latest
container_name: msa-client-prod
restart: always
environment:
NODE_ENV: production
volumes:
- client_logs:/var/log/nginx
depends_on:
api-gateway:
condition: service_healthy
networks:
- msa-frontend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 5s
retries: 3
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
# Monitoring Services
prometheus:
image: prom/prometheus:v2.47.0
container_name: msa-prometheus-prod
restart: always
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'
volumes:
- ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
networks:
- msa-backend
- msa-monitoring
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
grafana:
image: grafana/grafana:10.1.0
container_name: msa-grafana-prod
restart: always
environment:
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
GF_USERS_ALLOW_SIGN_UP: false
volumes:
- grafana_data:/var/lib/grafana
- ./config/grafana/provisioning:/etc/grafana/provisioning:ro
secrets:
- grafana_admin_password
networks:
- msa-monitoring
depends_on:
- prometheus
deploy:
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
# Log Management
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.9.0
container_name: msa-elasticsearch-prod
restart: always
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- xpack.security.enabled=false
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
networks:
- msa-logging
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
reservations:
memory: 512M
cpus: '0.25'
logstash:
image: docker.elastic.co/logstash/logstash:8.9.0
container_name: msa-logstash-prod
restart: always
volumes:
- ./config/logstash/pipeline:/usr/share/logstash/pipeline:ro
- ./config/logstash/config:/usr/share/logstash/config:ro
networks:
- msa-logging
depends_on:
- elasticsearch
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
kibana:
image: docker.elastic.co/kibana/kibana:8.9.0
container_name: msa-kibana-prod
restart: always
environment:
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
networks:
- msa-logging
depends_on:
- elasticsearch
deploy:
resources:
limits:
memory: 512M
cpus: '0.25'
reservations:
memory: 256M
cpus: '0.1'
# Docker Secrets
secrets:
mongodb_root_username:
file: ./secrets/mongodb_root_username.txt
mongodb_root_password:
file: ./secrets/mongodb_root_password.txt
mongodb_uri:
file: ./secrets/mongodb_uri.txt
redis_password:
file: ./secrets/redis_password.txt
jwt_secret:
file: ./secrets/jwt_secret.txt
refresh_token_secret:
file: ./secrets/refresh_token_secret.txt
grafana_admin_password:
file: ./secrets/grafana_admin_password.txt
# Named Volumes
volumes:
mongodb_data:
driver: local
mongodb_config:
driver: local
redis_data:
driver: local
auth_logs:
driver: local
posts_logs:
driver: local
comments_logs:
driver: local
gateway_logs:
driver: local
client_logs:
driver: local
nginx_logs:
driver: local
posts_uploads:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
elasticsearch_data:
driver: local
# Networks
networks:
msa-backend:
driver: bridge
internal: true
ipam:
config:
- subnet: 172.21.0.0/16
msa-frontend:
driver: bridge
ipam:
config:
- subnet: 172.22.0.0/16
msa-monitoring:
driver: bridge
internal: true
ipam:
config:
- subnet: 172.23.0.0/16
msa-logging:
driver: bridge
internal: true
ipam:
config:
- subnet: 172.24.0.0/16