-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.local.yaml
More file actions
410 lines (396 loc) · 12 KB
/
Copy pathdocker-compose.prod.local.yaml
File metadata and controls
410 lines (396 loc) · 12 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# =============================================================================
# Notetify — production stack (AWS deployment)
# -----------------------------------------------------------------------------
#
# docker compose -f docker-compose.prod.yaml --env-file .env.production.local up -d
#
# =============================================================================
# Shared logging defaults — JSON file with rotation, suitable for CloudWatch
# agent ingestion. Switch driver to `awslogs` if running on ECS or if you'd
# rather have Docker stream directly.
x-logging: &default-logging
driver: json-file
options:
max-size: "10m"
max-file: "5"
tag: "{{.Name}}"
services:
# ---------------------------------------------------------------------------
# db — Postgres 18-1
# Primary datastore. For real production replace with Amazon RDS and remove
# this service. RDS gives you automated backups, multi-AZ failover, and
# point-in-time recovery — none of which a single container provides.
# Internal only (no published port).
# ---------------------------------------------------------------------------
db:
image: postgres:18.1-alpine
container_name: notetify-db
networks:
- notetify-net
restart: always
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-postgres}", "-d", "${POSTGRES_DB:-notetify}"]
interval: 10s
timeout: 5s
retries: 10
start_period: 15s
user: postgres
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DB_DATABASE:-notetify}
- POSTGRES_USER=${DB_USERNAME:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:?DB_PASSWORD must be set in .env.production}
expose:
- 5432
env_file:
- .env.production.local
logging: *default-logging
deploy:
resources:
limits:
cpus: "2.0"
memory: 2g
reservations:
cpus: "0.5"
memory: 512m
# ---------------------------------------------------------------------------
# redis — Redis 8
# Cache + sessions + queue + Pulse ingest + Hocuspocus pub/sub. For real
# production replace with Amazon ElastiCache. Keep AOF persistence on so a
# restart doesn't drop in-flight queue jobs.
# Internal only.
# ---------------------------------------------------------------------------
redis:
image: redis:8.0.1-alpine
container_name: notetify-redis
networks:
- notetify-net
restart: always
command: ["redis-server", "--appendonly", "yes", "--maxmemory-policy", "allkeys-lru"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 10
start_period: 5s
volumes:
- redis-data:/data
expose:
- 6379
env_file:
- .env.production.local
logging: *default-logging
deploy:
resources:
limits:
cpus: "1.0"
memory: 1g
reservations:
cpus: "0.1"
memory: 128m
# ---------------------------------------------------------------------------
# rustfs — S3-compatible object storage
# Holds note attachments. EBS-backed volume on the host. If you'd rather
# use AWS S3 directly, swap Laravel's filesystem disk to `s3`, fill in
# AWS_* env vars, and delete this service.
# Internal only — Laravel reaches it on http://rustfs:9000.
# ---------------------------------------------------------------------------
rustfs:
image: rustfs/rustfs:latest
container_name: notetify-rustfs
networks:
- notetify-net
restart: always
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9000/minio/health/live"]
interval: 15s
timeout: 5s
retries: 10
start_period: 15s
environment:
RUSTFS_ROOT_USER: ${RUSTFS_KEY:?RUSTFS_KEY must be set in .env.production}
RUSTFS_ROOT_PASSWORD: ${RUSTFS_SECRET:?RUSTFS_SECRET must be set in .env.production}
RUSTFS_VOLUMES: /data
env_file:
- .env.production.local
volumes:
- rustfs-data:/data
expose:
- 9000
logging: *default-logging
deploy:
resources:
limits:
cpus: "2.0"
memory: 2g
reservations:
cpus: "0.25"
memory: 256m
# ---------------------------------------------------------------------------
# api — Laravel HTTP API (PHP-FPM + nginx)
# Serves /api/*. Internal only — fronted by client's nginx which
# terminates TLS and proxies /api to this container.
# ---------------------------------------------------------------------------
api:
build:
context: ./api
dockerfile: docker/Dockerfile.prod.local
target: production
container_name: notetify-api
networks:
- notetify-net
restart: always
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80/api/up"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
rustfs:
condition: service_started
env_file:
- .env.production.local
environment:
- APP_ENV=production
- APP_DEBUG=false
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=notetify
- DB_USERNAME=postgres
- REDIS_HOST=redis
- REDIS_PORT=6379
- RUSTFS_ENDPOINT=http://rustfs:9000
- FILESYSTEM_DISK=rustfs
volumes:
- api-storage:/app/storage
expose:
- 80
logging: *default-logging
deploy:
resources:
limits:
cpus: "2.0"
memory: 1g
reservations:
cpus: "0.5"
memory: 512m
# ---------------------------------------------------------------------------
# pulse — Pulse aggregator
# Runs `php artisan pulse:work`. Aggregates Redis-buffered metrics into
# Postgres for the /pulse dashboard.
# ---------------------------------------------------------------------------
pulse:
image: notetify-api
container_name: notetify-pulse
networks:
- notetify-net
restart: always
command: ["php", "artisan", "pulse:work"]
healthcheck:
test: ["CMD-SHELL", "pgrep -f 'pulse:work' > /dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
depends_on:
api:
condition: service_healthy
env_file:
- .env.production.local
environment:
- APP_ENV=production
- APP_DEBUG=false
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=notetify
- DB_USERNAME=postgres
- REDIS_HOST=redis
- REDIS_PORT=6379
logging: *default-logging
deploy:
resources:
limits:
cpus: "0.5"
memory: 384m
reservations:
cpus: "0.05"
memory: 64m
# ---------------------------------------------------------------------------
# horizon — Laravel Horizon queue worker + supervisor
# Runs `php artisan horizon`, which spawns and supervises the worker pool
# defined in config/horizon.php. SIGTERM drains in-flight jobs cleanly.
# Dashboard is served by api at /horizon (gated in prod via
# HorizonServiceProvider::gate()).
# ---------------------------------------------------------------------------
horizon:
image: notetify-api
container_name: notetify-horizon
networks:
- notetify-net
restart: always
command: ["php", "artisan", "horizon"]
stop_signal: SIGTERM
stop_grace_period: 60s
healthcheck:
test: ["CMD-SHELL", "pgrep -f 'artisan horizon' > /dev/null"]
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
depends_on:
api:
condition: service_healthy
env_file:
- .env.production.local
environment:
- APP_ENV=production
- APP_DEBUG=false
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=notetify
- DB_USERNAME=postgres
- REDIS_HOST=redis
- REDIS_PORT=6379
- QUEUE_CONNECTION=redis
logging: *default-logging
deploy:
resources:
limits:
cpus: "1.5"
memory: 768m
reservations:
cpus: "0.2"
memory: 192m
# ---------------------------------------------------------------------------
# collab — Hocuspocus (Yjs CRDT WebSocket server)
# Real-time collaborative editing. Receives WS connections at /collab
# (proxied by client's nginx with Upgrade headers). Persists via
# webhook back to api. Multi-instance fanout via Redis.
# See docs/COLLABORATION.md for the full architecture.
# ---------------------------------------------------------------------------
collab:
build:
context: ./collab
dockerfile: docker/Dockerfile.prod.local
target: production
container_name: notetify-collab
networks:
- notetify-net
restart: always
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:1234/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
depends_on:
redis:
condition: service_healthy
api:
condition: service_healthy
env_file:
- .env.production.local
environment:
- PORT=1234
- LARAVEL_URL=http://api:80
- REDIS_HOST=redis
- REDIS_PORT=6379
- NODE_ENV=production
expose:
- 1234
logging: *default-logging
deploy:
resources:
limits:
cpus: "1.0"
memory: 768m
reservations:
cpus: "0.1"
memory: 128m
# ---------------------------------------------------------------------------
# client — nginx + static React build (public-facing)
# The only container with published ports. Terminates TLS via Let's Encrypt
# certs (mounted from ./certbot/conf), serves the SPA, and reverse-proxies:
# /api -> api:80
# /collab -> collab:1234 (with Upgrade/Connection for WebSocket)
# Make sure client/nginx/*.conf includes both proxy blocks.
# ---------------------------------------------------------------------------
client:
build:
context: ./client
dockerfile: docker/Dockerfile.prod.local
target: production
args:
- VITE_BASE_URL=${CLIENT_BASE_URL:-https://localhost/api/}
- VITE_WS_ORIGIN=${CLIENT_WS_ORIGIN:-wss://localhost}
- VITE_APP_NAME=Notetify
- VITE_CLIENT_URL=${CLIENT_URL:-https://localhost/}
container_name: notetify-client
networks:
- notetify-net
restart: always
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
ports:
- "80:80"
- "443:443"
depends_on:
api:
condition: service_healthy
collab:
condition: service_healthy
env_file:
- .env.production.local
environment:
- DOMAIN=${DOMAIN:-localhost}
volumes:
- ./certbot/conf:/etc/nginx/certs:ro
- ./certbot/www:/var/www/certbot:ro
logging: *default-logging
deploy:
resources:
limits:
cpus: "1.0"
memory: 256m
reservations:
cpus: "0.1"
memory: 64m
# ---------------------------------------------------------------------------
# certbot — Let's Encrypt cert renewal
# Runs continuously, attempting renewal every 12h. Activate with the
# `production` profile so it doesn't start in local prod-test runs.
# ---------------------------------------------------------------------------
certbot:
image: certbot/certbot
container_name: certbot
profiles:
- production
restart: always
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
logging: *default-logging
deploy:
resources:
limits:
cpus: "0.25"
memory: 128m
networks:
notetify-net:
driver: bridge
volumes:
db-data:
redis-data:
rustfs-data:
api-storage: