Files
plm-lottery/docker-compose.yml
T

92 lines
2.9 KiB
YAML
Raw Normal View History

# 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).
services:
# 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: .
image: plm-lottery-web:local
user: "0:0"
entrypoint: ["/bin/sh", "-c", "chown -R 1000:1000 /data && chmod -R go-rwx /data"]
volumes:
- ./data:/data
restart: "no"
# The web process: Django behind gunicorn. It applies the migrations at startup.
web:
build: .
image: plm-lottery-web:local
restart: unless-stopped
env_file: .env
environment:
- 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).
- FORWARDED_ALLOW_IPS=172.28.0.10
volumes:
- ./data/db:/app/db_data
expose:
- "8000"
# ARC-73: liveness = the process answers and the database opens.
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request as u; u.urlopen('http://127.0.0.1:8000/health/live', timeout=4)"
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
depends_on:
data-permissions:
condition: service_completed_successfully
# 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
command: ["/bin/sh", "-c", "umask 077; exec python manage.py run_worker"]
volumes:
- ./data/db:/app/db_data
depends_on:
web:
condition: service_healthy
caddy:
image: caddy:2-alpine@sha256:d8542f48d34a9cf4e4c11a478865229840e87e4c96ea3f439101f31a5d35f75f
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
networks:
default:
ipv4_address: 172.28.0.10
depends_on:
- web
# A fixed subnet and a fixed address for Caddy, so gunicorn can trust exactly that one proxy (ARC-02).
networks:
default:
ipam:
config:
- subnet: 172.28.0.0/24
# The master-key secret returns with the worker in phase B (roadmap B4): only that process may read it.
volumes:
caddy_data:
caddy_config: