forked from Carbon-Ledger-stellar/carbonledger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
527 lines (498 loc) · 18.9 KB
/
Copy pathdocker-compose.yml
File metadata and controls
527 lines (498 loc) · 18.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
version: "3.9"
# ── Shared logging driver ─────────────────────────────────────────────────────
# All app services use json-file so Promtail can tail them via the Docker socket.
x-logging: &default-logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
# ── Resource limit anchors ────────────────────────────────────────────────────
# Override via env vars (e.g. BACKEND_MEM_LIMIT=1g) for non-testnet environments.
x-resources-backend: &resources-backend
deploy:
resources:
limits:
memory: ${BACKEND_MEM_LIMIT:-512m}
cpus: "${BACKEND_CPU_LIMIT:-0.75}"
reservations:
memory: ${BACKEND_MEM_RESERVATION:-128m}
cpus: "${BACKEND_CPU_RESERVATION:-0.25}"
x-resources-frontend: &resources-frontend
deploy:
resources:
limits:
memory: ${FRONTEND_MEM_LIMIT:-256m}
cpus: "${FRONTEND_CPU_LIMIT:-0.50}"
reservations:
memory: ${FRONTEND_MEM_RESERVATION:-64m}
cpus: "${FRONTEND_CPU_RESERVATION:-0.10}"
x-resources-postgres: &resources-postgres
deploy:
resources:
limits:
memory: ${POSTGRES_MEM_LIMIT:-1g}
cpus: "${POSTGRES_CPU_LIMIT:-1.00}"
reservations:
memory: ${POSTGRES_MEM_RESERVATION:-256m}
cpus: "${POSTGRES_CPU_RESERVATION:-0.25}"
x-resources-redis: &resources-redis
deploy:
resources:
limits:
memory: ${REDIS_MEM_LIMIT:-256m}
cpus: "${REDIS_CPU_LIMIT:-0.25}"
reservations:
memory: ${REDIS_MEM_RESERVATION:-32m}
cpus: "${REDIS_CPU_RESERVATION:-0.05}"
x-resources-oracle: &resources-oracle
deploy:
resources:
limits:
memory: ${ORACLE_MEM_LIMIT:-256m}
cpus: "${ORACLE_CPU_LIMIT:-0.50}"
reservations:
memory: ${ORACLE_MEM_RESERVATION:-64m}
cpus: "${ORACLE_CPU_RESERVATION:-0.10}"
x-resources-observability: &resources-observability
deploy:
resources:
limits:
memory: ${OBSERVABILITY_MEM_LIMIT:-256m}
cpus: "${OBSERVABILITY_CPU_LIMIT:-0.25}"
reservations:
memory: ${OBSERVABILITY_MEM_RESERVATION:-64m}
cpus: "${OBSERVABILITY_CPU_RESERVATION:-0.05}"
services:
# ── Infrastructure ──────────────────────────────────────────────────────────
postgres:
image: postgres:16-alpine
restart: unless-stopped
<<: *resources-postgres
environment:
POSTGRES_DB: carbonledger
POSTGRES_USER: carbonledger
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
volumes:
- postgres_data:/var/lib/postgresql/data
# Only expose directly for local development/debugging.
# In production, remove this port binding and only connect via pgbouncer.
ports:
- "5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U carbonledger"]
interval: 10s
timeout: 5s
retries: 5
logging: *default-logging
redis-primary:
image: redis:7-alpine
restart: unless-stopped
<<: *resources-redis
command: redis-server --requirepass ${REDIS_PASSWORD:-}
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-}", "ping"]
interval: 10s
timeout: 5s
retries: 5
logging: *default-logging
redis-replica:
image: redis:7-alpine
restart: unless-stopped
<<: *resources-redis
command: redis-server --replicaof redis-primary 6379 --masterauth ${REDIS_PASSWORD:-} --requirepass ${REDIS_PASSWORD:-}
depends_on:
redis-primary:
condition: service_healthy
logging: *default-logging
redis-sentinel:
image: bitnami/redis-sentinel:7.2
restart: unless-stopped
<<: *resources-redis
environment:
- REDIS_SENTINEL_QUORUM=1
- REDIS_MASTER_HOST=redis-primary
- REDIS_MASTER_PORT_NUMBER=6379
- REDIS_MASTER_SET=mymaster
- REDIS_SENTINEL_PASSWORD=${REDIS_PASSWORD:-}
- REDIS_MASTER_PASSWORD=${REDIS_PASSWORD:-}
healthcheck:
test: ["CMD", "redis-cli", "-p", "26379", "ping"]
interval: 10s
timeout: 5s
retries: 5
depends_on:
redis-primary:
condition: service_healthy
logging: *default-logging
# ── Application services ────────────────────────────────────────────────────
# ── Connection Pool ────────────────────────────────────────────────────────────
# PgBouncer sits between the application and PostgreSQL, multiplexing up to
# 200 client connections down to a managed pool of 100 server connections.
# Pool mode: transaction — each connection is returned to the pool after
# every transaction, maximising concurrency for stateless NestJS requests.
#
# Monitor pool health at any time:
# psql -h localhost -p 6432 -U carbonledger pgbouncer -c "SHOW STATS;"
# psql -h localhost -p 6432 -U carbonledger pgbouncer -c "SHOW POOLS;"
# psql -h localhost -p 6432 -U carbonledger pgbouncer -c "SHOW CLIENTS;"
pgbouncer:
build:
context: ./pgbouncer
dockerfile: Dockerfile
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
# These override values in pgbouncer.ini at runtime via env substitution.
# The DB_* vars allow the image to generate userlist.txt on first boot
# (supported by edoburu/pgbouncer via environment variables).
DB_USER: carbonledger
DB_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: carbonledger
POOL_MODE: ${PGBOUNCER_POOL_MODE:-transaction}
MAX_CLIENT_CONN: ${PGBOUNCER_MAX_CLIENT_CONN:-200}
DEFAULT_POOL_SIZE: ${PGBOUNCER_DEFAULT_POOL_SIZE:-100}
MIN_POOL_SIZE: 10
RESERVE_POOL_SIZE: 20
RESERVE_POOL_TIMEOUT: 5
SERVER_IDLE_TIMEOUT: 600
LOG_CONNECTIONS: 1
LOG_DISCONNECTIONS: 1
STATS_PERIOD: 60
AUTH_TYPE: md5
ADMIN_USERS: carbonledger
STATS_USERS: carbonledger
ports:
# Expose PgBouncer admin port for monitoring tools (not for app traffic)
- "6432:5432"
healthcheck:
# pg_isready targets PgBouncer which proxies to postgres
test: ["CMD-SHELL", "pg_isready -h localhost -p 5432 -U carbonledger"]
interval: 10s
timeout: 5s
retries: 5
# ── Cache ──────────────────────────────────────────────────────────────────────
# Redis is used for 5-minute TTL caching of expensive read queries:
# - GET /api/v1/projects
# - GET /api/v1/marketplace/listings
# - GET /api/v1/oracle/benchmark-price
# Cache is invalidated on any write (create / update / delete) to those resources.
redis:
image: redis:7-alpine
restart: unless-stopped
command: >
redis-server
--maxmemory 256mb
--maxmemory-policy allkeys-lru
--save ""
--appendonly no
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
# ── Backend API ────────────────────────────────────────────────────────────────
backend:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-backend
depends_on:
pgbouncer:
condition: service_healthy
redis:
condition: service_healthy
redis-sentinel:
condition: service_healthy
environment:
DATABASE_URL: postgresql://carbonledger:${POSTGRES_PASSWORD:-changeme}@postgres:5432/carbonledger
JWT_SECRET: ${JWT_SECRET}
JWT_EXPIRY: 7d
REDIS_URL: redis://redis:6379
STELLAR_NETWORK: ${STELLAR_NETWORK:-testnet}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
FRONTEND_URL: http://localhost:3000
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://localhost:3000}
PORT: 3001
REDIS_SENTINELS: redis-sentinel:26379
REDIS_SENTINEL_NAME: mymaster
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
LOG_LEVEL: ${LOG_LEVEL:-info}
OTEL_ENABLED: ${OTEL_ENABLED:-true}
OTEL_SERVICE_NAME: carbonledger-backend
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
OTEL_TRACES_SAMPLER_ARG: ${OTEL_TRACES_SAMPLER_ARG:-0.1}
ports:
- "3001:3001"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:3001/health/ready || exit 1"]
interval: 15s
timeout: 5s
retries: 3
start_period: 30s
command: >
sh -c "npx prisma migrate deploy && node dist/main"
logging: *default-logging
# ── Frontend ───────────────────────────────────────────────────────────────────
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-frontend
depends_on:
backend:
condition: service_healthy
environment:
NEXT_PUBLIC_API_URL: http://localhost:3001/api/v1
NEXT_PUBLIC_STELLAR_NETWORK: ${STELLAR_NETWORK:-testnet}
NEXT_PUBLIC_HORIZON_URL: ${STELLAR_HORIZON_URL:-https://horizon-testnet.stellar.org}
NEXT_PUBLIC_SOROBAN_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
NEXT_PUBLIC_REGISTRY_CONTRACT: ${CARBON_REGISTRY_CONTRACT_ID}
NEXT_PUBLIC_CREDIT_CONTRACT: ${CARBON_CREDIT_CONTRACT_ID}
NEXT_PUBLIC_MARKETPLACE_CONTRACT: ${CARBON_MARKETPLACE_CONTRACT_ID}
NEXT_PUBLIC_ORACLE_CONTRACT: ${CARBON_ORACLE_CONTRACT_ID}
NEXT_PUBLIC_USDC_CONTRACT: ${USDC_CONTRACT_ID}
ports:
- "3000:3000"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:3000/ || exit 1"]
interval: 15s
timeout: 5s
retries: 3
start_period: 30s
logging: *default-logging
# ── Oracle Services ───────────────────────────────────────────────────────────
oracle_verification:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
CARBON_REGISTRY_CONTRACT_ID: ${CARBON_REGISTRY_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
DATABASE_URL: postgresql://carbonledger:${POSTGRES_PASSWORD:-changeme}@pgbouncer:5432/carbonledger
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
GOLD_STANDARD_API_URL: ${GOLD_STANDARD_API_URL}
GOLD_STANDARD_API_KEY: ${GOLD_STANDARD_API_KEY}
VERRA_VCS_API_URL: ${VERRA_VCS_API_URL}
VERRA_VCS_API_KEY: ${VERRA_VCS_API_KEY}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
command: python3 verification_listener.py
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "ps aux | grep verification_listener.py | grep -v grep || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
oracle_verification_standby:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
CARBON_REGISTRY_CONTRACT_ID: ${CARBON_REGISTRY_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
DATABASE_URL: postgresql://carbonledger:${POSTGRES_PASSWORD:-changeme}@postgres:5432/carbonledger
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
GOLD_STANDARD_API_URL: ${GOLD_STANDARD_API_URL}
GOLD_STANDARD_API_KEY: ${GOLD_STANDARD_API_KEY}
VERRA_VCS_API_URL: ${VERRA_VCS_API_URL}
VERRA_VCS_API_KEY: ${VERRA_VCS_API_KEY}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
ORACLE_STANDBY_MODE: "true"
FAILOVER_SERVICE_NAME: verification_listener
command: python3 verification_listener.py
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "ps aux | grep verification_listener.py | grep -v grep || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
oracle_price:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
XPANSIV_API_KEY: ${XPANSIV_API_KEY}
TOUCAN_API_KEY: ${TOUCAN_API_KEY}
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
command: python3 price_oracle.py
healthcheck:
test: ["CMD-SHELL", "ps aux | grep price_oracle.py | grep -v grep || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
oracle_price_standby:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
XPANSIV_API_KEY: ${XPANSIV_API_KEY}
TOUCAN_API_KEY: ${TOUCAN_API_KEY}
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
ORACLE_STANDBY_MODE: "true"
FAILOVER_SERVICE_NAME: price_oracle
command: python3 price_oracle.py
healthcheck:
test: ["CMD-SHELL", "ps aux | grep price_oracle.py | grep -v grep || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
oracle_satellite:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
BACKEND_API_URL: http://backend:3001/api/v1
GEE_WEBHOOK_SECRET: ${GEE_WEBHOOK_SECRET}
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
SATELLITE_MONITOR_PORT: 5001
LOG_LEVEL: ${LOG_LEVEL:-INFO}
command: python3 satellite_monitor.py
ports:
- "5001:5001"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:5001/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
oracle_satellite_standby:
build:
context: ./oracle
dockerfile: Dockerfile
restart: unless-stopped
<<: *resources-oracle
environment:
ORACLE_SECRET_KEY: ${ORACLE_SECRET_KEY}
CARBON_ORACLE_CONTRACT_ID: ${CARBON_ORACLE_CONTRACT_ID}
STELLAR_RPC_URL: ${STELLAR_RPC_URL:-https://soroban-testnet.stellar.org}
BACKEND_API_URL: http://backend:3001/api/v1
GEE_WEBHOOK_SECRET: ${GEE_WEBHOOK_SECRET}
ADMIN_ALERT_WEBHOOK: ${ADMIN_ALERT_WEBHOOK}
SATELLITE_MONITOR_PORT: 5002
LOG_LEVEL: ${LOG_LEVEL:-INFO}
ORACLE_STANDBY_MODE: "true"
FAILOVER_SERVICE_NAME: satellite_monitor
command: python3 satellite_monitor.py
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:5002/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging: *default-logging
# ── Log aggregation stack ───────────────────────────────────────────────────
loki:
image: grafana/loki:2.9.8
restart: unless-stopped
<<: *resources-observability
ports:
- "3100:3100"
volumes:
- ./logging/loki/loki.yml:/etc/loki/loki.yml:ro
- loki_data:/loki
command: -config.file=/etc/loki/loki.yml
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:3100/ready || exit 1"]
interval: 10s
timeout: 5s
retries: 5
logging: *default-logging
promtail:
image: grafana/promtail:2.9.8
restart: unless-stopped
<<: *resources-observability
volumes:
- ./logging/promtail/promtail.yml:/etc/promtail/promtail.yml:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
command: -config.file=/etc/promtail/promtail.yml
depends_on:
loki:
condition: service_healthy
logging: *default-logging
grafana:
image: grafana/grafana:10.4.2
restart: unless-stopped
<<: *resources-observability
ports:
- "3200:3000"
environment:
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin}
GF_USERS_ALLOW_SIGN_UP: "false"
GF_ALERTING_ENABLED: "true"
GF_UNIFIED_ALERTING_ENABLED: "true"
volumes:
- ./logging/grafana/provisioning:/etc/grafana/provisioning:ro
- grafana_data:/var/lib/grafana
depends_on:
loki:
condition: service_healthy
logging: *default-logging
jaeger:
image: jaegertracing/all-in-one:1.57
restart: unless-stopped
<<: *resources-observability
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- "16686:16686"
- "4317:4317"
- "4318:4318"
- "6831:6831/udp"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://localhost:16686/ || exit 1"]
interval: 10s
timeout: 5s
retries: 5
logging: *default-logging
volumes:
postgres_data:
redis_data:
loki_data:
grafana_data: