Repository navigation
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
342 lines (327 loc) · 16.2 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
342 lines (327 loc) · 16.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
# ============================================================================
# Production Docker Compose — air-gapped deployment behind a private registry.
# Set REGISTRY in the environment (e.g. REGISTRY=nexus.example.com).
#
# Uses Dockerfile.prod files that pull from internal Nexus repo.
# No internet access required.
#
# Usage:
# docker compose -f docker-compose.prod.yml build
# docker compose -f docker-compose.prod.yml up -d
#
# Prerequisites on Nexus (${REGISTRY}):
# Docker Hub proxy: ${REGISTRY}/docker-hub/
# PyPI proxy: ${REGISTRY}/pypi-proxy/simple/
# NPM proxy: ${REGISTRY}/npm-proxy/
# APT proxy: ${REGISTRY}/apt-proxy/
# Raw binaries: ${REGISTRY}/raw/ (docker CLI, playwright)
#
# Base images pulled from Nexus Docker Hub proxy:
# ${REGISTRY}/docker-hub/python:3.12-slim
# ${REGISTRY}/docker-hub/node:20-alpine
# ${REGISTRY}/docker-hub/nginx:alpine
# ${REGISTRY}/docker-hub/pgvector/pgvector:pg16
# ${REGISTRY}/docker-hub/redis:7-alpine
# ============================================================================
services:
# ── Infrastructure ─────────────────────────────────────────────────────────
postgres:
image: ${REGISTRY}/docker-hub/pgvector/pgvector:pg16
container_name: atom_postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER must be set}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}
POSTGRES_DB: ${POSTGRES_DB:-atom_cm_db}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-atom_user} -d ${POSTGRES_DB:-atom_cm_db}"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: ${REGISTRY}/docker-hub/redis:7-alpine
container_name: atom_redis
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD:?REDIS_PASSWORD must be set}
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
# ── the Authority Platform ──────────────────────────────────────────────────────────
backend:
build:
context: ./backend
dockerfile: Dockerfile.prod
container_name: atom_backend
restart: unless-stopped
env_file:
- ./backend/.env
environment:
# Required, not defaulted. Every production control keys off this one string
# (docs suppression, HSTS, secret_key floor, config_encryption_key, the
# cleartext-URL block, the cert-agent token check) and `app_env` defaults to
# "development" — so omitting it here silently disabled all of them at once.
APP_ENV: ${APP_ENV:?APP_ENV must be set (use "production" for a production deployment)}
DATABASE_URL: postgresql://${POSTGRES_USER:?POSTGRES_USER must be set}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}@postgres:5432/${POSTGRES_DB:-atom_cm_db}
REDIS_URL: redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set}@redis:6379/0
volumes:
- ./artifacts:/app/artifacts
- ./knowledge_base:/app/knowledge_base
# The authority-policy seed document — read-only bind for first-boot seed
# of the policy singleton table. Admins maintain content via the Admin UI
# thereafter; this file is the reset-to-seed source.
#
# What ships here is an empty TEMPLATE, not policy. A production
# deployment MUST supply its own — edit this file, point
# AUTHORITY_POLICY_PATH at another, or paste into the Admin UI. Absent
# any of those the seeder falls back to the active domain pack's
# data/authority_policy.md, and failing that seeds an empty row.
- ./backend/data/authority_policy.md:/app/data/authority_policy.md:ro
# LLM call log (observability extension). One JSONL
# row per LLM round-trip with prompt/response heads (50 chars),
# input/output tokens, model name, and computed USD cost.
# Rotated by Python's RotatingFileHandler (50 MB × 10 = ~500 MB cap).
- ./logs:/app/logs
# Agentic codegen: persistent Maven cache so the OFFLINE verify build
# (`mvn -o`) resolves artifacts. MUST be warmed once by an ONLINE build
# into this volume, or the first verify run fails to resolve.
# Shared with celery_worker so core-repo `install` output is visible to
# the app-repo build (network-core → network-2.0).
# /home/appuser/.m2, not /root/.m2 — Dockerfile.prod now drops to appuser.
- m2_cache:/home/appuser/.m2
# Agentic workspace clones (200MB-2GB each). A named volume keeps them off
# the container layer and lets GC reclaim space. Size the host generously.
- agentic_workspace:/app/workspace
# Architecture review A0 (Critical): do NOT publish this port to the
# host. All ingress must go through nginx, which is the only layer
# enforcing TLS, mTLS, the rate limiter, and client_max_body_size.
# Publishing 8000 here would let anyone who can reach the host bypass
# every one of those controls. For host-side debugging, use
# `docker compose -f docker-compose.prod.yml exec backend sh` or, if a
# direct HTTP path from the host is genuinely required, bind to
# loopback only: `ports: ["127.0.0.1:8000:8000"]` — never `0.0.0.0`.
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
command: >
sh -c "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2"
networks:
# A2A calls to the Partner Platform (deployed separately, see §Partner
# Platform below) travel over the shared `certagent_cert-net` bridge.
# Without this attachment the backend cannot reach `partner_backend:8001`.
- default
- cert-net
celery_worker:
build:
context: ./backend
dockerfile: Dockerfile.prod
container_name: atom_celery
restart: unless-stopped
env_file:
- ./backend/.env
environment:
# Required, not defaulted. Every production control keys off this one string
# (docs suppression, HSTS, secret_key floor, config_encryption_key, the
# cleartext-URL block, the cert-agent token check) and `app_env` defaults to
# "development" — so omitting it here silently disabled all of them at once.
APP_ENV: ${APP_ENV:?APP_ENV must be set (use "production" for a production deployment)}
DATABASE_URL: postgresql://${POSTGRES_USER:?POSTGRES_USER must be set}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}@postgres:5432/${POSTGRES_DB:-atom_cm_db}
REDIS_URL: redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set}@redis:6379/0
volumes:
- ./artifacts:/app/artifacts
- ./knowledge_base:/app/knowledge_base
- ./logs:/app/logs
# Same shared Maven cache + workspace as backend — the celery worker is what
# actually runs the verify build and the push, so it needs both .
# /home/appuser/.m2, not /root/.m2 — Dockerfile.prod now drops to appuser.
- m2_cache:/home/appuser/.m2
- agentic_workspace:/app/workspace
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Scoped to the DEFAULT queue only — the long agentic tasks get their own
# worker below (A15). -Q is mandatory on BOTH services: celery_tasks.py routes
# agentic.* to the `agentic` queue, so a worker with no -Q would consume only
# `celery` and leave every agentic message unread in Redis (runs created but
# never driven — the UI hangs on "Getting ready" with nothing in the logs).
command: celery -A app.services.celery_tasks worker --loglevel=info -Q celery
networks:
# Same rationale as backend: A2A push/retry tasks target `partner_backend`.
- default
- cert-net
# Dedicated agentic worker. Splitting the queues is what makes the routing in
# celery_tasks.py actually mean something: an agentic run clones repos, makes
# dozens of LLM calls and runs Maven builds for minutes-to-hours, and on a
# shared worker that starves the short periodic sweeps
# (a2a retry every 2 min, agentic.recover every 2 min, jobs/negotiation sweeps).
# Lower concurrency than the sweep worker on purpose — each slot can hold a
# multi-GB clone plus a JVM heap, so this is bounded by disk and RAM, not CPU.
celery_worker_agentic:
build:
context: ./backend
dockerfile: Dockerfile.prod
container_name: atom_celery_agentic
restart: unless-stopped
env_file:
- ./backend/.env
environment:
# Required, not defaulted. Every production control keys off this one string
# (docs suppression, HSTS, secret_key floor, config_encryption_key, the
# cleartext-URL block, the cert-agent token check) and `app_env` defaults to
# "development" — so omitting it here silently disabled all of them at once.
APP_ENV: ${APP_ENV:?APP_ENV must be set (use "production" for a production deployment)}
DATABASE_URL: postgresql://${POSTGRES_USER:?POSTGRES_USER must be set}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}@postgres:5432/${POSTGRES_DB:-atom_cm_db}
REDIS_URL: redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set}@redis:6379/0
volumes:
- ./artifacts:/app/artifacts
- ./knowledge_base:/app/knowledge_base
- ./logs:/app/logs
# This worker is the one that actually runs the verify build and the push,
# so it needs the Maven cache and the shared agentic workspace.
# /home/appuser/.m2, not /root/.m2 — Dockerfile.prod now drops to appuser.
- m2_cache:/home/appuser/.m2
- agentic_workspace:/app/workspace
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
command: >
celery -A app.services.celery_tasks worker --loglevel=info
-Q agentic --concurrency=${AGENTIC_WORKER_CONCURRENCY:-2}
networks:
# Agentic runs make A2A calls to partner (certification push, telemetry).
- default
- cert-net
# Celery beat — fires the periodic sweeps (agentic.recover, gc_workspaces,
# negotiation/jobs sweeps). WITHOUT this service the `agentic.recover` sweep
# never runs, so a run whose worker dies (deploy, crash, OOM, node restart)
# stays wedged in "active" forever with NO auto-recovery — the operator has to
# unstick it by hand. Exactly one beat per deployment; never scale it >1
# (duplicate ticks would double-fire every scheduled task).
celery_beat:
build:
context: ./backend
dockerfile: Dockerfile.prod
container_name: atom_celery_beat
restart: unless-stopped
env_file:
- ./backend/.env
environment:
# Required, not defaulted. Every production control keys off this one string
# (docs suppression, HSTS, secret_key floor, config_encryption_key, the
# cleartext-URL block, the cert-agent token check) and `app_env` defaults to
# "development" — so omitting it here silently disabled all of them at once.
APP_ENV: ${APP_ENV:?APP_ENV must be set (use "production" for a production deployment)}
DATABASE_URL: postgresql://${POSTGRES_USER:?POSTGRES_USER must be set}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}@postgres:5432/${POSTGRES_DB:-atom_cm_db}
REDIS_URL: redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set}@redis:6379/0
volumes:
# Beat only dispatches task names onto the queue (the worker does the work),
# so it needs neither the Maven cache nor the agentic workspace — just app
# imports + a place for its own log.
- ./artifacts:/app/artifacts
- ./knowledge_base:/app/knowledge_base
- ./logs:/app/logs
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
command: celery -A app.services.celery_tasks beat --loglevel=info
networks:
# Beat dispatches sweeps that eventually push to partner via A2A workers;
# keeping it on the same network as the workers avoids surprising splits.
- default
- cert-net
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.prod
container_name: atom_frontend
restart: unless-stopped
depends_on:
- backend
# ── Partner Platform ───────────────────────────────────────────────────────
#
# Deployed separately from its own repository and compose file:
# https://github.com/npci/atom-partner-platform
#
# It reaches this platform over A2A as an authenticated client, so there is
# nothing to co-deploy here. Partner ingress, TLS and datastore are the
# partner deployment's own concern.
#
# The `cert-net` attachment on `backend`, `celery*` and `nginx` is what makes
# cross-stack traffic to that separate deployment work — backend/celery reach
# partner over A2A, nginx proxies the `/partner/*` routes defined in
# `nginx/nginx.conf`. No change here when the partner comes up in its own
# stack on the same shared network.
# ── Nginx ──────────────────────────────────────────────────────────────────
nginx:
image: ${REGISTRY}/docker-hub/nginx:alpine
container_name: atom_nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
# mTLS-tier ingress. Partners on that tier present a pinned client
# cert here; every other participant tier continues using :443. The same
# ./nginx/ssl mount also needs to contain `clients-ca.crt` (the
# authority's internal CA bundle) — see the header of nginx/nginx.conf
# for how the three files are provisioned.
- "8443:8443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
# TLS termination. Mount the cert + key read-only; the :8443 mTLS
# block also reads `clients-ca.crt` from this same directory.
# Operator must populate ./nginx/ssl/{server.crt,server.key} (and
# ./nginx/ssl/clients-ca.crt for mTLS) before `docker compose up`
# (or set NGINX_SSL_DIR to a different path holding the files).
# For dev / smoke a self-signed cert + a self-issued clients-CA
# is acceptable; production uses the authority's internal CA.
- ${NGINX_SSL_DIR:-./nginx/ssl}:/etc/nginx/ssl:ro
# certbot ACME challenge volume — keeps `--webroot` renewal flows
# working without rebuilding the container.
- ${NGINX_ACME_WEBROOT:-./nginx/acme}:/var/www/certbot:ro
depends_on:
- backend
- frontend
networks:
# `nginx/nginx.conf` proxies `/partner/*` at `partner_backend:8001` and
# `partner_frontend:80` via per-request DNS (`resolver 127.0.0.11`).
# Docker's embedded resolver only resolves services on networks the
# container is attached to, so nginx must sit on `cert-net` alongside the
# partner stack for those routes to reach anything.
- default
- cert-net
volumes:
postgres_data:
redis_data:
m2_cache: # warmed Maven cache for offline agentic verify builds
agentic_workspace: # agentic run clones (GC'd by the hourly sweep)
networks:
# Implicit project network — declared explicitly so services that opt into
# `cert-net` can still keep `default` (services listing `networks:` only join
# the listed ones, not also the default).
default:
# External network for cross-stack traffic to the Partner Platform (deployed
# separately per the §Partner Platform stub above). Create it before the
# first `docker compose up`:
#
# docker network create certagent_cert-net
#
# Backend/celery need it to make A2A calls to the partner; nginx needs it to
# route the `/partner/*` paths defined in `nginx/nginx.conf`. Missing the
# network shows up as "network certagent_cert-net declared as external, but
# could not be found" at startup.
cert-net:
external: true
name: certagent_cert-net