Repository navigation
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
266 lines (251 loc) · 8.97 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
266 lines (251 loc) · 8.97 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
# Production "app" stack: redis, backend, and the two frontends.
# PostgreSQL and Caddy/fail2ban live in their own files on purpose (so routine
# app work here never has the DB/proxy config in view) — always run all
# three together:
# aws ecr get-login-password --region ${AWS_REGION:-ap-south-1} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
# docker compose -f docker-compose.prod.yml -f docker-compose.postgres.yml -f docker-compose.caddy.yml pull
# docker compose -f docker-compose.prod.yml -f docker-compose.postgres.yml -f docker-compose.caddy.yml up -d
#
# Images are built and pushed to ECR by .github/workflows/deploy-production.yml
# on every push to the `production` branch, tagged `<service>-<git-sha>` and
# `<service>-latest`. Set IMAGE_TAG to a git sha in .env to pin a specific
# build instead of always pulling latest.
# ECR_REGISTRY / ECR_REPOSITORY default to the tgl/attendix repo below;
# override in .env only if the registry ever changes.
x-logging: &default-logging
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
services:
redis:
image: valkey/valkey:8-alpine
container_name: attendance-redis
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- SETGID
- SETUID
logging: *default-logging
command: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru --requirepass ${REDIS_PASSWORD:?REDIS_PASSWORD must be set in .env}
expose:
- "6379"
volumes:
# Named `valkey_data`, not `redis_data`: this switched from redis:7-alpine
# to valkey/valkey:8-alpine, and Valkey can't read an RDB file written by
# a newer Redis (seen locally: "Can't handle RDB format version 12",
# which crash-loops the container on boot). Giving Valkey its own volume
# means this deploy never touches whatever the old `redis_data` volume
# contains — no manual migration/cleanup step to remember on the prod
# host. The old volume is orphaned but harmless (only rate-limit/
# session/deny-list cache, nothing durable) and can be removed manually
# later with `docker volume rm`.
- valkey_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
networks:
- db-net
backend:
image: ${ECR_REGISTRY:-559444199242.dkr.ecr.ap-south-1.amazonaws.com}/${ECR_REPOSITORY:-tgl/attendix}:backend-${IMAGE_TAG:-latest}
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
logging: *default-logging
environment:
- NODE_ENV=${NODE_ENV:-production}
# Exact origins only; the backend rejects `*` and refuses to start on an
# unparseable entry rather than falling back to allow-any.
- CORS_ORIGIN=${CORS_ORIGIN}
# Origin a student's browser reaches the site on, used to build
# shareable short links. NOT the same as WEBAUTHN_ORIGIN (the RP
# origin) — links used to be built from that and pointed at :5000.
- PUBLIC_BASE_URL=${PUBLIC_BASE_URL}
# Subnet of the reverse proxy, so X-Forwarded-For can be trusted for
# rate-limit keying. Empty means the socket peer is always used.
- TRUSTED_PROXIES=${TRUSTED_PROXIES:-}
# Bearer token Prometheus presents to scrape /metrics.
- METRICS_TOKEN=${METRICS_TOKEN:-}
- PORT=5000
- DATABASE_URL=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set in .env}@postgres:5432/${POSTGRES_DB:-attendance_geotag}
- TIMESCALE_DATABASE_URL=postgres://${TIMESCALE_USER:-attendix_telemetry}:${TIMESCALE_PASSWORD:?TIMESCALE_PASSWORD must be set in .env}@timescaledb:5432/${TIMESCALE_DB:-attendix_telemetry}
- REDIS_URL=redis://:${REDIS_PASSWORD:?REDIS_PASSWORD must be set in .env}@redis:6379
- JWT_SECRET=${JWT_SECRET:?JWT_SECRET must be set in .env — run scripts/generate-secrets.sh}
- JWT_EXPIRE=7d
- ADMIN_SECRET=${ADMIN_SECRET:?ADMIN_SECRET must be set in .env — run scripts/generate-secrets.sh}
# Only s3 is implemented as a StorageProvider (backend-rust/src/storage) — no Cloudinary support.
- STORAGE_PROVIDER=s3
# AWS S3
- AWS_S3_BUCKET=${AWS_S3_BUCKET}
- AWS_REGION=${AWS_REGION:-us-east-1}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
# WebAuthn
- WEBAUTHN_RP_NAME=${WEBAUTHN_RP_NAME:-Attendix Attendance System}
# Must match the domain Caddyfile.prod actually serves (RP ID has to be
# a registrable domain suffix of the origin, or passkey ceremonies are
# silently rejected by the browser) — these defaults exist only so a
# deploy without an explicit .env override still matches that domain
# instead of an unrelated one.
- WEBAUTHN_RP_ID=${WEBAUTHN_RP_ID:-attendixv2.talenciaglobal.com}
- WEBAUTHN_ORIGIN=${WEBAUTHN_ORIGIN:-https://attendixv2.talenciaglobal.com}
# Database Pool (names must match backend-rust/src/config/mod.rs::AppConfig::from_env)
# 30 per replica x 3 replicas = 90 cluster-wide, comfortably under
# postgres's max_connections=200 (docker-compose.postgres.yml) with
# headroom for psql/backup-sidecar/admin connections. Connections are
# only held for query duration, not for the extension's 15-30s batch
# interval, so this doesn't need to scale with concurrent students.
- PG_MAX_POOL_SIZE=${PG_MAX_POOL_SIZE:-30}
- PG_MIN_POOL_SIZE=${PG_MIN_POOL_SIZE:-5}
- DEV_BYPASS_ALL=${DEV_BYPASS_ALL:-false}
# See docker-compose.yml's backend service for why .cache needs to be
# writable too, not just /tmp.
read_only: true
tmpfs:
- /tmp
- /home/appuser/.cache:uid=1001,gid=1001,mode=0755
deploy:
replicas: 3
resources:
limits:
cpus: '1.5'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
depends_on:
postgres:
condition: service_healthy
timescaledb:
condition: service_healthy
redis:
condition: service_healthy
networks:
- db-net
- web-net
admin-frontend:
image: ${ECR_REGISTRY:-559444199242.dkr.ecr.ap-south-1.amazonaws.com}/${ECR_REPOSITORY:-tgl/attendix}:admin-frontend-${IMAGE_TAG:-latest}
restart: unless-stopped
security_opt:
- no-new-privileges:true
# nginx-unprivileged (see frontend/admin/Dockerfile) runs as the `nginx`
# user from the start and listens on 8080, not 80 — no capabilities
# needed at all anymore.
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
- /var/cache/nginx
- /var/run
logging: *default-logging
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
depends_on:
- backend
networks:
- web-net
mentor-frontend:
image: ${ECR_REGISTRY:-559444199242.dkr.ecr.ap-south-1.amazonaws.com}/${ECR_REPOSITORY:-tgl/attendix}:mentor-frontend-${IMAGE_TAG:-latest}
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
- /var/cache/nginx
- /var/run
logging: *default-logging
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
depends_on:
- backend
networks:
- web-net
student-frontend:
image: ${ECR_REGISTRY:-559444199242.dkr.ecr.ap-south-1.amazonaws.com}/${ECR_REPOSITORY:-tgl/attendix}:student-frontend-${IMAGE_TAG:-latest}
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
- /var/cache/nginx
- /var/run
logging: *default-logging
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
depends_on:
- backend
networks:
- web-net
home-frontend:
image: ${ECR_REGISTRY:-559444199242.dkr.ecr.ap-south-1.amazonaws.com}/${ECR_REPOSITORY:-tgl/attendix}:home-frontend-${IMAGE_TAG:-latest}
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
logging: *default-logging
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.1'
memory: 64M
networks:
- web-net
volumes:
valkey_data:
networks:
db-net:
driver: bridge
web-net:
driver: bridge