-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
634 lines (612 loc) · 17.9 KB
/
docker-compose.yml
File metadata and controls
634 lines (612 loc) · 17.9 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
# =============================================================================
# Nivo - Docker Compose (Base Configuration)
# =============================================================================
#
# Usage:
# Development: docker compose up -d (auto-loads docker-compose.override.yml)
# Production: docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Monitoring: docker compose -f docker-compose.yml -f docker-compose.observability.yml up -d
#
# Memory:
# - Development: ~1.1GB (this file alone)
# - Production: ~750MB (with docker-compose.prod.yml for 1GB VPS)
# - Requires 2GB swap enabled on host
# - See scripts/setup-server.sh for swap configuration
#
# Security:
# - All containers implement cap_drop: ALL and no-new-privileges: true
# - Only nginx exposes external ports (80, 443)
# - All backend services communicate via internal Docker network
#
# =============================================================================
services:
# ===========================================================================
# INFRASTRUCTURE
# ===========================================================================
postgres:
image: postgres:15-alpine
container_name: nivo-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-nivo}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-nivo}
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-nivo}"]
interval: 10s
timeout: 5s
retries: 5
networks:
- nivo-network
# Security hardening
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- DAC_OVERRIDE
deploy:
resources:
limits:
memory: 256M
reservations:
memory: 128M
redis:
image: redis:7-alpine
container_name: nivo-redis
restart: unless-stopped
command: >
redis-server
--appendonly yes
--requirepass ${REDIS_PASSWORD}
--maxmemory 48mb
--maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
- nivo-network
# Security hardening (Redis runs as non-root uid 999)
# Redis needs SETUID/SETGID to switch to redis user
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- SETUID
- SETGID
read_only: true
tmpfs:
- /tmp:size=64M
deploy:
resources:
limits:
memory: 64M
pids: 32
reservations:
memory: 32M
# ===========================================================================
# BACKEND SERVICES
# ===========================================================================
identity-service:
build:
context: .
dockerfile: services/identity/Dockerfile
container_name: nivo-identity
restart: unless-stopped
environment:
SERVICE_PORT: 8080
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
JWT_SECRET: ${JWT_SECRET}
JWT_EXPIRY_HOURS: ${JWT_EXPIRY_HOURS:-24}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
RBAC_SERVICE_URL: http://rbac-service:8082
WALLET_SERVICE_URL: http://wallet-service:8083
NOTIFICATION_SERVICE_URL: http://notification-service:8087
INTERNAL_SERVICE_SECRET: ${INTERNAL_SERVICE_SECRET:-}
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
rbac-service:
condition: service_healthy
wallet-service:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8080/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 96M
pids: 64
reservations:
memory: 48M
ledger-service:
build:
context: .
dockerfile: services/ledger/Dockerfile
container_name: nivo-ledger
restart: unless-stopped
environment:
SERVICE_PORT: 8081
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8081/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 96M
pids: 64
rbac-service:
build:
context: .
dockerfile: services/rbac/Dockerfile
container_name: nivo-rbac
restart: unless-stopped
environment:
SERVICE_PORT: 8082
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
INTERNAL_SERVICE_SECRET: ${INTERNAL_SERVICE_SECRET:-}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8082/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 64M
pids: 32
wallet-service:
build:
context: .
dockerfile: services/wallet/Dockerfile
container_name: nivo-wallet
restart: unless-stopped
environment:
SERVICE_PORT: 8083
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
LEDGER_SERVICE_URL: http://ledger-service:8081
JWT_SECRET: ${JWT_SECRET}
INTERNAL_SERVICE_SECRET: ${INTERNAL_SERVICE_SECRET:-}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
ledger-service:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8083/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 96M
pids: 64
transaction-service:
build:
context: .
dockerfile: services/transaction/Dockerfile
container_name: nivo-transaction
restart: unless-stopped
environment:
SERVICE_PORT: 8084
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
WALLET_SERVICE_URL: http://wallet-service:8083
LEDGER_SERVICE_URL: http://ledger-service:8081
RISK_SERVICE_URL: http://risk-service:8085
JWT_SECRET: ${JWT_SECRET}
INTERNAL_SERVICE_SECRET: ${INTERNAL_SERVICE_SECRET:-}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
wallet-service:
condition: service_healthy
ledger-service:
condition: service_healthy
risk-service:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8084/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 96M
pids: 64
risk-service:
build:
context: .
dockerfile: services/risk/Dockerfile
container_name: nivo-risk
restart: unless-stopped
environment:
SERVICE_PORT: 8085
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8085/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 64M
pids: 32
notification-service:
build:
context: .
dockerfile: services/notification/Dockerfile
container_name: nivo-notification
restart: unless-stopped
environment:
SERVICE_PORT: 8087
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
SIM_DELIVERY_DELAY_MS: 1000
SIM_FINAL_DELAY_MS: 2000
SIM_FAILURE_RATE_PERCENT: 10.0
SIM_MAX_RETRY_ATTEMPTS: 3
SIM_RETRY_DELAY_MS: 2000
depends_on:
postgres:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8087/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 64M
pids: 32
simulation-service:
build:
context: .
dockerfile: services/simulation/Dockerfile
container_name: nivo-simulation
restart: unless-stopped
environment:
SERVICE_PORT: 8086
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_URL: postgres://${POSTGRES_USER:-nivo}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-nivo}?sslmode=disable
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
GATEWAY_URL: http://gateway:8000
ADMIN_TOKEN: ${ADMIN_TOKEN:-}
AUTO_START_SIMULATION: ${AUTO_START_SIMULATION:-false}
TIMEZONE: Asia/Kolkata
DEFAULT_CURRENCY: INR
COUNTRY_CODE: IN
depends_on:
postgres:
condition: service_healthy
gateway:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8086/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 64M
pids: 32
# ===========================================================================
# API GATEWAY
# ===========================================================================
gateway:
build:
context: .
dockerfile: gateway/Dockerfile
container_name: nivo-gateway
restart: unless-stopped
environment:
SERVICE_PORT: 8000
ENVIRONMENT: ${ENVIRONMENT:-production}
DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
IDENTITY_SERVICE_URL: http://identity-service:8080
LEDGER_SERVICE_URL: http://ledger-service:8081
RBAC_SERVICE_URL: http://rbac-service:8082
WALLET_SERVICE_URL: http://wallet-service:8083
TRANSACTION_SERVICE_URL: http://transaction-service:8084
RISK_SERVICE_URL: http://risk-service:8085
NOTIFICATION_SERVICE_URL: http://notification-service:8087
depends_on:
identity-service:
condition: service_healthy
ledger-service:
condition: service_healthy
rbac-service:
condition: service_healthy
wallet-service:
condition: service_healthy
transaction-service:
condition: service_healthy
notification-service:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:8000/health || exit 1"]
interval: 15s
timeout: 5s
retries: 5
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 96M
pids: 64
# ===========================================================================
# FRONTEND (nginx serving React apps + reverse proxy)
# ===========================================================================
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
VITE_API_URL: ${VITE_API_URL:-https://api.nivomoney.com}
container_name: nivo-frontend
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./frontend/nginx.conf:/etc/nginx/nginx.conf:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
- /var/www/certbot:/var/www/certbot:ro
depends_on:
gateway:
condition: service_healthy
networks:
- nivo-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost/nginx-health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
- CHOWN
- SETUID
- SETGID
- DAC_OVERRIDE
deploy:
resources:
limits:
memory: 48M
pids: 32
# Certbot for SSL certificate renewal
certbot:
image: certbot/certbot
container_name: nivo-certbot
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
networks:
- nivo-network
# ===========================================================================
# OBSERVABILITY
# ===========================================================================
prometheus:
image: prom/prometheus:v2.47.0
container_name: nivo-prometheus
restart: unless-stopped
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=15d'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
- '--web.enable-lifecycle'
volumes:
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./monitoring/prometheus/alerts.yml:/etc/prometheus/alerts.yml:ro
- prometheus_data:/prometheus
# No external ports - accessed via internal network only
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:9090/-/healthy || exit 1"]
interval: 30s
timeout: 10s
retries: 3
networks:
- nivo-network
# Security hardening (runs as nobody:65534)
user: "65534:65534"
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 512M
pids: 64
reservations:
memory: 256M
grafana:
image: grafana/grafana:10.2.0
container_name: nivo-grafana
restart: unless-stopped
environment:
# Admin credentials
GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:-admin}
# Security settings
GF_SECURITY_COOKIE_SECURE: "true"
GF_SECURITY_COOKIE_SAMESITE: strict
GF_SECURITY_DISABLE_GRAVATAR: "true"
GF_SECURITY_ALLOW_EMBEDDING: "false"
# Disable sign-up
GF_USERS_ALLOW_SIGN_UP: "false"
GF_USERS_ALLOW_ORG_CREATE: "false"
# Anonymous access disabled
GF_AUTH_ANONYMOUS_ENABLED: "false"
# Server config
GF_SERVER_ROOT_URL: ${GF_SERVER_ROOT_URL:-https://grafana.nivomoney.com}
GF_SERVER_DOMAIN: ${GF_SERVER_DOMAIN:-grafana.nivomoney.com}
GF_SERVER_HTTP_PORT: "3000"
# No external ports - accessed via nginx reverse proxy at grafana.nivomoney.com
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
- ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
depends_on:
prometheus:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
networks:
- nivo-network
# Security hardening (runs as grafana:472)
user: "472:472"
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
deploy:
resources:
limits:
memory: 512M
pids: 64
reservations:
memory: 256M
volumes:
postgres_data:
driver: local
redis_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
networks:
nivo-network:
driver: bridge