-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
249 lines (240 loc) · 6.43 KB
/
Copy pathdocker-compose.yml
File metadata and controls
249 lines (240 loc) · 6.43 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
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
init: true
mem_limit: ${POSTGRES_MEMORY_LIMIT:-256m}
cpus: ${POSTGRES_CPU_LIMIT:-0.75}
pids_limit: 100
command:
- postgres
- -c
- max_connections=50
- -c
- shared_buffers=64MB
- -c
- effective_cache_size=192MB
- -c
- work_mem=2MB
- -c
- maintenance_work_mem=32MB
- -c
- huge_pages=off
environment:
POSTGRES_USER: ${POSTGRES_USER:-unity}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-unity}
POSTGRES_DB: ${POSTGRES_DB:-unity_run_club}
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-unity} -d ${POSTGRES_DB:-unity_run_club}"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
redis:
image: redis:7-alpine
restart: unless-stopped
init: true
mem_limit: ${REDIS_MEMORY_LIMIT:-96m}
cpus: ${REDIS_CPU_LIMIT:-0.25}
pids_limit: 50
command:
- redis-server
- --maxmemory
- ${REDIS_MAXMEMORY:-64mb}
- --maxmemory-policy
- noeviction
- --save
- "300"
- "10"
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
# Sits between the API/worker and Postgres: transaction pooling lets each
# replica keep a generous local pgx pool (DATABASE_MAX_CONN) while Postgres
# itself only ever sees PGBOUNCER_DEFAULT_POOL_SIZE real backend
# connections, regardless of how many API replicas are running.
pgbouncer:
image: edoburu/pgbouncer:v1.24.1-p1
restart: unless-stopped
init: true
mem_limit: ${PGBOUNCER_MEMORY_LIMIT:-64m}
cpus: ${PGBOUNCER_CPU_LIMIT:-0.25}
pids_limit: 50
environment:
DATABASE_URL: postgres://${POSTGRES_USER:-unity}:${POSTGRES_PASSWORD:-unity}@postgres:5432/${POSTGRES_DB:-unity_run_club}
LISTEN_PORT: "6432"
POOL_MODE: transaction
MAX_CLIENT_CONN: ${PGBOUNCER_MAX_CLIENT_CONN:-1000}
DEFAULT_POOL_SIZE: ${PGBOUNCER_DEFAULT_POOL_SIZE:-20}
AUTH_TYPE: scram-sha-256
expose:
- "6432"
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 6432 -U ${POSTGRES_USER:-unity}"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
api: &api-service
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
init: true
mem_limit: ${API_MEMORY_LIMIT:-256m}
cpus: ${API_CPU_LIMIT:-1.0}
pids_limit: 100
env_file:
- path: .env
required: false
environment: &api-environment
PROCESS_ROLE: api
PORT: "8080"
METRICS_PORT: "9091"
DATABASE_MAX_CONN: ${DATABASE_MAX_CONN:-20}
DATABASE_URL: postgres://${POSTGRES_USER:-unity}:${POSTGRES_PASSWORD:-unity}@pgbouncer:6432/${POSTGRES_DB:-unity_run_club}?sslmode=disable
DATABASE_PGBOUNCER_COMPAT: "true"
REDIS_ADDR: redis:6379
REALTIME_INTERNAL_URL: http://realtime:8081
UPLOAD_DIR: /app/uploads
GOMEMLIMIT: ${API_GO_MEMORY_LIMIT:-192MiB}
GOMAXPROCS: ${API_GO_MAX_PROCS:-1}
expose:
- "8080"
- "9091"
depends_on:
postgres:
condition: service_healthy
pgbouncer:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- event_uploads:/app/uploads
stop_grace_period: 20s
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:8080/ready"]
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
api-replica:
<<: *api-service
# Exactly one worker: email sweeps are not safe to run concurrently.
worker:
<<: *api-service
environment:
<<: *api-environment
PROCESS_ROLE: worker
DATABASE_MAX_CONN: ${WORKER_DATABASE_MAX_CONN:-10}
api-gateway:
image: traefik:v3.7.12
restart: unless-stopped
init: true
mem_limit: ${GATEWAY_MEMORY_LIMIT:-128m}
cpus: ${GATEWAY_CPU_LIMIT:-0.25}
pids_limit: 100
command:
- --entrypoints.api.address=:8080
- --entrypoints.health.address=:9090
- --providers.file.filename=/etc/traefik/api.yml
- --ping=true
- --ping.entrypoint=health
- --accesslog=true
- --accesslog.format=json
- --log.format=json
configs:
- source: api-load-balancer
target: /etc/traefik/api.yml
ports:
- "${PORT:-8080}:8080"
# Start even if a replica is unhealthy; the gateway checks /ready itself.
depends_on:
api:
condition: service_started
api-replica:
condition: service_started
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:9090/ping"]
interval: 10s
timeout: 3s
retries: 3
stop_grace_period: 20s
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
realtime:
build:
context: ./realtime
dockerfile: Dockerfile
restart: unless-stopped
init: true
mem_limit: ${REALTIME_MEMORY_LIMIT:-96m}
cpus: ${REALTIME_CPU_LIMIT:-0.25}
pids_limit: 50
environment:
PORT: 8081
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-}
REDIS_DB: ${REDIS_DB:-0}
ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS:-http://localhost:3000}
NODE_OPTIONS: --max-old-space-size=${REALTIME_NODE_HEAP_MB:-64}
ports:
- "${REALTIME_PORT:-8081}:8081"
depends_on:
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:8081/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5s
logging:
driver: local
options:
max-size: "10m"
max-file: "3"
volumes:
postgres_data:
redis_data:
event_uploads:
configs:
api-load-balancer:
file: ./deploy/traefik/api.yml