A1: Django skeleton with web and worker processes (ADR-54, ADR-55, WEB-01, WEB-07, ARC-70..74)
Django 5.2 project (config/, apps/accounts with a custom User and case-insensitive usernames, apps/lottery with the run_worker command, apps/web with a placeholder home and /health/live, apps/ops), SQLite in WAL with IMMEDIATE transactions, secrets and hosts from the environment. The compose stack is now web + worker + caddy and serves https://localhost; the old FastAPI service is out of the stack until roadmap D1. The three old infrastructure tests follow the new Dockerfile and compose. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79f7ebe53e
commit
fc23a75c9b
43 files changed
+709
-61
No files matched your search
+33
-24
@@ -1,52 +1,65 @@
|
||||
# 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-app:local
|
||||
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"
|
||||
|
||||
app:
|
||||
# The web process: Django behind gunicorn. It applies the migrations at startup.
|
||||
web:
|
||||
build: .
|
||||
image: plm-lottery-app:local
|
||||
image: plm-lottery-web:local
|
||||
restart: unless-stopped
|
||||
env_file: .env
|
||||
environment:
|
||||
- DATABASE_URL=sqlite+aiosqlite:////app/db_data/plm_lottery.db
|
||||
- MASTER_KEY_PATH=/app/key_data/master.xprv.enc
|
||||
- XPRV_ENCRYPTION_KEY_FILE=/run/secrets/xprv_encryption_key
|
||||
# B-92 (ARC-02): uvicorn trusts X-Forwarded-For from Caddy's fixed address only, so the access
|
||||
# log records the client's IP instead of Caddy's.
|
||||
- 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
|
||||
secrets:
|
||||
- xprv_encryption_key
|
||||
volumes:
|
||||
- ./data/db:/app/db_data
|
||||
- ./data/keys:/app/key_data
|
||||
- ./data/logs:/app/logs
|
||||
expose:
|
||||
- "8123"
|
||||
# B-92 (ARC-61): ready = Electrum connected, a recent header, a live scheduler. Docker does not
|
||||
# restart an unhealthy container (the process exiting does); the state is for monitoring.
|
||||
- "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:8123/health/ready', timeout=4)"
|
||||
- "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: 60s
|
||||
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
|
||||
@@ -63,20 +76,16 @@ services:
|
||||
default:
|
||||
ipv4_address: 172.28.0.10
|
||||
depends_on:
|
||||
- app
|
||||
- web
|
||||
|
||||
# A fixed subnet and a fixed address for Caddy, so uvicorn can trust exactly that one proxy (ARC-02).
|
||||
# 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 Fernet key that protects the master key lives in its own file, outside ./data (a backup of
|
||||
# the data does not carry both) and in no environment variable (SEC-53).
|
||||
secrets:
|
||||
xprv_encryption_key:
|
||||
file: ./secrets/xprv_encryption.key
|
||||
# The master-key secret returns with the worker in phase B (roadmap B4): only that process may read it.
|
||||
|
||||
volumes:
|
||||
caddy_data:
|
||||
|
||||
Reference in new issue
Block a user