Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
359 lines (349 loc) · 11.1 KB
/
Copy pathdocker-compose.yml
File metadata and controls
359 lines (349 loc) · 11.1 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
# =============================================================================
# Scrumooth - Production Docker Compose Configuration
# =============================================================================
# Production-ready orchestration with security best practices
# =============================================================================
name: scrumooth
services:
# ===========================================================================
# Caddy Reverse Proxy with automatic HTTPS
# Handles TLS termination and SSL certificate management
# ===========================================================================
caddy:
image: caddy:2-alpine
container_name: scrumooth-caddy
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
frontend:
condition: service_healthy
backend:
condition: service_healthy
restart: unless-stopped
networks:
- scrumooth-network
# Security options
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
healthcheck:
test: ["CMD", "caddy", "validate", "--config", "/etc/caddy/Caddyfile"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
deploy:
resources:
limits:
cpus: '0.5'
memory: 128M
reservations:
cpus: '0.1'
memory: 32M
# ===========================================================================
# Backend API Service
# ===========================================================================
backend:
build:
context: .
dockerfile: packages/backend/Dockerfile
target: production
args:
BUILD_DATE: "${BUILD_DATE:-}"
VCS_REF: "${VCS_REF:-}"
NPM_REGISTRY: "${NPM_REGISTRY:-__default__}"
APT_MIRROR: "${APT_MIRROR:-}"
image: scrumooth-backend:${VERSION:-latest}
container_name: scrumooth-backend
expose:
- "5010"
env_file:
- ./packages/backend/.env.production
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped
networks:
- scrumooth-network
# Security options
security_opt:
- no-new-privileges:true
# Read-only root filesystem with writable paths
read_only: true
tmpfs:
- /tmp
- /app/logs:uid=1000,gid=1000
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:5010/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.25'
memory: 128M
# ===========================================================================
# Frontend Service (Nginx)
# ===========================================================================
frontend:
build:
context: .
dockerfile: packages/frontend/Dockerfile
target: production
args:
BUILD_DATE: "${BUILD_DATE:-}"
VCS_REF: "${VCS_REF:-}"
NPM_REGISTRY: "${NPM_REGISTRY:-__default__}"
# Vite environment variables (non-sensitive only)
# Read from .env.production file
VITE_BASE_PATH: "${VITE_BASE_PATH:-/scrumooth/}"
# Use relative URL for API - nginx proxies /api to backend:5010
VITE_API_URL: "${VITE_API_URL:-/api/v1}"
# Mock mode is off by default and stays off in a release build: `vite build`
# refuses VITE_USE_MOCK_API=true outside demo mode. A backend-free demo image
# is built from the committed `packages/frontend/.env.demo` (--mode demo)
# rather than by flipping this here.
VITE_USE_MOCK_API: "${VITE_USE_MOCK_API:-false}"
VITE_BACKLOG_ITEM_LIMIT: "${VITE_BACKLOG_ITEM_LIMIT:-100}"
VITE_BACKLOG_MAX_ITEMS_PER_GOAL: "${VITE_BACKLOG_MAX_ITEMS_PER_GOAL:-200}"
VITE_LOG_LEVEL: "${VITE_LOG_LEVEL:-info}"
image: scrumooth-frontend:${VERSION:-latest}
container_name: scrumooth-frontend
expose:
- "80"
depends_on:
backend:
condition: service_healthy
restart: unless-stopped
networks:
- scrumooth-network
# Security options
security_opt:
- no-new-privileges:true
# Read-only root filesystem with writable paths for nginx
read_only: true
tmpfs:
- /tmp
- /var/cache/nginx:uid=101,gid=101
- /var/run:uid=101,gid=101
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
deploy:
resources:
limits:
cpus: '0.5'
memory: 128M
reservations:
cpus: '0.1'
memory: 32M
# ===========================================================================
# PostgreSQL Database
# ===========================================================================
postgres:
image: postgres:18-alpine
container_name: scrumooth-postgres
env_file:
- ./packages/backend/.env.production
environment:
- POSTGRES_USER=${DB_USER:-scrumooth}
- POSTGRES_PASSWORD=${DB_PASSWORD:-Str0ng!DBp@ss2026}
- POSTGRES_DB=${DB_NAME:-scrumooth}
- POSTGRES_INITDB_ARGS=--encoding=UTF-8 --locale=en_US.UTF-8
volumes:
- scrumooth_postgres_data:/var/lib/postgresql
restart: unless-stopped
networks:
- scrumooth-network
# Security options
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-scrumooth} -d ${DB_NAME:-scrumooth}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "5"
deploy:
resources:
limits:
cpus: '1'
memory: 512M
reservations:
cpus: '0.25'
memory: 128M
# PostgreSQL writes its logs to stderr (default), which Docker captures as
# container logs. The file-based logging_collector is NOT used because the
# official postgres image runs as a non-root user and the /var/log/postgresql
# directory is root-owned, causing "Permission denied" on container startup.
# Use `docker compose logs postgres` to view database logs.
# ===========================================================================
# PgBouncer - Connection Pooling for Production
# NOTE: Commented out due to Docker mirror availability issues.
# Uncomment and configure if you have access to bitnami/pgbouncer or edoburu/pgbouncer images.
# ===========================================================================
# pgbouncer:
# image: bitnami/pgbouncer:1.22
# container_name: scrumooth-pgbouncer
# environment:
# PGBOUNCER_DATABASE_HOST: postgres
# PGBOUNCER_DATABASE_PORT_NUMBER: 5432
# PGBOUNCER_DATABASE_NAME: ${DB_NAME:-scrumooth}
# PGBOUNCER_DATABASE_USER: ${DB_USER:-postgres}
# PGBOUNCER_DATABASE_PASSWORD: ${DB_PASSWORD:-postgres}
# PGBOUNCER_POOL_MODE: transaction
# PGBOUNCER_MAX_CLIENT_CONN: 100
# PGBOUNCER_DEFAULT_POOL_SIZE: 20
# PGBOUNCER_MIN_POOL_SIZE: 5
# PGBOUNCER_RESERVE_POOL_SIZE: 5
# PGBOUNCER_MAX_DB_CONNECTIONS: 50
# PGBOUNCER_SERVER_IDLE_TIMEOUT: 600
# PGBOUNCER_SERVER_LIFETIME: 3600
# PGBOUNCER_CLIENT_IDLE_TIMEOUT: 0
# PGBOUNCER_CLIENT_LOGIN_TIMEOUT: 60
# PGBOUNCER_QUERY_TIMEOUT: 0
# PGBOUNCER_QUERY_WAIT_TIMEOUT: 120
# ports:
# - "6432:6432"
# depends_on:
# postgres:
# condition: service_healthy
# restart: unless-stopped
# networks:
# - scrumooth-network
# logging:
# driver: "json-file"
# options:
# max-size: "10m"
# max-file: "5"
# deploy:
# resources:
# limits:
# cpus: '0.5'
# memory: 128M
# reservations:
# cpus: '0.1'
# memory: 32M
# ===========================================================================
# Automated SQL Backup Service
# Creates SQL dumps of the database daily at 2 AM
# ===========================================================================
backup:
image: postgres:18-alpine
container_name: scrumooth-backup
volumes:
- ./backups:/backups
- ./scripts/maintenance/database:/scripts:ro
environment:
- POSTGRES_USER=${DB_USER:-scrumooth}
- POSTGRES_PASSWORD=${DB_PASSWORD:-Str0ng!DBp@ss2026}
- DB_NAME=${DB_NAME:-scrumooth}
- DB_USER=${DB_USER:-scrumooth}
- PGHOST=postgres
command: >
sh -c "
apk add --no-cache bash &&
echo '0 2 * * * cd /scripts && ./db-backup.sh /backups >> /backups/backup.log 2>&1' | crontab - &&
crond -f -l 2
"
depends_on:
postgres:
condition: service_healthy
networks:
- scrumooth-network
restart: unless-stopped
# Security options
security_opt:
- no-new-privileges:true
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# ===========================================================================
# Automated Volume Backup Service
# Creates file-level backups of the PostgreSQL data volume weekly on Sundays at 3 AM
# ===========================================================================
volume-backup:
image: docker:cli
container_name: scrumooth-volume-backup
volumes:
- scrumooth_postgres_data:/data:ro
- ./backups/volumes:/backups
- ./scripts/maintenance/database:/scripts:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
command: >
sh -c "
apk add --no-cache bash &&
echo '0 3 * * 0 cd /scripts && ./db-volume-backup.sh /backups >> /backups/volume-backup.log 2>&1' | crontab - &&
crond -f -l 2
"
depends_on:
postgres:
condition: service_healthy
networks:
- scrumooth-network
restart: unless-stopped
# Security options
security_opt:
- no-new-privileges:true
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# =============================================================================
# Volumes
# =============================================================================
volumes:
scrumooth_postgres_data:
driver: local
caddy_data:
driver: local
caddy_config:
driver: local
# =============================================================================
# Networks
# =============================================================================
networks:
scrumooth-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.28.0.0/16