Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
100 lines (92 loc) · 3.16 KB
/
Copy pathdocker-compose.yml
File metadata and controls
100 lines (92 loc) · 3.16 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
name: notify-queue
# docker compose up --build one API, one worker
# docker compose up --build --scale worker=3 horizontally scaled workers
# docker compose --profile seed run --rm seed load demo data (after migrate)
x-app: &app
build: .
image: notify-queue:local
init: true # tini as PID 1: forwards SIGTERM so workers drain, reaps zombies
environment: &app-env
DATABASE_HOST: postgres
DATABASE_PORT: 5432
DATABASE_NAME: notify_queue
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
LOG_LEVEL: ${LOG_LEVEL:-info}
MOCK_FAILURE_RATE: ${MOCK_FAILURE_RATE:-0.2}
MAX_RETRIES: ${MAX_RETRIES:-5}
BASE_RETRY_DELAY_MS: ${BASE_RETRY_DELAY_MS:-1000}
MAX_RETRY_DELAY_MS: ${MAX_RETRY_DELAY_MS:-60000}
RATE_LIMIT_MAX_NOTIFICATIONS: ${RATE_LIMIT_MAX_NOTIFICATIONS:-10}
RATE_LIMIT_WINDOW_SECONDS: ${RATE_LIMIT_WINDOW_SECONDS:-3600}
WEBHOOK_URL: http://api:3000/webhooks/mock
services:
postgres:
image: postgres:17-alpine
# Terse error logs leave out DETAIL lines such as "Failing row contains
# (...)", which would copy recipients and payloads into the server log.
command: ['postgres', '-c', 'log_error_verbosity=terse']
environment:
POSTGRES_DB: notify_queue
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
# Host port 5434 avoids clashing with a local Postgres on 5432. Bound to
# 127.0.0.1 so the demo credentials are never reachable from the network.
- '127.0.0.1:${POSTGRES_HOST_PORT:-5434}:5432'
volumes:
- postgres-data:/var/lib/postgresql/data
- ./docker/postgres:/docker-entrypoint-initdb.d:ro
healthcheck:
# Container start is not database readiness; dependants wait on this.
test: ['CMD-SHELL', 'pg_isready -U postgres -d notify_queue']
interval: 2s
timeout: 3s
retries: 30
start_period: 5s
# Runs pending migrations once, then exits. api and worker start only after
# it succeeds: several containers migrating at once would race each other.
migrate:
<<: *app
command: ['node', 'node_modules/typeorm/cli.js', 'migration:run', '-d', 'dist/database/data-source.js']
healthcheck:
disable: true
restart: 'no'
depends_on:
postgres:
condition: service_healthy
api:
<<: *app
environment:
<<: *app-env
APP_ROLE: api
ports:
- '${API_HOST_PORT:-3000}:3000'
depends_on:
migrate:
condition: service_completed_successfully
worker:
<<: *app
environment:
<<: *app-env
APP_ROLE: worker
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-10}
WORKER_BATCH_SIZE: ${WORKER_BATCH_SIZE:-100}
# No published port: any number of replicas can run side by side.
# Longer than WORKER_SHUTDOWN_TIMEOUT_MS (30s) so the drain can finish.
stop_grace_period: 35s
depends_on:
migrate:
condition: service_completed_successfully
seed:
<<: *app
profiles: [seed]
command: ['node', 'dist/database/seeds/run-seed.js', 'seed.sql']
healthcheck:
disable: true
restart: 'no'
depends_on:
migrate:
condition: service_completed_successfully
volumes:
postgres-data: