2026-11-16 12:00:57 +01:00
|
|
|
# ADR-54, ADR-55, WEB-07: the same file serves http://localhost today and a domain later —
|
|
|
|
|
# only SITE_ADDRESS (and DJANGO_ALLOWED_HOSTS / DJANGO_CSRF_TRUSTED_ORIGINS if needed) change.
|
|
|
|
|
# The previous FastAPI service is not part of the stack any more (roadmap D1 removes the code).
|
2026-07-21 11:15:04 +02:00
|
|
|
services:
|
2026-10-18 00:54:23 +02:00
|
|
|
# B-91 (SEC-51): one-shot, as root, so the bind-mounted ./data belongs to the non-root
|
|
|
|
|
# user the app runs as (uid 1000) and is closed to everyone else — also the first time
|
|
|
|
|
# after an older root-owned install, with no sudo on the host.
|
|
|
|
|
data-permissions:
|
|
|
|
|
build: .
|
2026-11-16 12:00:57 +01:00
|
|
|
image: plm-lottery-web:local
|
2026-10-18 00:54:23 +02:00
|
|
|
user: "0:0"
|
|
|
|
|
entrypoint: ["/bin/sh", "-c", "chown -R 1000:1000 /data && chmod -R go-rwx /data"]
|
|
|
|
|
volumes:
|
|
|
|
|
- ./data:/data
|
|
|
|
|
restart: "no"
|
|
|
|
|
|
2026-11-16 12:00:57 +01:00
|
|
|
# The web process: Django behind gunicorn. It applies the migrations at startup.
|
|
|
|
|
web:
|
2026-07-21 11:15:04 +02:00
|
|
|
build: .
|
2026-11-16 12:00:57 +01:00
|
|
|
image: plm-lottery-web:local
|
2026-07-21 11:15:04 +02:00
|
|
|
restart: unless-stopped
|
|
|
|
|
env_file: .env
|
|
|
|
|
environment:
|
2026-11-16 12:00:57 +01:00
|
|
|
- DJANGO_DB_PATH=/app/db_data/site.sqlite3
|
|
|
|
|
- SITE_ADDRESS=${SITE_ADDRESS:-localhost}
|
|
|
|
|
# gunicorn trusts X-Forwarded-Proto/For from Caddy's fixed address only (ARC-02).
|
Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
2026-10-18 01:15:22 +02:00
|
|
|
- FORWARDED_ALLOW_IPS=172.28.0.10
|
2026-07-21 11:15:04 +02:00
|
|
|
volumes:
|
|
|
|
|
- ./data/db:/app/db_data
|
|
|
|
|
expose:
|
2026-11-16 12:00:57 +01:00
|
|
|
- "8000"
|
|
|
|
|
# ARC-73: liveness = the process answers and the database opens.
|
Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
2026-10-18 01:15:22 +02:00
|
|
|
healthcheck:
|
|
|
|
|
test:
|
|
|
|
|
- CMD
|
|
|
|
|
- python
|
|
|
|
|
- -c
|
2026-11-16 12:00:57 +01:00
|
|
|
- "import urllib.request as u; u.urlopen('http://127.0.0.1:8000/health/live', timeout=4)"
|
Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
2026-10-18 01:15:22 +02:00
|
|
|
interval: 30s
|
|
|
|
|
timeout: 5s
|
|
|
|
|
retries: 3
|
2026-11-16 12:00:57 +01:00
|
|
|
start_period: 30s
|
2026-10-18 00:54:23 +02:00
|
|
|
depends_on:
|
|
|
|
|
data-permissions:
|
|
|
|
|
condition: service_completed_successfully
|
2026-07-21 11:15:04 +02:00
|
|
|
|
2026-11-16 12:00:57 +01:00
|
|
|
# The background worker (ADR-55): its own process on the same SQLite file. It starts after
|
|
|
|
|
# the web process has migrated the database.
|
|
|
|
|
worker:
|
|
|
|
|
build: .
|
|
|
|
|
image: plm-lottery-web:local
|
|
|
|
|
restart: unless-stopped
|
|
|
|
|
env_file: .env
|
|
|
|
|
environment:
|
|
|
|
|
- DJANGO_DB_PATH=/app/db_data/site.sqlite3
|
2026-11-16 15:53:50 +01:00
|
|
|
- PROCESS_ROLE=worker
|
2026-11-16 16:18:34 +01:00
|
|
|
# ARC-78: the signing key is mounted here and nowhere else (read-only); `manage.py init_keys` writes it.
|
|
|
|
|
- PLM_MASTER_KEY_FILE=/run/plm-keys/master.key
|
|
|
|
|
- PLM_KEY_ENCRYPTION_KEY_FILE=/run/plm-keys/master.encryption.key
|
2026-11-16 12:00:57 +01:00
|
|
|
command: ["/bin/sh", "-c", "umask 077; exec python manage.py run_worker"]
|
|
|
|
|
volumes:
|
|
|
|
|
- ./data/db:/app/db_data
|
2026-11-16 16:18:34 +01:00
|
|
|
- ./data/keys:/run/plm-keys:ro
|
2026-11-16 12:00:57 +01:00
|
|
|
depends_on:
|
|
|
|
|
web:
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
|
2026-07-21 11:15:04 +02:00
|
|
|
caddy:
|
2026-10-18 00:54:23 +02:00
|
|
|
image: caddy:2-alpine@sha256:d8542f48d34a9cf4e4c11a478865229840e87e4c96ea3f439101f31a5d35f75f
|
2026-07-21 11:15:04 +02:00
|
|
|
restart: unless-stopped
|
|
|
|
|
ports:
|
|
|
|
|
- "80:80"
|
|
|
|
|
- "443:443"
|
|
|
|
|
environment:
|
|
|
|
|
- SITE_ADDRESS=${SITE_ADDRESS:-localhost}
|
|
|
|
|
volumes:
|
|
|
|
|
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
|
|
|
|
- caddy_data:/data
|
|
|
|
|
- caddy_config:/config
|
Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
2026-10-18 01:15:22 +02:00
|
|
|
networks:
|
|
|
|
|
default:
|
|
|
|
|
ipv4_address: 172.28.0.10
|
2026-07-21 11:15:04 +02:00
|
|
|
depends_on:
|
2026-11-16 12:00:57 +01:00
|
|
|
- web
|
2026-07-21 11:15:04 +02:00
|
|
|
|
2026-11-16 12:00:57 +01:00
|
|
|
# A fixed subnet and a fixed address for Caddy, so gunicorn can trust exactly that one proxy (ARC-02).
|
Readiness, Electrum status, audit browsing and logs (B-92, API-37, API-46, API-47, AUD-34, AUD-41, ARC-02, ARC-09, ARC-61, ELC-29, SEC-48)
2026-10-18 01:15:22 +02:00
|
|
|
networks:
|
|
|
|
|
default:
|
|
|
|
|
ipam:
|
|
|
|
|
config:
|
|
|
|
|
- subnet: 172.28.0.0/24
|
|
|
|
|
|
2026-11-16 12:00:57 +01:00
|
|
|
# The master-key secret returns with the worker in phase B (roadmap B4): only that process may read it.
|
2026-10-18 00:54:23 +02:00
|
|
|
|
2026-07-21 11:15:04 +02:00
|
|
|
volumes:
|
|
|
|
|
caddy_data:
|
|
|
|
|
caddy_config:
|