Repository navigation
Expand file tree
/
Copy pathcompose.prod.yaml
More file actions
213 lines (207 loc) · 7.68 KB
/
Copy pathcompose.prod.yaml
File metadata and controls
213 lines (207 loc) · 7.68 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
# Production stack: Caddy (TLS) → app → Postgres. Unlike compose.yaml (the
# build-from-source staging stack), this PULLS the released app image from the
# registry — no source tree or build toolchain on the host:
#
# export IMAGE_REPO=ghcr.io/<owner>/<repo> # e.g. ghcr.io/virtuos/wolke
# export WOLKE_VERSION=1.4.0 # a released tag (or a digest)
# docker compose -f compose.prod.yaml up -d
#
# The app applies forward-only migrations itself on startup (advisory-locked, so
# replicas don't race), so there's no separate migrate step.
#
# Everything fails closed: the image coordinates, DB password, session secret,
# public URL, and OIDC client settings must all be set (in a .env beside this
# file, or the environment) or `compose up` aborts. Hardening (no-new-privileges,
# cap_drop, read-only roots) and the edge/backend network split mirror compose.yaml.
#
# Before first deploy: put the real hostname in the Caddyfile (replace `localhost`)
# and provide config.yaml (OIDC claim→role mapping + branding) next to this file.
services:
postgres:
image: docker.io/library/postgres:17
environment:
POSTGRES_USER: wolke
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
POSTGRES_DB: wolke
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- backend
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- FOWNER
- SETGID
- SETUID
read_only: true
tmpfs:
- /tmp
- /var/run/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U wolke -d wolke"]
interval: 5s
timeout: 3s
retries: 10
app:
image: ${IMAGE_REPO:?set IMAGE_REPO (e.g. ghcr.io/owner/repo)}:${WOLKE_VERSION:?set WOLKE_VERSION}
environment:
PUBLIC_URL: ${PUBLIC_URL:?set PUBLIC_URL (e.g. https://wolke.example.edu)}
HTTP_ADDR: ":8080"
DATABASE_URL: postgres://wolke:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/wolke?sslmode=disable
SESSION_SECRET: ${SESSION_SECRET:?set SESSION_SECRET (openssl rand -base64 32)}
# Trust X-Forwarded-* only from the edge network (Caddy's subnet).
TRUSTED_PROXIES: 172.28.0.0/16
LOG_LEVEL: ${LOG_LEVEL:-info}
# OIDC (provider-agnostic): discovery URL + client credentials. Claim→role
# mapping lives in config.yaml.
OIDC_ISSUER_URL: ${OIDC_ISSUER_URL:?set OIDC_ISSUER_URL}
OIDC_CLIENT_ID: ${OIDC_CLIENT_ID:?set OIDC_CLIENT_ID}
OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET:?set OIDC_CLIENT_SECRET}
CONFIG_FILE: /config.yaml
# METRICS_TOKEN is optional — /metrics is already 404'd at the edge and the
# app port is internal-only (see README → Metrics). Set it only if the
# scrape path crosses an untrusted boundary.
volumes:
# ,z relabels for SELinux (rootless podman) — without it the container
# can't read the mount; harmless elsewhere. Same flag as the Caddyfile.
- ./config.yaml:/config.yaml:ro,z
# Optional: override the image's baked-in default branding.
# - ./branding:/branding:ro,z
# The app auto-migrates on startup, so it only needs the database reachable.
depends_on:
postgres:
condition: service_healthy
networks:
- edge
- backend
expose:
- "8080"
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
healthcheck:
test: ["CMD", "/server", "healthcheck"]
interval: 15s
timeout: 5s
start_period: 10s
retries: 3
# Scheduled Postgres backups to an S3 bucket via restic. OPT-IN: this service
# only starts with `--profile backup`, so a deployment that hasn't configured
# a repository runs exactly as before. When it IS enabled it fails closed and
# loudly — missing configuration, an unreachable bucket or an unreachable
# database all log at ERROR and exit non-zero, so the container crash-loops
# visibly instead of silently skipping backups. See README → Backups.
#
# postgres:*-alpine is the base so pg_dump matches the server's major version
# exactly (an older pg_dump refuses to dump a newer server); restic is added
# from the matching Alpine community repo on start-up, which is why this is
# the one service without a read-only root filesystem.
backup:
image: docker.io/library/postgres:17-alpine
profiles: ["backup"]
entrypoint: ["/bin/sh", "/backup.sh"]
environment:
# --- Where backups go (no defaults; all institution-specific) ---
# NOTE: these use `:-`, not the `:?` fail-closed form used elsewhere in
# this file. Compose interpolates the whole file before it applies
# profiles, so a `:?` here would abort `compose up` for deployments that
# never enable backups. The check moved into backup.sh instead: it refuses
# to start and logs at ERROR when these are empty.
RESTIC_REPOSITORY: ${RESTIC_REPOSITORY:-}
RESTIC_PASSWORD: ${RESTIC_PASSWORD:-}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-east-1}
# --- What to dump ---
PGHOST: postgres
PGUSER: wolke
PGDATABASE: wolke
PGPASSWORD: ${POSTGRES_PASSWORD:-}
# --- Schedule and retention (defaults: daily, 7/4/6) ---
BACKUP_INTERVAL_SECONDS: ${BACKUP_INTERVAL_SECONDS:-86400}
BACKUP_RUN_ON_START: ${BACKUP_RUN_ON_START:-true}
BACKUP_KEEP_DAILY: ${BACKUP_KEEP_DAILY:-7}
BACKUP_KEEP_WEEKLY: ${BACKUP_KEEP_WEEKLY:-4}
BACKUP_KEEP_MONTHLY: ${BACKUP_KEEP_MONTHLY:-6}
BACKUP_TAG: ${BACKUP_TAG:-wolke-db}
# Create the repository on first run. Set false if you'd rather run
# `restic init` yourself (then a typo'd repository fails instead of
# quietly starting a second, empty one).
BACKUP_INIT_REPO: ${BACKUP_INIT_REPO:-true}
# How long to wait for the repository to answer before declaring it
# unreachable (restic's own backoff would otherwise retry for ~15 min).
BACKUP_PROBE_TIMEOUT: ${BACKUP_PROBE_TIMEOUT:-45}
# Pin restic itself if you need reproducibility, e.g. "0.18.1-r7".
BACKUP_RESTIC_VERSION: ${BACKUP_RESTIC_VERSION:-}
volumes:
- ./deploy/backup/backup.sh:/backup.sh:ro
depends_on:
postgres:
condition: service_healthy
# `backend` reaches Postgres; `egress` is the only route out to S3. It is a
# separate network from `edge` on purpose — the backup job must not sit in
# the subnet the app trusts for X-Forwarded-* headers.
networks:
- backend
- egress
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
caddy:
image: docker.io/library/caddy:2
ports:
- "${CADDY_HTTP_PORT:-80}:80"
- "${CADDY_HTTPS_PORT:-443}:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro,z
- caddy_data:/data
- caddy_config:/config
depends_on:
app:
condition: service_healthy
networks:
- edge
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
read_only: true
tmpfs:
- /tmp
volumes:
pgdata:
caddy_data:
caddy_config:
networks:
edge:
ipam:
config:
- subnet: 172.28.0.0/16
backend:
internal: true
ipam:
config:
- subnet: 172.29.0.0/16
# Outbound-only network for the backup job (S3). Not `internal`, and
# deliberately not `edge` — see the backup service.
egress:
ipam:
config:
- subnet: 172.30.0.0/16