diff --git a/.deprecated/README.md b/.deprecated/README.md index 464d3d0..e1dc188 100644 --- a/.deprecated/README.md +++ b/.deprecated/README.md @@ -1,6 +1,6 @@ # .deprecated -STATUS: nothing in here is live. No compose file, nginx template or script +STATUS: nothing in here is live. No compose file, Caddyfile or script references this directory. It is kept, not deleted, in line with the repo's "legacy is kept" convention; the full history is also in git. @@ -34,5 +34,18 @@ effectively root on the host. To bring it back, layer `docker-compose.autoheal.yml` the same way as above. Since 2026-10-19 it is back in `docker-compose.yml`, watching only containers -labelled `autoheal=true` (nginx). This copy is the old `all` variant, kept for -reference. +labelled `autoheal=true` (caddy; nginx until 2026-11-17). This copy is the old +`all` variant, kept for reference. + +## nginx/ and certbot/ + +The public edge until 2026-11-17, when Caddy (`caddy/`) replaced both: +`nginx/` is the image (three templates chosen at start by `entrypoint.sh`, +the shared route table, the payload log and security-header includes), and +`certbot/entrypoint.sh` obtained and renewed the certificate that nginx +reloaded through a sentinel file. Their compose services were removed in +`daa2a46`. The last certbot certificate is still in `./certbot/conf` on the +host, valid until 2027-01-20. + +To bring them back: revert the commit that moved them here and then `daa2a46`; +DEPLOYMENT.md §7 ("Roll back to nginx") has the commands. diff --git a/certbot/entrypoint.sh b/.deprecated/certbot/entrypoint.sh similarity index 100% rename from certbot/entrypoint.sh rename to .deprecated/certbot/entrypoint.sh diff --git a/nginx/.dockerignore b/.deprecated/nginx/.dockerignore similarity index 100% rename from nginx/.dockerignore rename to .deprecated/nginx/.dockerignore diff --git a/nginx/Dockerfile b/.deprecated/nginx/Dockerfile similarity index 100% rename from nginx/Dockerfile rename to .deprecated/nginx/Dockerfile diff --git a/nginx/entrypoint.sh b/.deprecated/nginx/entrypoint.sh similarity index 100% rename from nginx/entrypoint.sh rename to .deprecated/nginx/entrypoint.sh diff --git a/nginx/nginx.conf.template b/.deprecated/nginx/nginx.conf.template similarity index 100% rename from nginx/nginx.conf.template rename to .deprecated/nginx/nginx.conf.template diff --git a/nginx/nginx_dev.conf.template b/.deprecated/nginx/nginx_dev.conf.template similarity index 100% rename from nginx/nginx_dev.conf.template rename to .deprecated/nginx/nginx_dev.conf.template diff --git a/nginx/nginx_dev_common.conf.template b/.deprecated/nginx/nginx_dev_common.conf.template similarity index 100% rename from nginx/nginx_dev_common.conf.template rename to .deprecated/nginx/nginx_dev_common.conf.template diff --git a/nginx/nginx_routes.conf.template b/.deprecated/nginx/nginx_routes.conf.template similarity index 100% rename from nginx/nginx_routes.conf.template rename to .deprecated/nginx/nginx_routes.conf.template diff --git a/nginx/nginx_setup.conf.template b/.deprecated/nginx/nginx_setup.conf.template similarity index 100% rename from nginx/nginx_setup.conf.template rename to .deprecated/nginx/nginx_setup.conf.template diff --git a/nginx/payload_log.conf b/.deprecated/nginx/payload_log.conf similarity index 100% rename from nginx/payload_log.conf rename to .deprecated/nginx/payload_log.conf diff --git a/nginx/security_headers.conf b/.deprecated/nginx/security_headers.conf similarity index 100% rename from nginx/security_headers.conf rename to .deprecated/nginx/security_headers.conf diff --git a/.env.example b/.env.example index 6379352..622785a 100644 --- a/.env.example +++ b/.env.example @@ -184,7 +184,7 @@ LIQUIDSOAP_HARBOR_PORT=8001 # certificate for it and for www.DOMAIN, and canonicalises to www. # EMAIL was certbot's Let's Encrypt account address. Nothing reads it since # the move to Caddy, which registers its ACME account without one; it stays -# for the nginx/certbot rollback (DEPLOYMENT.md §7). +# for the nginx/certbot rollback (.deprecated/, DEPLOYMENT.md §7). DOMAIN= EMAIL= diff --git a/.gitignore b/.gitignore index 6702e7c..88dcdea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ icecast2/fallback_music/* .claude/ !icecast2/fallback_music/.gitkeep +# The retired certbot's data (code in .deprecated/certbot/), still on the +# host as the rollback certificate certbot/conf certbot/www # Caddy's certificates, keys and ACME account (docker-compose.yml) diff --git a/CLAUDE.md b/CLAUDE.md index 0f92a9c..3171c02 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -65,7 +65,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun **Uploads / Garage** (`garage/`): every stored file goes through one path. Frontend: `vue/src/uploads.js` (`uploadFile(file)` → URL, plus `ACCEPT` for pickers, `kindOf`, `isUploadUrl`, `tagFor`). Backend: `POST /api/uploads` (`handlers/handle_upload.go`), a thin wrapper over `services.Uploads.Save` (`services/uploads.go`), which owns the type table (`UploadTypes`), the 10MB limit, random naming and storage. A new feature that takes a file calls those, never its own endpoint. `GET /api/uploads` (admin only, `Uploads.List`, `listUploads()`) lists what is stored, bucket and disk merged, for `components/util/UploadPicker.vue`, the "choose an existing upload" modal used by the canvas's Background panel, Box editor and admin bar. Public files go to a bucket in a self-hosted Garage container (the `uploads` volume when `S3_ENDPOINT` is unset, or when Garage refuses a write). Caddy serves `/uploads/` from Garage's anonymous website endpoint first and the volume second, so the bucket is the source of truth and a Garage outage only affects bucket-only files. Private attachments (`/uploads/private/`) always stay on disk. `garage-webui` at `/garage/` (admin-gated) manages the bucket. First run on a fresh volume needs `garage/bootstrap.sh`; the full runbook is "Garage" in `DEPLOYMENT.md` §7. -**Caddy** (`caddy/`): the public edge since 2026-11-17 — TLS, the SPA and the reverse proxy in front of every service. It obtains and renews its own certificates (DNS-01 through the Cloudflare API, into `./caddy/data`), so there is no certbot. `caddy/Caddyfile` holds the global options and the shared snippets (`proxy`, `limit`, `admin_gate`, `permission_gate`, the upload headers, logging); `caddy/routes.caddy` is the one route table both modes use — add a new route there, in the right place, because inside its `route` block the first matching `handle` wins; `caddy/sites/prod.caddy` and `sites/dev.caddy` hold what differs (TLS, security headers, the apex, static caching, `/`), picked by `CADDY_SITE`. Every variable the config reads goes through the caddy service's explicit `environment:` list. The image build runs `caddy validate`, so `make check-caddy` (or a failed deploy build) catches a bad config before any container is replaced; the first build on a host compiles Caddy with its two plugins (rate limiting, the Cloudflare DNS provider) and is slow, later ones are cached. Rate limits (`import limit `) are sliding windows keyed on the real client IP, and a refused request gets 503; a zone name shared by several routes shares one bucket, so it must always carry the same numbers. Every request is also logged as a JSON line, body included (redacted if it mentions a password, token or secret), to `logs/caddy/payloads.log`. The `traffic` container tails that file so it shows up in Dozzle, which is served at `/dozzle/` behind the admin login; the admin panel no longer has a log view. Caddy has a healthcheck (`http://127.0.0.1/caddy-health`); the `autoheal` container restarts it when that fails, since Docker never restarts an unhealthy container itself. Gitea's commit-pinned history views and archives are admin-gated at the edge because a crawler swarm hammers them; the branch views stay public. `caddy/edge_test.sh` checks the privacy denials and every gate against a running edge. `nginx/` and `certbot/` are the pre-cutover edge, kept only as the rollback. +**Caddy** (`caddy/`): the public edge since 2026-11-17 — TLS, the SPA and the reverse proxy in front of every service. It obtains and renews its own certificates (DNS-01 through the Cloudflare API, into `./caddy/data`), so there is no certbot. `caddy/Caddyfile` holds the global options and the shared snippets (`proxy`, `limit`, `admin_gate`, `permission_gate`, the upload headers, logging); `caddy/routes.caddy` is the one route table both modes use — add a new route there, in the right place, because inside its `route` block the first matching `handle` wins; `caddy/sites/prod.caddy` and `sites/dev.caddy` hold what differs (TLS, security headers, the apex, static caching, `/`), picked by `CADDY_SITE`. Every variable the config reads goes through the caddy service's explicit `environment:` list. The image build runs `caddy validate`, so `make check-caddy` (or a failed deploy build) catches a bad config before any container is replaced; the first build on a host compiles Caddy with its two plugins (rate limiting, the Cloudflare DNS provider) and is slow, later ones are cached. Rate limits (`import limit `) are sliding windows keyed on the real client IP, and a refused request gets 503; a zone name shared by several routes shares one bucket, so it must always carry the same numbers. Every request is also logged as a JSON line, body included (redacted if it mentions a password, token or secret), to `logs/caddy/payloads.log`. The `traffic` container tails that file so it shows up in Dozzle, which is served at `/dozzle/` behind the admin login; the admin panel no longer has a log view. Caddy has a healthcheck (`http://127.0.0.1/caddy-health`); the `autoheal` container restarts it when that fails, since Docker never restarts an unhealthy container itself. Gitea's commit-pinned history views and archives are admin-gated at the edge because a crawler swarm hammers them; the branch views stay public. `caddy/edge_test.sh` checks the privacy denials and every gate against a running edge. The pre-cutover nginx and certbot configs are in `.deprecated/nginx/` and `.deprecated/certbot/`, kept for the rollback in `DEPLOYMENT.md` §7. ## Backend Structure diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index b038849..2e1e177 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -259,8 +259,9 @@ Encrypt allows five certificates for the same name a week, so do not make a habit of it. Until 2026-11-17 this was certbot plus a bootstrap nginx config, a reload -sentinel and a watcher loop. `certbot/` and its `./certbot/conf` stay on the -host as the rollback (§7); that certificate expires on 2027-01-20. +sentinel and a watcher loop, now in `.deprecated/`. The last certbot +certificate is still in `./certbot/conf` on the host as the rollback (§7); it +expires on 2027-01-20. ### Cloudflare Tunnel @@ -522,13 +523,15 @@ export "$(grep '^DOMAIN=' .env)" caddy/edge_test.sh https://www.$DOMAIN --resolve www.$DOMAIN:443:127.0.0.1 ``` -**Roll back to nginx** (until `nginx/` and `certbot/` are removed; the certbot -certificate in `./certbot/conf` is valid until 2027-01-20). `git revert` the -cutover commit and push, or by hand on the host, under the lock so a deploy -cannot interleave: +**Roll back to nginx** (possible while the certbot certificate in +`./certbot/conf` is valid, until 2027-01-20). The old edge is in +`.deprecated/nginx/` and `.deprecated/certbot/`. Revert the commit that moved +it there and then the cutover (`daa2a46`), which restores both directories +and nginx's compose services. Push, or apply it by hand on the host under the +lock so a deploy cannot interleave: ``` -git revert --no-edit +git revert --no-edit daa2a46 flock .compose.lock sh -c 'docker compose stop caddy && docker compose rm -f caddy && docker compose up -d --build nginx certbot cloudflared traffic' ``` @@ -707,11 +710,11 @@ docker compose restart caddy Documented, not fixed — each would change deploy behaviour. -1. **`nginx/`, `certbot/` and their host directories are still here** as the - rollback from the 2026-11-17 cutover. Once Caddy has run for a couple of - weeks: move `nginx/` and `certbot/` to `.deprecated/`, then delete - `./certbot/` and `./logs/nginx/` on the host and the `logs/nginx` logrotate - stanza. +1. **The old edge's host directories are still on stpvm** as the rollback + from the 2026-11-17 cutover: `./certbot/` (the last certbot certificate) + and `./logs/nginx/`, plus the `logs/nginx` stanza in + `/etc/logrotate.d/web_server`. The code is in `.deprecated/`. Once the + rollback is no longer wanted, delete the two directories and the stanza. 2. **`gitea/config/entrypoint.sh` is an empty, unused file** that would be mounted to the same in-container path as the real wrapper. It is currently shadowed by an explicit file mount — fragile. Deleting it would be safe but diff --git a/caddy/Caddyfile b/caddy/Caddyfile index 344bdf9..6c1f5ca 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -1,6 +1,7 @@ # ============================================================================= # Caddyfile — the public edge: TLS, the SPA, and the reverse proxy in front of -# every other service. Replaces nginx/ and the certbot container. +# every other service. Replaced nginx and certbot (now .deprecated/) on +# 2026-11-17. # # FILES (all baked into the image by caddy/Dockerfile) # Caddyfile this file: global options, the snippets every site @@ -29,7 +30,7 @@ # list in docker-compose.yml, or it reaches Caddy empty. Note an EMPTY # variable is not "unset": {$X:default} keeps the empty value. So defaults # live in that compose list (${X:-default}), which treats both alike, as -# nginx/entrypoint.sh's ${X:-default} did. +# nginx's entrypoint's ${X:-default} did. # # WHAT NO LONGER NEEDS DOING (vs nginx) # - Upstreams are resolved when Caddy dials them, not at startup, so it diff --git a/docker-compose.yml b/docker-compose.yml index 8d0a21f..b4a5422 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -114,8 +114,7 @@ services: # 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; - # nginx/ and certbot/ stay in the repo until that has settled, as the - # rollback. + # 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