-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
214 lines (202 loc) · 6.25 KB
/
Copy pathdocker-compose.yml
File metadata and controls
214 lines (202 loc) · 6.25 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
###############################################################################
# Spidder — development stack (hot reload).
#
# docker compose up --build
#
# This is the DEFAULT compose file, so development — the thing done many times
# a day — needs no -f flag. Deployment is the rare, deliberate act, and it is
# the one that spells out its file:
#
# docker-compose.yml THIS FILE — hot-reload dev stack, everything in
# containers including Postgres and Redis
# docker-compose.prod.yml a real deployment on a real server: images pulled
# from Docker Hub, Postgres and Redis on the host
#
# Same topology as production, but every app runs from its Dockerfile.dev with
# the repo bind-mounted over /app, so edits on the host hot-reload inside the
# container (tsx watch for the services, next dev for the web app).
#
# Open http://localhost:3001
#
# The `node_modules` anonymous volumes are load-bearing: they shadow the host's
# node_modules so the container keeps its own linux-native install rather than
# the host's (possibly different-arch) one.
###############################################################################
# Distinct from the prod stack's `spidder`, so a local stack and a deployment on
# the same machine never adopt each other's containers or volumes.
name: spidder-dev
x-app-env: &app-env
NODE_ENV: development
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/spidder?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: spidder
# 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-dev:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d spidder"]
interval: 5s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
restart: unless-stopped
ports:
- "127.0.0.1:${REDIS_PORT:-6379}:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
piston:
image: ghcr.io/engineer-man/piston
restart: unless-stopped
privileged: true
ports:
- "${PISTON_PORT:-2000}:2000"
volumes:
- pistondata-dev:/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 ----------------------------------------------
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"
db-init:
build:
context: .
dockerfile: docker/db-init/Dockerfile
depends_on:
postgres:
condition: service_healthy
environment:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/spidder?schema=public
restart: "no"
# --- application services (hot reload) -----------------------------------
http-api:
build:
context: .
dockerfile: apps/http-api/Dockerfile.dev
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"
volumes:
- .:/app
# Keep the container's linux-native installs and build output.
- /app/node_modules
- /app/apps/http-api/node_modules
- /app/packages/db/node_modules
- /app/packages/db/generated
ws-server:
build:
context: .
dockerfile: apps/ws-server/Dockerfile.dev
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"
volumes:
- .:/app
- /app/node_modules
- /app/apps/ws-server/node_modules
- /app/packages/db/node_modules
- /app/packages/db/generated
judge-worker:
build:
context: .
dockerfile: apps/judge-worker/Dockerfile.dev
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}
volumes:
- .:/app
- /app/node_modules
- /app/apps/judge-worker/node_modules
- /app/packages/db/node_modules
- /app/packages/db/generated
web:
build:
context: .
dockerfile: apps/web/Dockerfile.dev
restart: unless-stopped
depends_on:
- http-api
- ws-server
environment:
NODE_ENV: development
PORT: 3001
# Read at dev-server start; these are the URLs the BROWSER uses.
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:4001}
NEXT_PUBLIC_WS_URL: ${NEXT_PUBLIC_WS_URL:-ws://localhost:4002/ws}
ports:
- "3001:3001"
volumes:
- .:/app
- /app/node_modules
- /app/apps/web/node_modules
- /app/apps/web/.next
volumes:
pgdata-dev:
pistondata-dev: