-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
169 lines (163 loc) · 5.79 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
169 lines (163 loc) · 5.79 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
# PennyCore — production-shape compose file (Day 29, Phase 6).
#
# This file is the local rehearsal of the production deploy. It is
# intentionally close to what fly.io / railway / ECS would orchestrate,
# minus the cloud-side load balancer:
#
# - Builds from Dockerfile.prod (gunicorn supervisor, tini PID 1).
# - No bind-mounts. The source tree inside the image is frozen at
# build time.
# - No uvicorn hot-reload flag. Workers are recycled by gunicorn,
# not by file watchers.
# - `restart: unless-stopped` on every service — matches the policy
# fly.io / railway use by default.
# - `WEB_CONCURRENCY` parameterises gunicorn workers per service so
# a hosted instance with 1 vCPU and a beefier 4 vCPU host both
# read the same compose file.
# - Postgres + Redis carry the same volumes/healthchecks as the dev
# compose, but the published-port mappings are commented out —
# prod only exposes the FastAPI surface.
# - `.env.prod` (NOT committed; documented in `.env.example.prod`)
# supplies the real keys.
#
# Boot:
# docker compose -f docker-compose.prod.yml --env-file .env.prod up -d
#
# Tear down:
# docker compose -f docker-compose.prod.yml down
#
# Smoke test once up:
# curl http://localhost:8001/info # context-engine self-describes
# curl http://localhost:8001/readyz
# curl http://localhost:8002/readyz
#
# The `fly.io` deploy adapter in `scripts/deploy_fly.sh` mirrors the
# environment shape below — anything added here MUST be replicated
# in fly secrets via that script.
services:
postgres:
image: pgvector/pgvector:pg16
container_name: pennycore-postgres-prod
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-pennycore}
POSTGRES_USER: ${POSTGRES_USER:-pennycore}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set in .env.prod}
# Production: do NOT expose postgres to the host. The service-network
# alias is all the app containers need. Uncomment locally only if
# you need a psql shell from the host for diagnostic work.
# ports:
# - "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data_prod:/var/lib/postgresql/data
- ./migrations/versions:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-pennycore} -d ${POSTGRES_DB:-pennycore}"]
interval: 10s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
container_name: pennycore-redis-prod
restart: unless-stopped
# Same reasoning as Postgres — no host port mapping in prod.
# ports:
# - "${REDIS_PORT:-6379}:6379"
volumes:
- redis_data_prod:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 10
context_engine:
build:
context: .
dockerfile: Dockerfile.prod
args:
# Override these at build time. The defaults make the build
# succeed without git context (e.g. inside a fresh CI runner).
GIT_SHA: ${GIT_SHA:-unknown}
BUILD_DATE: ${BUILD_DATE:-unknown}
IMAGE_VERSION: ${IMAGE_VERSION:-0.2.0}
image: pennycore:prod
container_name: pennycore-context-engine-prod
restart: unless-stopped
# The Dockerfile CMD already points at context_engine.api:app — no
# override needed here. Worker count is per-service so the
# orchestrator can run hotter (decision pipeline is the latency
# bottleneck on a real workload).
environment:
WEB_CONCURRENCY: ${CONTEXT_ENGINE_WORKERS:-2}
DATABASE_URL: ${DATABASE_URL:-postgresql://pennycore:${POSTGRES_PASSWORD}@postgres:5432/pennycore}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
LLM_PROVIDER: ${LLM_PROVIDER:-mock}
MOCK_LLM: ${MOCK_LLM:-false}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
AZURE_API_KEY: ${AZURE_API_KEY:-}
AZURE_ENDPOINT: ${AZURE_ENDPOINT:-}
AZURE_API_VERSION: ${AZURE_API_VERSION:-}
LLM_MODEL: ${LLM_MODEL:-}
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
ports:
- "${CONTEXT_ENGINE_PORT:-8001}:8000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
orchestrator:
build:
context: .
dockerfile: Dockerfile.prod
args:
GIT_SHA: ${GIT_SHA:-unknown}
BUILD_DATE: ${BUILD_DATE:-unknown}
IMAGE_VERSION: ${IMAGE_VERSION:-0.2.0}
image: pennycore:prod
container_name: pennycore-orchestrator-prod
restart: unless-stopped
# Override the image's default CMD to launch the orchestrator app.
# Gunicorn flags mirror the Dockerfile's context-engine CMD so the
# two services have identical lifecycle behavior.
command:
- gunicorn
- orchestrator.api:app
- --worker-class
- uvicorn.workers.UvicornWorker
- --workers
- "${ORCHESTRATOR_WORKERS:-3}"
- --bind
- 0.0.0.0:8000
- --timeout
- "30"
- --graceful-timeout
- "20"
- --keep-alive
- "5"
- --access-logfile
- "-"
- --error-logfile
- "-"
environment:
WEB_CONCURRENCY: ${ORCHESTRATOR_WORKERS:-3}
DATABASE_URL: ${DATABASE_URL:-postgresql://pennycore:${POSTGRES_PASSWORD}@postgres:5432/pennycore}
REDIS_URL: ${REDIS_URL:-redis://redis:6379/0}
LLM_PROVIDER: ${LLM_PROVIDER:-mock}
MOCK_LLM: ${MOCK_LLM:-false}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
AZURE_API_KEY: ${AZURE_API_KEY:-}
AZURE_ENDPOINT: ${AZURE_ENDPOINT:-}
AZURE_API_VERSION: ${AZURE_API_VERSION:-}
LLM_MODEL: ${LLM_MODEL:-}
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
ports:
- "${ORCHESTRATOR_PORT:-8002}:8000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
volumes:
postgres_data_prod:
redis_data_prod: