-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.production.yml
More file actions
357 lines (348 loc) · 9.96 KB
/
Copy pathdocker-compose.production.yml
File metadata and controls
357 lines (348 loc) · 9.96 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
# OpenCodeHub Production Docker Compose
# ============================================================
# Usage:
# 1. Copy .env.example to .env and configure ALL secrets
# 2. Run: docker compose --profile production up -d
#
# Architecture:
# Caddy (TLS termination) → App → PostgreSQL + Redis
# → CI Runner (Docker-in-Docker)
# ============================================================
services:
# ── Caddy Reverse Proxy (TLS termination) ──────────────────
caddy:
image: docker.io/library/caddy:2-alpine
container_name: opencodehub-caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
depends_on:
- app
networks:
- opencodehub-external
logging:
driver: json-file
options:
max-size: "50m"
max-file: "5"
deploy:
resources:
limits:
memory: 256M
cpus: "0.5"
profiles:
- production
# ── Main OpenCodeHub Application ───────────────────────────
app:
build:
context: .
dockerfile: Dockerfile
container_name: opencodehub-app
restart: unless-stopped
expose:
- "4321" # Internal only — Caddy proxies to this
ports:
- "${SSH_PORT:-2222}:2222" # SSH Git (exposed directly)
environment:
- NODE_ENV=production
- DATABASE_DRIVER=postgres
- DATABASE_URL=postgresql://${POSTGRES_USER:-opencodehub}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-opencodehub}
- DATABASE_SSL=false
- REDIS_URL=redis://:${REDIS_PASSWORD:?Set REDIS_PASSWORD in .env}@redis:6379
- JWT_SECRET=${JWT_SECRET:?Set JWT_SECRET in .env}
- SESSION_SECRET=${SESSION_SECRET:-${JWT_SECRET}}
- INTERNAL_HOOK_SECRET=${INTERNAL_HOOK_SECRET:?Set INTERNAL_HOOK_SECRET in .env}
- CRON_SECRET=${CRON_SECRET:?Set CRON_SECRET in .env}
- AI_CONFIG_ENCRYPTION_KEY=${AI_CONFIG_ENCRYPTION_KEY:?Set AI_CONFIG_ENCRYPTION_KEY in .env}
- WORKFLOW_SECRET_ENCRYPTION_KEY=${WORKFLOW_SECRET_ENCRYPTION_KEY:?Set WORKFLOW_SECRET_ENCRYPTION_KEY in .env}
- RUNNER_SECRET=${RUNNER_SECRET:?Set RUNNER_SECRET in .env}
- SSH_HOST_KEY_PATH=/data/ssh/host_key
- SITE_URL=${SITE_URL:-https://opencodehub.example.com}
- SERVER_URL=${SITE_URL:-https://opencodehub.example.com}
- STORAGE_TYPE=${STORAGE_TYPE:-local}
- STORAGE_PATH=/data/storage
- REPOS_PATH=/data/repos
- GIT_REPOS_PATH=/data/repos
- LOG_LEVEL=${LOG_LEVEL:-info}
- RATE_LIMIT_ENABLED=true
- RATE_LIMIT_SKIP_DEV=false
- CSRF_SKIP_DEV=false
- ALLOWED_ORIGINS=${SITE_URL:-https://opencodehub.example.com}
- MAX_REQUEST_BODY_MB=${MAX_REQUEST_BODY_MB:-10}
# SSH server (runs inside app container)
- GIT_SSH_PORT=2222
- GIT_SSH_HOST_KEY=/data/ssh/host_key
volumes:
- repos-data:/data/repos
- storage-data:/data/storage
- ssh-data:/data/ssh
- cache-data:/data/cache
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- opencodehub-internal
- opencodehub-external
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:4321/api/health",
]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
logging:
driver: json-file
options:
max-size: "100m"
max-file: "10"
deploy:
resources:
limits:
memory: 2G
cpus: "2.0"
reservations:
memory: 512M
cpus: "0.5"
# ── Background Worker ──────────────────────────────────────
worker:
build:
context: .
dockerfile: Dockerfile
container_name: opencodehub-worker
restart: unless-stopped
command: ["bun", "scripts/worker.ts"]
expose:
- "9090" # Worker health check (internal only)
environment:
- NODE_ENV=production
- DATABASE_DRIVER=postgres
- DATABASE_URL=postgresql://${POSTGRES_USER:-opencodehub}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-opencodehub}
- REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379
- JWT_SECRET=${JWT_SECRET}
- LOG_LEVEL=${LOG_LEVEL:-info}
volumes:
- repos-data:/data/repos
- storage-data:/data/storage
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- opencodehub-internal
logging:
driver: json-file
options:
max-size: "50m"
max-file: "5"
deploy:
resources:
limits:
memory: 1G
cpus: "1.0"
# ── PostgreSQL Database ────────────────────────────────────
postgres:
image: docker.io/library/postgres:16-alpine
container_name: opencodehub-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-opencodehub}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-opencodehub}
# Performance tuning
POSTGRES_INITDB_ARGS: "--data-checksums"
command:
- postgres
- -c
- shared_buffers=256MB
- -c
- effective_cache_size=768MB
- -c
- work_mem=8MB
- -c
- maintenance_work_mem=128MB
- -c
- max_connections=100
- -c
- wal_level=replica
- -c
- max_wal_senders=3
- -c
- log_min_duration_statement=1000
- -c
- log_checkpoints=on
- -c
- log_connections=on
- -c
- log_disconnections=on
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- "5432" # Internal only
networks:
- opencodehub-internal
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-opencodehub} -d ${POSTGRES_DB:-opencodehub}"]
interval: 10s
timeout: 5s
retries: 5
logging:
driver: json-file
options:
max-size: "50m"
max-file: "5"
deploy:
resources:
limits:
memory: 1G
cpus: "1.0"
reservations:
memory: 256M
# ── Redis (sessions, caching, distributed locking) ────────
redis:
image: docker.io/library/redis:7-alpine
container_name: opencodehub-redis
restart: unless-stopped
command:
- redis-server
- --requirepass
- ${REDIS_PASSWORD:?Set REDIS_PASSWORD in .env}
- --appendonly
- "yes"
- --appendfsync
- everysec
- --maxmemory
- 256mb
- --maxmemory-policy
- allkeys-lru
- --save
- "60"
- "1000"
volumes:
- redis-data:/data
expose:
- "6379" # Internal only
networks:
- opencodehub-internal
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
logging:
driver: json-file
options:
max-size: "20m"
max-file: "3"
deploy:
resources:
limits:
memory: 512M
cpus: "0.5"
# ── CI/CD Runner (Docker-in-Docker) ────────────────────────
runner:
build:
context: .
dockerfile: Dockerfile.runner
container_name: opencodehub-runner
restart: unless-stopped
privileged: true
environment:
- RUNNER_TOKEN=${RUNNER_TOKEN:-}
- SERVER_URL=http://app:4321
- DOCKER_HOST=unix:///var/run/docker.sock
- RUNNER_WORK_DIR=/work
- RUNNER_CACHE_DIR=/cache
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- runner-work:/work
- runner-cache:/cache
depends_on:
- app
networks:
- opencodehub-internal
logging:
driver: json-file
options:
max-size: "50m"
max-file: "5"
deploy:
resources:
limits:
memory: 4G
cpus: "4.0"
profiles:
- production
- with-runner
# ── MinIO (S3-compatible object storage, optional) ─────────
minio:
image: minio/minio:latest
container_name: opencodehub-minio
restart: unless-stopped
command: server /data --console-address ":9001"
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Set MINIO_ROOT_PASSWORD in .env}
volumes:
- minio-data:/data
expose:
- "9000"
- "9001"
networks:
- opencodehub-internal
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 30s
timeout: 10s
retries: 3
profiles:
- with-minio
# ── Volumes ──────────────────────────────────────────────────
volumes:
repos-data:
driver: local
storage-data:
driver: local
ssh-data:
driver: local
cache-data:
driver: local
postgres-data:
driver: local
redis-data:
driver: local
runner-work:
driver: local
runner-cache:
driver: local
minio-data:
driver: local
caddy-data:
driver: local
caddy-config:
driver: local
# ── Networks ─────────────────────────────────────────────────
networks:
# Internal network — app, database, redis, worker communicate here
# No external access
opencodehub-internal:
driver: bridge
internal: true
# External network — only Caddy and app's SSH port are exposed
opencodehub-external:
driver: bridge