# ============================================================================= # docker-compose.yml — production topology for the whole site. # # WHAT IT DOES # Defines every container, the single bridge network they share, and the # named volumes that survive restarts. This file alone IS production: # docker compose up --build # Dev layers docker-compose.dev.yml on top of it (see that file). # # WHEN IT RUNS # On stpvm, via the Gitea Actions deploy workflow # (.gitea/workflows/deploy.yaml) on every push to main, and by hand. # # ENV VARS # Everything interpolated as ${VAR} below is read by the docker compose CLI # from ./.env at the repo root (gitignored, and edited by hand on the host). # Note the two distinct mechanisms: # - ${VAR} in this file -> substituted by compose when parsing # - `env_file: ./.env` -> the whole file injected into the container # Many services need both: the container name comes from substitution, the # app config from env_file. # # Required by this file: POSTGRES_{USER,PASSWORD,DB,PORT,HOST}, # BACKEND_HOST, ICECAST_HOST, GITEA_HOST, GITEA_UPSTREAM and # OBSIDIAN_DIR. PYTHON_HOST/PYTHON_PORT/TFL_APP_KEY/LIQUIDSOAP_HARBOR_PORT have # inline defaults. # # NAMING CONVENTION / WHY container_name IS SET FROM env # Service discovery is by container name on app-network. Caddy builds its # upstreams from the same ${*_HOST} variables (the caddy service's # environment list), so naming the containers from .env keeps the proxy and # the containers in sync from one source of truth. Renaming a *_HOST value # renames the container AND repoints Caddy at it — do not change one without # the other. # # WHAT IS PUBLISHED TO THE HOST # Only caddy (80, 443), gitea (3000 HTTP, 2222 SSH: the forwarder to the # Gitea LXC) and the liquidsoap harbor port. Everything else is reachable only from inside app-network, which is # why the backend, db, silverbullet and python have no `ports:` — they are # deliberately not exposed and are reached through Caddy. Web traffic can # also arrive through the `cloudflared` tunnel, which publishes nothing. # ============================================================================= networks: # One flat bridge network; every service resolves every other by container # name via docker's embedded DNS at 127.0.0.11 (Caddy resolves an upstream # through it each time it dials one). The subnet is pinned explicitly so it cannot collide # with the Pi's LAN range or wander between compose versions. app-network: driver: bridge ipam: config: - subnet: 172.28.0.0/16 # The usaco site's code runner and nothing else but the site. internal: # no route out, so code submitted to it cannot reach the internet, and # being off app-network keeps it away from postgres, gitea, garage and the # backend. Docker picks the subnet; nothing here pins an address on it. usaco-runner-net: driver: bridge internal: true # PERSISTENT vs EPHEMERAL state # Named volumes below survive `docker compose down` and container rebuilds; # they are only destroyed by `docker compose down -v` or an explicit # `docker volume rm`. Bind mounts (./backend/token, ./logs, ./caddy/data) # live in the repo checkout on the host and survive everything # short of deleting the directory. Anything inside a container's own # filesystem is ephemeral and gone on rebuild. volumes: # Postgres database — PERSISTENT. Holds the app DB and the job and activity # trackers' DBs. Deleting this wipes posts, users and messages. (Gitea's # database moved to its own Postgres in the Gitea LXC.) dbdata: # File upload — PERSISTENT. Written by the backend at /backend/uploads, # served read-only by Caddy at /uploads/. Shared so Caddy can serve user # uploads without proxying through the Go process. Since Garage, it holds # private attachments (always), the uploads from before the bucket, and any # upload the backend wrote here because Garage refused it. Caddy serves # /uploads/ from the bucket first and only then from here. uploads: # Garage object store — PERSISTENT, both. garage_meta is the metadata DB # (buckets, keys, the object index, the cluster layout); garage_data is the # object bytes. Lose meta and the bytes in data are unreadable, so back up # the two together. A fresh pair needs garage/bootstrap.sh run once. garage_meta: garage_data: # Vue build — EPHEMERAL in spirit but a named volume for handoff: the # one-shot `vue` container writes the built SPA here and exits; Caddy mounts # it at /srv/www and serves it. Repopulated on every rebuild. vue_dist: # Caddy's /config: the JSON it autosaves on each config load. Nothing in it # is needed across restarts (the Caddyfile is the source); named only so # the image's VOLUME does not leave an anonymous volume behind on every # recreate. The certificates are in ./caddy/data, not here. caddy_config: services: # One-shot build container, NOT a long-running service. `vite build` writes # the SPA into the shared vue_dist volume and the container exits 0. That # exit is expected — `docker compose ps` showing vue as Exited is healthy. # In dev this same service is overridden to run the Vite dev server instead # (docker-compose.dev.yml) and does stay up. vue: build: context: ./vue dockerfile: Dockerfile container_name: vue volumes: - vue_dist:/output networks: - app-network # The only public entrypoint: Caddy (caddy/Caddyfile). Terminates TLS, # serves the SPA, reverse-proxies everything else, and obtains and renews # its own certificates over DNS-01 into ./caddy/data, with no reload and no # inbound port. It replaced nginx and the certbot container on 2026-11-17; # both are in .deprecated/ (DEPLOYMENT.md §7 has the rollback). # # ENVIRONMENT: an explicit list, not the whole .env, so the edge never sees # the database password or the JWT secret. A variable the Caddyfile reads # must be added here, or it reaches Caddy empty. The ${X:-default} forms # are the defaults nginx's entrypoint gave the optional services; they live # here because Caddy's own {$X:default} keeps a variable that is set but # empty, which is how a blank line in .env arrives. # # NO depends_on: Caddy resolves an upstream when it dials it, so it starts # with any of them missing (502 until it appears), and there is no Vue # build to wait for: the SPA is files in vue_dist, served as they appear. caddy: build: context: ./caddy dockerfile: Dockerfile container_name: caddy restart: always environment: - DOMAIN=${DOMAIN} - BACKEND_HOST=${BACKEND_HOST} - BACKEND_PORT=${BACKEND_PORT} - BACKEND_ENDPOINT=${BACKEND_ENDPOINT} - ICECAST_HOST=${ICECAST_HOST} - ICECAST_PORT=${ICECAST_PORT} - GITEA_HOST=${GITEA_HOST} - GITEA_PORT=${GITEA_PORT} - SILVERBULLET_HOST=${SILVERBULLET_HOST:-silverbullet} - SILVERBULLET_PORT=${SILVERBULLET_PORT:-3000} - SILVERBULLET_PUBLIC_HOST=${SILVERBULLET_PUBLIC_HOST:-silverbullet-public} - SILVERBULLET_PUBLIC_PORT=${SILVERBULLET_PUBLIC_PORT:-3000} - PYTHON_HOST=${PYTHON_HOST:-python} - PYTHON_PORT=${PYTHON_PORT:-8000} # A dead port by default, so /receipt/ reads "offline". - RECEIPT_WEB_UPSTREAM=${RECEIPT_WEB_UPSTREAM:-127.0.0.1:9} - RECEIPT_WEB_TOKEN=${RECEIPT_WEB_TOKEN:-} # Partner Radar (radar.DOMAIN): the adamf/cto stack's `web` container, # which joins app-network under this alias (its docker-compose.stpvm.yml). # While that stack is down the name does not resolve and radar.DOMAIN # answers "offline". - RADAR_UPSTREAM=${RADAR_UPSTREAM:-radar-web:80} # Zone -> Zone -> Read and Zone -> DNS -> Edit; see .env.example. - CLOUDFLARE_DNS_API_TOKEN=${CLOUDFLARE_DNS_API_TOKEN:-} networks: app-network: # The site's public names, resolving to this container for everything # on app-network. They exist for cloudflared: its tunnel origin is # https://www.DOMAIN, which lands here over the bridge with a name the # Let's Encrypt certificate actually covers, so the tunnel verifies # TLS with no extra dashboard settings (`https://caddy` would fail the # name check). Any other container that calls the public site now # reaches Caddy directly instead of hairpinning through the internet. aliases: - ${DOMAIN} - www.${DOMAIN} - radar.${DOMAIN} # Fixed for cloudflared's extra_hosts (see there): an alias only # exists while Caddy is running, and this address is pinned to the # same names for when it is not. Top of the /16 beside cloudflared's, # away from docker's dynamic allocations. ipv4_address: 172.28.255.251 ports: - 80:80 - 443:443 volumes: # The certificates, their keys and the ACME account. PERSISTENT and # private key material: gitignored, never commit. Losing it only costs # a re-issue on the next start (seconds over DNS-01), during which the # tunnel, which verifies the certificate, serves 502s. - ./caddy/data:/data - caddy_config:/config - uploads:/srv/uploads:ro # The SPA written by the one-shot `vue` container. - vue_dist:/srv/www:ro # The JSON request-body log, kept on the host so it survives rebuilds # and the `traffic` container can tail it. Caddy rotates it itself # (50 MiB, five files kept). - ./logs/caddy:/var/log/caddy # restart: always only acts when the process exits. On 2026-10-19 nginx's # worker stalled while its master lived, and the site was down 4.6 hours # with the container "Up". /caddy-health (http://127.0.0.1 in the # Caddyfile) is answered by Caddy's own server, so a hung server shows # here; Docker only marks it unhealthy, and the `autoheal` label is what # gets it restarted (see the autoheal service). The image has busybox # wget, not curl. healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/caddy-health"] interval: 30s timeout: 10s retries: 3 start_period: 30s labels: - autoheal=true # Cloudflare Tunnel: an OUTBOUND connection from here to Cloudflare's edge, # which then forwards visitors' requests back down it to Caddy. Nothing is # published to the host, so with the tunnel live the router's 80/443 # forwards can be closed. The tunnel is "remotely managed": its public # hostnames and origin settings live in the Cloudflare dashboard, and this # container only needs the token. The routing set up there (DEPLOYMENT.md, # "Cloudflare Tunnel") is https://www.DOMAIN, which Caddy's network aliases # resolve to Caddy itself, so the certificate verifies; Caddy's config, # redirects and security headers apply to tunnel traffic exactly as to # direct traffic, and both paths work side by side. # # Fixed address so Caddy can trust the CF-Connecting-IP header from this # container and no other (trusted_proxies in caddy/Caddyfile). It sits # at the top of the /16 because docker hands out dynamic addresses from the # bottom; the two must change together. # # Disabled in dev via the `disabled` profile in docker-compose.dev.yml. cloudflared: image: cloudflare/cloudflared:2026.9.3 container_name: cloudflared restart: always command: ["tunnel", "--no-autoupdate", "run"] # Explicit, not env_file: the container only ever needs the token. environment: - TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN:-} depends_on: - caddy # Pins the tunnel origin's names to Caddy's fixed address. Its aliases # vanish while it is stopped (every deploy and the weekly maintenance), and # docker's DNS then forwards the name to public DNS, which answers with # Cloudflare's own IPs: the tunnel sent requests back to the edge and # visitors got error 1000. /etc/hosts wins over DNS, so a stopped Caddy is # now a refused connection, which cloudflared reports as a plain 502. extra_hosts: - "${DOMAIN}:172.28.255.251" - "www.${DOMAIN}:172.28.255.251" - "radar.${DOMAIN}:172.28.255.251" networks: app-network: ipv4_address: 172.28.255.250 backend: build: context: ./backend dockerfile: Dockerfile container_name: "${BACKEND_HOST}" restart: always # MAP form, not the list form used elsewhere: this waits for db's # healthcheck to pass, not merely for its container to start. Without it # the Go process raced Postgres on every boot, failed its first connection, # died, and relied on `restart: always` to try again — noisy log churn and # a slower cold start in practice. # `restart: always` is deliberately KEPT as the backstop: if db's health # probe were ever to stall past compose's patience, or the DB dropped out # later, the restart policy still recovers the backend. depends_on: db: condition: service_healthy networks: - app-network env_file: - ./.env volumes: # PERSISTENT, and the subtle one: the Spotify OAuth refresh token is # written here as spotify_token.json. Without this bind mount the token # would live in the container filesystem and be destroyed on every # rebuild, forcing a manual re-authorisation of Spotify after each # deploy. Gitignored (it is a credential). - ./backend/token/:/backend/token # The Obsidian vault on the host, read by the backend for the notes API. # Same directory is mounted read-write into silverbullet (the editor) and # read-only into silverbullet-public (the /notes/ site). - ${OBSIDIAN_DIR}:/backend/notes - ./logs:/backend/logs # Same named volume Caddy serves at /uploads/ — backend writes, Caddy reads. - uploads:/backend/uploads # Shared with icecast2, which plays these as the radio fallback playlist; # the backend reads them to report what is queued. - ./icecast2/fallback_music:/backend/fallback_music # Reported to docker only: nothing acts on `unhealthy` since the autoheal # watchdog was retired (.deprecated/autoheal), so this just shows up in # `docker ps`. `restart: always` covers a crashed process, not a hung one. # start_period gives the Go process 10s to bind before failures start # counting. healthcheck: test: ["CMD", "wget", "-qO-", "http://localhost:8080/"] interval: 30s timeout: 5s retries: 3 start_period: 10s # Single Postgres instance: ${POSTGRES_DB} for the Go backend, plus the job # and activity trackers' databases. The postgres image only creates # POSTGRES_DB on first init; the others are created by hand (see their # READMEs). Gitea's database is not here any more: it has its own Postgres # in the Gitea LXC (gitea/docker-compose.yml). # Schema for the app DB comes from GORM auto-migration at backend start — # there are no migration files. db: image: postgres:16 container_name: "${POSTGRES_HOST}" restart: always env_file: - ./.env networks: - app-network volumes: - dbdata:/var/lib/postgresql/data # Postgres is the one dependency the backend genuinely cannot start # without, so `backend` gates on this healthcheck (condition: # service_healthy) instead of on mere container start. # TUNED FOR SLOW ARM HARDWARE: on a Raspberry Pi with a cold page cache a # first-boot Postgres can take well over a minute to finish initdb/recovery # and accept connections. start_period is the grace window during which a # failing probe does NOT count against `retries` and does NOT mark the # container unhealthy, so 90s costs nothing on a warm boot and prevents a # false "unhealthy" on a cold one. After that, 10 retries at 10s gives # another ~100s before anything gives up. `pg_isready -U $POSTGRES_USER` # is the cheapest real readiness probe (it does a protocol-level connect, # not just a TCP open). Note $$POSTGRES_USER: the doubled $ escapes # compose's own interpolation so the variable is expanded by the shell # INSIDE the container, from env_file, at probe time. healthcheck: test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\" -q"] interval: 10s timeout: 5s retries: 10 start_period: 90s # Internet radio: one container running BOTH icecast2 (the streaming server # listeners connect to, proxied at /radio/) and liquidsoap (the source that # feeds it). See icecast2/entrypoint.sh. # # This is the only non-Caddy service that publishes a host port, and it has # to: LIQUIDSOAP_HARBOR_PORT is the live-DJ input. A broadcasting client # (e.g. butt) connects straight to the Pi on that port, by its Tailscale # name now that the public domain resolves to Cloudflare, with the icecast # source password and pre-empts the fallback playlist. It is NOT proxied # through Caddy because it is a raw source protocol, not HTTP the SPA uses. # Note the host:container mapping uses the same variable on both sides, so # the published port always matches what liquidsoap actually binds. icecast2: build: context: ./icecast2 dockerfile: Dockerfile container_name: "${ICECAST_HOST}" restart: always networks: - app-network env_file: - ./.env volumes: - ./icecast2/fallback_music:/music:ro ports: - "${LIQUIDSOAP_HARBOR_PORT:-8001}:${LIQUIDSOAP_HARBOR_PORT:-8001}" # Browser-based editor for the vault, so notes are editable from a phone. # Proxied at /sb/ behind Caddy's admin gate. The public site at /notes/ is # a SECOND, read-only SilverBullet over the same folder (silverbullet-public, # below). # # SINGLE-SPACE MODE is auto-detected because the mounted folder is not empty # (the alternative, multi-space, expects /data to be a SilverBullet-owned # folder of spaces). In this mode it treats the mount as the space itself and # writes NO database or metadata files into the vault — the folder stays a # plain directory of markdown that Obsidian still understands. silverbullet: image: ghcr.io/silverbulletmd/silverbullet:2.11.0 container_name: "${SILVERBULLET_HOST:-silverbullet}" restart: always networks: - app-network environment: SB_PORT: "${SILVERBULLET_PORT:-3000}" # The app builds its service-worker scope and asset URLs from this, which # is why Caddy must NOT strip the /sb/ prefix. See caddy/routes.caddy. SB_URL_PREFIX: /sb # Only .obsidian: it is editor config and plugin JS, not notes. # # Deliberately NOT silverbullet-public's list, which also hides private/ # and templates/. The two answer different questions: the public # instance hides private/ because it must never be PUBLISHED, whereas # this is the editor, reachable only through the admin gate, and hiding # notes from it just stops you editing them. # # MUST be newline separated: a comma separated list is accepted silently # and does nothing. SB_SPACE_IGNORE: | .obsidian # Pinned rather than inferred from the mount's owner, so the files it # writes match the vault's ownership on the host. PUID: "1000" PGID: "1000" # Uncomment for a look-but-don't-touch first boot against a real vault: # SB_READ_ONLY: "true" volumes: - ${OBSIDIAN_DIR}:/data # The PUBLIC notes site at /notes/ (replaced Quartz): the same SilverBullet # image in read-only mode over the same vault, with no auth. Visitors get the # full client — navigation, backlinks, live queries — but cannot write. # Edits made in the /sb/ editor show up here live, since both watch one folder. # # KEEPING private/ PRIVATE takes three layers, because none is enough alone: # 1. SB_SPACE_IGNORE hides the paths from the file LIST, so they are # never indexed, searched or shown. It does NOT stop # a direct fetch of /.fs/private/x.md, nor the page # URL /notes/private/x (server-rendered with the # note's content), nor /.fs/.git/ — SilverBullet # only applies it to listing (checked in 2.11.0). # 2. Caddy deny rules 404 any private/ or templates/ segment and any # nested dot-folder under /notes/; this is what # actually closes those holes. Keep its folder list # in step with the one below. # 3. SB_REVISIONS the default ("unmanaged") serves history from the # vault's own .git, i.e. every version of every file # including private/ and deleted ones. Disabled here, # and Caddy blocks /notes/.revisions as well. # # SB_READ_ONLY rejects writes server-side and also disables the shell and the # /.proxy endpoint (otherwise an open fetch proxy). The :ro mount is a second # lock on writes. It is flagged "legacy" upstream in favour of multi-space # mode's per-space publish setting, which cannot exclude a folder and would # mean migrating the editor too — revisit if single-space mode is removed. # # Keep the image tag in lockstep with the editor above. silverbullet-public: image: ghcr.io/silverbulletmd/silverbullet:2.11.0 container_name: "${SILVERBULLET_PUBLIC_HOST:-silverbullet-public}" restart: always networks: - app-network environment: SB_PORT: "${SILVERBULLET_PUBLIC_PORT:-3000}" # Same reason as the editor's SB_URL_PREFIX: Caddy must not strip /notes/. SB_URL_PREFIX: /notes SB_READ_ONLY: "true" SB_REVISIONS: disabled # Newline separated (commas are silently ignored). Gitignore semantics, # so these match at any depth. Must match the folder list in the # /notes/ deny regex in caddy/routes.caddy, or a new entry here is # hidden from the list but still publicly fetchable. SB_SPACE_IGNORE: | private/ templates/ .obsidian PUID: "1000" PGID: "1000" volumes: - ${OBSIDIAN_DIR}:/data:ro # SilverBullet has no concept of git, so this commits and pushes what it # writes, and pulls what Obsidian pushes from elsewhere. # # WHY A SEPARATE CONTAINER and not SilverBullet's own shell backend: enabling # that would give anyone who gets past Caddy's admin gate command execution # inside the container. Since SilverBullet itself runs with no SB_USER, that # gate is the only thing protecting it, so the blast radius stays here. silverbullet-git: image: alpine/git:v2.54.0 container_name: "${SILVERBULLET_GIT_HOST:-silverbullet-git}" restart: always networks: - app-network # The vault's remotes are ssh://git@DOMAIN:2222/..., but Caddy's network # aliases make DOMAIN resolve to Caddy on app-network, which has no :2222, # so every pull and push was refused. /etc/hosts wins over Docker's DNS, so # this sends DOMAIN back to the host, where the gitea forwarder publishes # 2222. The name # is unchanged, so known_hosts still matches. extra_hosts: - "${DOMAIN}:host-gateway" # Same uid SilverBullet writes as, so commits don't leave root-owned objects # in .git that the host user can no longer clean up. user: "1000:1000" environment: SYNC_INTERVAL: "${SILVERBULLET_GIT_INTERVAL:-300}" GIT_AUTHOR_NAME: silverbullet GIT_AUTHOR_EMAIL: "silverbullet@${DOMAIN}" GIT_COMMITTER_NAME: silverbullet GIT_COMMITTER_EMAIL: "silverbullet@${DOMAIN}" # uid 1000 has no home in this image; give git somewhere writable. HOME: /tmp GIT_SSH_COMMAND: "ssh -i /ssh/id_ed25519 -o UserKnownHostsFile=/ssh/known_hosts -o IdentitiesOnly=yes" entrypoint: ["/bin/sh", "/git-sync.sh"] volumes: - ${OBSIDIAN_DIR}:/space - ./silverbullet/git-sync.sh:/git-sync.sh:ro - ./silverbullet/ssh:/ssh:ro # ssh will not run for a uid with no passwd entry; see the file's comment. - ./silverbullet/passwd:/etc/passwd:ro # FastAPI side-service, proxied at /py/ with the prefix stripped by Caddy. # ROOT_PATH=/py tells FastAPI it is mounted under a prefix so the generated # OpenAPI/Swagger URLs (/py/docs) are correct even though the app's own # routes are written relative to /. # Note this service uses `environment:` with an explicit allow-list rather # than `env_file: ./.env` — it only gets the variables it needs and never # sees the database password, Spotify secrets, or the other API keys. # CLAUDE_API_KEY is the one secret on the list: the rowing photo reader # (POST /internal/rowing/read, called by the backend, blocked at Caddy) # makes its Claude call here. python: build: context: ./python dockerfile: Dockerfile container_name: "${PYTHON_HOST:-python}" restart: always networks: - app-network environment: - PYTHON_PORT=${PYTHON_PORT:-8000} - ROOT_PATH=/py - TFL_APP_KEY=${TFL_APP_KEY:-} - CLAUDE_API_KEY=${CLAUDE_API_KEY:-} - CLAUDE_MODEL=${CLAUDE_MODEL:-} healthcheck: test: ["CMD", "python", "-c", "import urllib.request,os; urllib.request.urlopen(f\"http://localhost:{os.environ.get('PYTHON_PORT','8000')}/health\")"] interval: 30s timeout: 5s retries: 3 start_period: 10s # The job application tracker, served at /jobs/. Built and published by its # own repo (adamf/job-tracker on this Gitea), whose README covers the # first-time database setup and the cutover from the old in-backend tracker. # # Like python, it gets an explicit `environment:` list rather than the whole # .env: it never sees the site's database password or JWT secret, and has a # database role of its own. A variable the tracker reads must be added to # the list below as well as .env.example. # # It has no login. Caddy's admin gate gates /jobs/ like /sb/ (except the # bearer-token capture API and the userscript), and the tracker checks # again itself: AUTH_VALIDATE_URL is the backend's validate-admin route # (the one Caddy's admin gate uses), which it asks with the visitor's # cookies on each admin request. # # ./jobs-data holds the Microsoft Graph session and the capture token. The # image runs as uid 1000, so the directory must be owned by it. jobs: image: adam-french.co.uk/adamf/job-tracker:${JOBS_IMAGE_TAG:-latest} container_name: jobs restart: always depends_on: db: condition: service_healthy networks: - app-network environment: - DATABASE_URL=postgres://${POSTGRES_JOBS_USER:-jobs}:${POSTGRES_JOBS_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_JOBS_DB:-jobs}?sslmode=disable - AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin - CLAUDE_API_KEY=${CLAUDE_API_KEY:-} - CLAUDE_MODEL=${CLAUDE_MODEL:-} - EMAIL_BACKEND=${EMAIL_BACKEND:-} - EMAIL_SYNC_ENABLED=${EMAIL_SYNC_ENABLED:-} - EMAIL_SYNC_INTERVAL=${EMAIL_SYNC_INTERVAL:-} - MSGRAPH_CLIENT_ID=${MSGRAPH_CLIENT_ID:-} - MSGRAPH_CLIENT_SECRET=${MSGRAPH_CLIENT_SECRET:-} - MSGRAPH_TENANT_ID=${MSGRAPH_TENANT_ID:-} - MSGRAPH_REDIRECT_URI=${MSGRAPH_REDIRECT_URI:-} - IMAP_HOST=${IMAP_HOST:-} - IMAP_PORT=${IMAP_PORT:-} - IMAP_EMAIL=${IMAP_EMAIL:-} - IMAP_PASSWORD=${IMAP_PASSWORD:-} - JOB_LEADS_ENABLED=${JOB_LEADS_ENABLED:-} - JOB_LEADS_INTERVAL=${JOB_LEADS_INTERVAL:-} - ADZUNA_APP_ID=${ADZUNA_APP_ID:-} - ADZUNA_APP_KEY=${ADZUNA_APP_KEY:-} - REED_API_KEY=${REED_API_KEY:-} volumes: - ./jobs-data:/data # The USACO practice log, served at /usaco/. Built and published by the # usaco repo's CI (adamf/usaco on this Gitea; the server is in its site/ # directory), which pulls :latest into this service on every push to main # that touches the site. Pin USACO_IMAGE_TAG to hold a version. # # It has no database: git is its store. It keeps a clone of adamf/usaco in # ./usaco-data, pulled over the Docker network when Gitea's push webhook # fires (USACO_WEBHOOK_SECRET signs it), and commits the admin's edits # (status, link, notes, statement, explanations) back with USACO_GIT_TOKEN. # CLAUDE_API_KEY powers the admin's Explain button (USACO_CLAUDE_MODEL picks # the model; blank is claude-opus-5-5). Recording reviews also need # USACO_OPENAI_API_KEY to transcribe, and keep the audio in Garage's # private usaco-audio bucket when USACO_S3_* is set (the site refuses to # start with only some S3_* set, so all five go together or not at all: # the blank-key case blanks the rest). USACO_CLAUDE_MONTHLY_BUDGET (dollars, # blank for none) stops new Claude jobs once a month's estimated spend # reaches it. ./usaco-data holds that clone, the background jobs' records # and the Claude spend ledger; deleting it is safe (it re-clones) but loses # any answer not yet committed. The image runs as uid 1000, so the # directory must be owned by it. # # On stop it lets running Claude jobs finish for up to SHUTDOWN_GRACE (5m # by default) before exiting, so stop_grace_period must be longer than # that, or Docker kills it mid-job. # # Same explicit `environment:` list as jobs. Like the tracker it has no # login: visitors see solved problems, and AUTH_VALIDATE_URL decides who # is the admin from the visitor's cookies. usaco: image: adam-french.co.uk/adamf/usaco:${USACO_IMAGE_TAG:-latest} container_name: usaco restart: always stop_grace_period: 6m depends_on: - gitea - usaco-runner networks: - app-network - usaco-runner-net environment: - GIT_REMOTE_URL=http://${GITEA_HOST}:${GITEA_PORT}/adamf/usaco.git - GIT_TOKEN=${USACO_GIT_TOKEN:-} - WEBHOOK_SECRET=${USACO_WEBHOOK_SECRET:-} - AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin - CLAUDE_API_KEY=${CLAUDE_API_KEY:-} - CLAUDE_MODEL=${USACO_CLAUDE_MODEL:-} - CLAUDE_MONTHLY_BUDGET=${USACO_CLAUDE_MONTHLY_BUDGET:-} - TRANSCRIBE_API_KEY=${USACO_OPENAI_API_KEY:-} - S3_ACCESS_KEY_ID=${USACO_S3_ACCESS_KEY_ID:-} - S3_SECRET_ACCESS_KEY=${USACO_S3_SECRET_ACCESS_KEY:-} - S3_ENDPOINT=${USACO_S3_ACCESS_KEY_ID:+http://garage:3900} - S3_REGION=${USACO_S3_ACCESS_KEY_ID:+garage} - S3_BUCKET=${USACO_S3_ACCESS_KEY_ID:+usaco-audio} - RUNNER_URL=http://usaco-runner:8081 volumes: - ./usaco-data:/data # The usaco site's code runner (site/Dockerfile.runner in adamf/usaco): # compiles and runs solutions against their tests, and lints them, for the # admin's solve page. It runs submitted code, so it has no secrets (no # environment at all) and is only on usaco-runner-net, which is internal: # no internet, and nothing but the site can reach it. Published by # adamf/usaco's CI, which rolls it before `usaco`; pin # USACO_RUNNER_IMAGE_TAG to hold a version. # # The hardening is the point: # read_only the image is not writable; only /tmp is # tmpfs /tmp one directory per request, removed after. Must NOT be # noexec: the compiled program runs from it. Its pages count # against mem_limit. # mem_limit, cpus # on top of the runner's own per-program limits (512 MB # address space, CPU time, 64 MB files, wall clock) # pids_limit what stops a fork bomb: the runner does not set # RLIMIT_NPROC (it counts the whole uid, the server's own # threads included). The image's tini reaps the leftovers. # cap_drop, no-new-privileges # the runner needs no capabilities, and runs as uid 1000 usaco-runner: image: adam-french.co.uk/adamf/usaco-runner:${USACO_RUNNER_IMAGE_TAG:-latest} container_name: usaco-runner restart: always networks: - usaco-runner-net read_only: true tmpfs: - /tmp:size=256m,exec mem_limit: 1g cpus: 2 pids_limit: 128 cap_drop: - ALL security_opt: - no-new-privileges:true # The activity tracker (time spent per app, site, walk...), served at # /tracker/ with the prefix stripped. Built and published by its own repo # (adamf/ccp on this Gitea), whose CI pulls :latest into this service on # every push to main; pin ACTIVITY_TRACKER_IMAGE_TAG to hold a version. # # Same shape as jobs: an explicit `environment:` list and a database role of # its own, created by hand once (the ccp README has the command). It applies # its own migrations on start. No state outside Postgres. # # Two kinds of auth. Collectors send per-device bearer keys, made on the # tracker's /tracker/setup page or with `docker exec activity-tracker # tracker apikey create`. The dashboard and setup pages have no login of # their own: Caddy's admin gate gates them like /sb/ (everything but # /tracker/api/v1/ and the userscript), and like jobs the tracker also asks # AUTH_VALIDATE_URL (the backend's validate-admin) with the visitor's # cookies and sends anyone else to /admin/login. activity-tracker: image: adam-french.co.uk/adamf/activity-tracker:${ACTIVITY_TRACKER_IMAGE_TAG:-latest} container_name: activity-tracker restart: always depends_on: db: condition: service_healthy networks: - app-network environment: - DATABASE_URL=postgres://${POSTGRES_TRACKER_USER:-tracker}:${POSTGRES_TRACKER_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_TRACKER_DB:-tracker}?sslmode=disable - TRACKER_TZ=${TRACKER_TZ:-} - AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin # Echoes Caddy's JSON request-body log to its own stdout, and does nothing # else. It exists so Dozzle shows the payloads as a stream of their own, # rendered as JSON fields, instead of interleaved with Caddy's compact access # log and error output. -F re-opens the file after rotation; -n0 skips the # backlog on restart, which stays in the file on the host. traffic: image: busybox:1.38.0 container_name: traffic restart: always command: ["tail", "-n0", "-F", "/logs/payloads.log"] network_mode: none volumes: - ./logs/caddy:/logs:ro # Dozzle: a live, searchable web view of every container's logs, served at # /dozzle/ behind the admin login (caddy/routes.caddy). The # `traffic` container is the one to watch for incoming request bodies. # # The Docker socket is mounted :ro, but that only stops the file being # replaced — the API behind it is still fully usable, which is effectively # root on the Pi. Hence: no published port, the admin auth_request in front, # and container actions and shell left at their default of off. dozzle: image: amir20/dozzle:v11.2.0 container_name: dozzle restart: always networks: - app-network environment: - DOZZLE_BASE=/dozzle - DOZZLE_NO_ANALYTICS=true volumes: - /var/run/docker.sock:/var/run/docker.sock:ro # Restarts any container labelled autoheal=true once Docker marks it # unhealthy, which Docker itself never does (restart policies only see the # process exit). Only caddy carries the label today; give it to another # service with a healthcheck to cover that one too. It polls every 5s. # # It needs the Docker socket read-write to restart things, which is root on # the host, so it gets no network at all: nothing can reach it, and it # reaches nothing but the socket. For the same reason the image is pinned BY # DIGEST, never a tag, so a push to Docker Hub cannot gain root here at the # next pull. The digest is the multi-arch index of 1.2.0, the newest tagged # release; it calls the API unversioned, so it keeps working as the engine's # minimum API version moves. To bump: `docker buildx imagetools inspect # willfarrell/autoheal:` and paste the top-level Digest. # # This is the watchdog retired on 2026-10-01 (.deprecated/autoheal), back # with a label filter instead of `all`, so backend's and python's # healthchecks stay informational. autoheal: image: willfarrell/autoheal@sha256:31f580ef0279eaced5b38d631b08c474d70d8403c1c2fdd6ddcf2e879d5f3f7c container_name: autoheal restart: always network_mode: none environment: - AUTOHEAL_CONTAINER_LABEL=autoheal volumes: - /var/run/docker.sock:/var/run/docker.sock # S3-compatible object store holding public uploads (the `uploads` bucket). # The backend writes to it on :3900 once S3_ENDPOINT is set in .env; Caddy # serves /uploads/ from it anonymously on :3902, falling back to the # `uploads` volume; garage-webui manages it via :3903. Nothing is published # to the host. Config is garage/garage.toml (no secrets in it); the two # secrets come from .env through the explicit list below. # # Nothing depends on this container being up. Caddy is deliberately NOT # given it in depends_on: it resolves garage when it dials it, so a missing # or crash-looping garage only makes bucket-only files 404 (everything on # the volume is still served), never Caddy's start; and the backend falls back # to the volume when a write fails. # # FIRST RUN: garage/bootstrap.sh (layout, bucket, key, website access). # The image is FROM scratch — no shell, so no in-container init script and # a healthcheck that calls the binary itself. garage: image: dxflrs/garage:v2.5.0 container_name: garage restart: always networks: - app-network environment: - GARAGE_RPC_SECRET=${GARAGE_RPC_SECRET} - GARAGE_ADMIN_TOKEN=${GARAGE_ADMIN_TOKEN} volumes: - ./garage/garage.toml:/etc/garage.toml:ro - garage_meta:/var/lib/garage/meta - garage_data:/var/lib/garage/data healthcheck: test: ["CMD", "/garage", "status"] interval: 30s timeout: 5s retries: 3 start_period: 10s # Admin web UI for Garage, served at /garage/ behind Caddy's admin gate. # Manages buckets and keys, and browses/uploads/deletes objects. Its own # login (AUTH_USER_PASS) is left unset because Caddy's admin gate already # requires the site admin — and it holds the admin token, so never publish # its port. It reads the s3/web settings from garage.toml; the token comes # from .env instead, since the file has none. # # Files uploaded here land in the PUBLIC bucket and are served at # /uploads/ with none of the backend's checks. Put hand-managed media # under a prefix (e.g. media/) so it can't collide with the backend's # random hex names. garage-webui: image: khairul169/garage-webui:1.1.0 container_name: garage-webui restart: always depends_on: - garage networks: - app-network environment: - BASE_PATH=/garage - API_BASE_URL=http://garage:3903 - API_ADMIN_KEY=${GARAGE_ADMIN_TOKEN} - S3_ENDPOINT_URL=http://garage:3900 - S3_REGION=garage # The image has no /tmp, and Go spools any multipart upload over 32MB to # a temp file there, so without this every large upload fails with # "open /tmp/multipart-…: no such file or directory". tmpfs: - /tmp volumes: - ./garage/garage.toml:/etc/garage.toml:ro # Gitea's ports on this host, forwarded to Gitea itself, which runs in its # own LXC (gitea/docker-compose.yml; DEPLOYMENT.md §7, "Gitea LXC"). A # plain TCP forwarder (gitea/forwarder.cfg), kept under the old service and # container name so nothing that talked to Gitea here had to change: # Caddy's /gitea/ and /v2/ upstream and the backend's feed (GITEA_HOST, # GITEA_PORT), usaco's pulls, and on the host the runner and Renovate # (localhost:3000) and every repo's CI and the obsidian checkout # (localhost:2222, or DOMAIN:2222 pinned to the host). # # Gitea is also the CI server: .gitea/workflows/deploy.yaml redeploys this # whole stack on push to main, executed by the act_runner that lives # outside docker (gitea-runner/). Recreating this container drops git and # registry connections in flight for a moment, which is why its config is # small and rarely changes; Gitea itself is never restarted by a deploy. # # GITEA_UPSTREAM is the LXC's LAN IP. Dev has no Gitea: it points at a dummy # address and /gitea/ answers 502. gitea: image: haproxy:3.2.27-alpine container_name: "${GITEA_HOST}" restart: always networks: - app-network environment: - GITEA_UPSTREAM=${GITEA_UPSTREAM:?set GITEA_UPSTREAM in .env to the Gitea LXC's LAN IP} volumes: - ./gitea/forwarder.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ports: # 2222 = Gitea's built-in SSH server; clones use ssh://git@host:2222/... # — including the deploy workflow, which fetches from # ssh://git@localhost:2222. - "2222:2222" # 3000 = HTTP, published as well as proxied at /gitea/, because the # act_runner registers against http://localhost:3000 from the host. - "3000:3000"