-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
191 lines (179 loc) · 5.39 KB
/
Copy pathdocker-compose.yml
File metadata and controls
191 lines (179 loc) · 5.39 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
###############################################################################
# CombatX — production stack.
#
# docker compose up --build
#
# Brings up Postgres, Redis, the Piston sandbox (with its Python runtime auto
# installed), applies the DB schema + seed, then starts the API, the realtime
# server, the judge worker, and the web app.
#
# Open http://localhost:3001
#
# Startup is sequenced with healthchecks: apps wait for db-init and piston-init
# to exit 0, so the first request never hits an unmigrated database or a Piston
# without a Python runtime.
###############################################################################
name: combatx
x-app-env: &app-env
NODE_ENV: production
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/combateone?schema=public
REDIS_URL: redis://redis:6379
PISTON_URL: http://piston:2000/api/v2
JWT_SECRET: ${JWT_SECRET:-dev-secret-change-me-in-production}
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:3001}
services:
# --- infrastructure ------------------------------------------------------
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: combateone
# Bound to loopback, and overridable: a Postgres already running on the
# host would otherwise make `compose up` fail with "address already in use".
ports:
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d combateone"]
interval: 5s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes"]
ports:
- "127.0.0.1:${REDIS_PORT:-6379}:6379"
volumes:
- redisdata:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
# The code sandbox. Needs privileged mode to build its own isolation cgroups.
piston:
image: ghcr.io/engineer-man/piston
restart: unless-stopped
privileged: true
ports:
- "${PISTON_PORT:-2000}:2000"
volumes:
- pistondata:/piston
healthcheck:
# This image ships Node 15 — no global fetch, no curl, no wget. http.get
# is the only probe available to us here.
test:
[
"CMD",
"node",
"-e",
"require('http').get('http://127.0.0.1:2000/api/v2/runtimes',r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))",
]
interval: 5s
timeout: 5s
retries: 20
# --- one-shot initialisers ----------------------------------------------
# Installs the Python runtime into Piston. Idempotent; exits 0 when ready.
piston-init:
image: alpine:3.20
depends_on:
piston:
condition: service_healthy
environment:
PISTON_URL: http://piston:2000/api/v2
volumes:
- ./docker/piston-init/provision.sh:/provision.sh:ro
entrypoint: ["/bin/sh", "/provision.sh"]
restart: "no"
# Applies the Prisma schema and seeds problems. Idempotent; exits 0.
db-init:
build:
context: .
dockerfile: docker/db-init/Dockerfile
depends_on:
postgres:
condition: service_healthy
environment:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/combateone?schema=public
restart: "no"
# --- application services -------------------------------------------------
http-api:
build:
context: .
dockerfile: apps/http-api/Dockerfile.prod
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
db-init:
condition: service_completed_successfully
environment:
<<: *app-env
HTTP_API_HOST: 0.0.0.0
HTTP_API_PORT: 4001
ports:
- "4001:4001"
ws-server:
build:
context: .
dockerfile: apps/ws-server/Dockerfile.prod
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
db-init:
condition: service_completed_successfully
environment:
<<: *app-env
WS_SERVER_HOST: 0.0.0.0
WS_SERVER_PORT: 4002
ports:
- "4002:4002"
judge-worker:
build:
context: .
dockerfile: apps/judge-worker/Dockerfile.prod
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
db-init:
condition: service_completed_successfully
piston-init:
condition: service_completed_successfully
environment:
<<: *app-env
JUDGE_CONCURRENCY: ${JUDGE_CONCURRENCY:-4}
web:
build:
context: .
dockerfile: apps/web/Dockerfile.prod
args:
# Inlined into the client bundle at build time — these are the URLs the
# BROWSER uses, so they must be host-reachable, not compose-internal.
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:4001}
NEXT_PUBLIC_WS_URL: ${NEXT_PUBLIC_WS_URL:-ws://localhost:4002/ws}
restart: unless-stopped
depends_on:
http-api:
condition: service_healthy
ws-server:
condition: service_healthy
environment:
NODE_ENV: production
PORT: 3001
HOSTNAME: 0.0.0.0
ports:
- "3001:3001"
volumes:
pgdata:
redisdata:
pistondata: