From 223c8ae35aa74d4ef7933c11f546e3aefbacef70 Mon Sep 17 00:00:00 2001 From: Adam French Date: Thu, 26 Nov 2026 14:32:33 +0000 Subject: [PATCH] Move Garage and garage-webui to stpcore Garage now runs on the stpcore LXC (adamf/stpcore), the shared core other stacks depend on. caddy, backend and usaco pin the name `garage` to it with GARAGE_UPSTREAM; /garage/ goes to stpcore's Caddy with X-Core-Token. The disk fallback for /uploads/ is unchanged. Co-Authored-By: Claude Opus 5.5 --- .env.dev | 15 ++-- .env.example | 50 ++++++------- .gitea/workflows/renovate.yaml | 2 +- CLAUDE.md | 4 +- DEPLOYMENT.md | 75 ++++++++++--------- backend/main.go | 2 +- caddy/Caddyfile | 4 + caddy/routes.caddy | 27 ++++--- docker-compose.yml | 55 ++------------ garage/bootstrap.sh | 72 ------------------ garage/garage.toml | 29 ------- .../architecture/diagrams/edge/RouteMap.vue | 6 +- .../diagrams/infra/HostOverview.vue | 4 +- 13 files changed, 108 insertions(+), 237 deletions(-) delete mode 100755 garage/bootstrap.sh delete mode 100644 garage/garage.toml diff --git a/.env.dev b/.env.dev index 3da67e2..b7ccdc9 100644 --- a/.env.dev +++ b/.env.dev @@ -16,7 +16,7 @@ # # Keep it in step with .env.example: a new variable goes in both. Settings that # are not secrets (hosts, ports, timezone) keep .env.example's defaults; values -# a service parses (Garage's hex secrets, the S3 key id) are dummies in the exact shape it requires, or that service won't start. +# a service parses (the S3 key id and secret) are dummies in the exact shape it requires, or that service won't start. # # The dummy Postgres credentials only work on a database volume created with # them: an existing dbdata volume keeps whatever password it was initialised @@ -124,17 +124,16 @@ TRACKER_TZ=Europe/London TFL_APP_KEY=dev-dummy-tfl-key -# --- Garage object store (public /uploads/) ----------------------------------- -# Shapes Garage enforces: 64 hex for the RPC secret, "GK" + 24 hex for the key -# id, 64 hex for the secret. Uploads fall back to the `uploads` volume until -# garage/bootstrap.sh has imported this key and created the bucket. -GARAGE_RPC_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef -GARAGE_ADMIN_TOKEN=dev-garage-admin-token +# --- Garage object store (public /uploads/, on stpcore) ----------------------- +# Uploads fall back to the `uploads` volume unless a dev stpcore is running +# with LAN_BIND=172.17.0.1 and these same dummy values (see stpcore's README). +# Shapes Garage enforces: "GK" + 24 hex for the key id, 64 hex for the secret. +GARAGE_UPSTREAM=host-gateway +GARAGE_WEBUI_TOKEN=dev-garage-webui-token S3_ACCESS_KEY_ID=GK0123456789abcdef01234567 S3_SECRET_ACCESS_KEY=fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210 S3_ENDPOINT=http://garage:3900 S3_REGION=garage S3_BUCKET=uploads -GARAGE_CAPACITY=1G STPPRIV_LAN_IP=192.0.2.1 diff --git a/.env.example b/.env.example index 1e03505..009b139 100644 --- a/.env.example +++ b/.env.example @@ -197,13 +197,12 @@ USACO_CLAUDE_MONTHLY_BUDGET= # Claude cannot take audio, so this OpenAI key transcribes it (whisper-1, # about $0.006 a minute). Blank turns reviews off. USACO_OPENAI_API_KEY= -# Optional: keep the recordings for playback in a PRIVATE Garage bucket, -# never `uploads` (that one is served publicly at /uploads/). Its own key, -# same shapes as S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY above. With the -# key blank the recordings are thrown away once transcribed. One-off setup: -# docker compose exec -T garage /garage bucket create usaco-audio -# docker compose exec -T garage /garage key import -n usaco-site --yes "$USACO_S3_ACCESS_KEY_ID" "$USACO_S3_SECRET_ACCESS_KEY" -# docker compose exec -T garage /garage bucket allow --read --write usaco-audio --key "$USACO_S3_ACCESS_KEY_ID" +# Optional: keep the recordings for playback in a PRIVATE Garage bucket +# (`usaco-audio` on stpcore), never `uploads` (that one is served publicly at +# /uploads/). Its own key, same shapes as S3_ACCESS_KEY_ID / +# S3_SECRET_ACCESS_KEY below. With the key blank the recordings are thrown +# away once transcribed. Put the same pair in stpcore's .env and run its +# garage/bootstrap.sh, which creates the bucket and imports the key. USACO_S3_ACCESS_KEY_ID= USACO_S3_SECRET_ACCESS_KEY= @@ -242,30 +241,29 @@ STPPRIV_LAN_IP= # TfL Unified API key (500 req/min); used by the Python hotel finder TFL_APP_KEY= -# --- Garage object store (public /uploads/) ----------------------------------- -# See garage/garage.toml and DEPLOYMENT.md ("Garage"). Everything here is -# optional for the site to run: with S3_ENDPOINT blank the backend keeps -# writing uploads to the `uploads` volume exactly as before. +# --- Garage object store (public /uploads/, on stpcore) ----------------------- +# Garage runs on the stpcore LXC (adamf/stpcore); its README is the runbook +# and its .env holds Garage's own secrets. Everything here is optional for +# the site to run: with S3_ENDPOINT blank, or stpcore down, the backend +# writes uploads to the `uploads` volume and Caddy serves them from there. # -# Garage's own secrets, passed to the garage and garage-webui containers. -# Generate each with `openssl rand -hex 32`. The RPC secret must never change -# once the node has data; the admin token unlocks garage-webui's whole API. -GARAGE_RPC_SECRET= -GARAGE_ADMIN_TOKEN= -# The backend's S3 access, imported into Garage by garage/bootstrap.sh. -# Garage only accepts this shape: +# stpcore's LAN IP: the name `garage` is pinned to it in caddy, backend and +# usaco. `host-gateway` in dev. Blank means 127.0.0.1, which fails fast. +GARAGE_UPSTREAM= +# Shared secret Caddy adds as X-Core-Token on /garage/, after the admin +# gate; the same value as GARAGE_WEBUI_TOKEN in stpcore's .env. +# `openssl rand -hex 32`. Changing it needs `docker compose up -d caddy`. +GARAGE_WEBUI_TOKEN= +# The backend's S3 key, the same values as in stpcore's .env (whose +# bootstrap.sh imports it). Garage only accepts this shape: # S3_ACCESS_KEY_ID "GK" + 24 hex (echo GK$(openssl rand -hex 12)) # S3_SECRET_ACCESS_KEY 64 hex (openssl rand -hex 32) S3_ACCESS_KEY_ID= S3_SECRET_ACCESS_KEY= -# Blank keeps uploads on disk. Set to http://garage:3900 (after running -# garage/bootstrap.sh) to store new public uploads in the bucket; recreate the -# backend after changing it. If a write to Garage fails the backend logs it and -# writes to disk instead, and Caddy serves the file from there. +# Blank keeps uploads on disk. http://garage:3900 stores new public uploads +# in the bucket; recreate the backend after changing it. If a write to Garage +# fails the backend logs it and writes to disk instead. S3_ENDPOINT= -# Optional; these defaults match garage.toml and bootstrap.sh. +# Optional; these defaults match stpcore's garage.toml and bootstrap.sh. S3_REGION=garage S3_BUCKET=uploads -# Optional, bootstrap.sh only: the node's capacity in the layout. With one node -# it only has to be non-zero; it is not a quota. Default 20G. -GARAGE_CAPACITY= diff --git a/.gitea/workflows/renovate.yaml b/.gitea/workflows/renovate.yaml index 55402db..da3a859 100644 --- a/.gitea/workflows/renovate.yaml +++ b/.gitea/workflows/renovate.yaml @@ -30,7 +30,7 @@ jobs: -e RENOVATE_PLATFORM=gitea \ -e RENOVATE_ENDPOINT=http://git.adam-french.co.uk:3000/api/v1 \ -e RENOVATE_GIT_URL=endpoint \ - -e RENOVATE_REPOSITORIES=adamf/stpweb,adamf/stpgit,adamf/stppriv \ + -e RENOVATE_REPOSITORIES=adamf/stpweb,adamf/stpgit,adamf/stppriv,adamf/stpcore \ -e RENOVATE_TOKEN \ -e GITHUB_COM_TOKEN \ -e LOG_LEVEL=info \ diff --git a/CLAUDE.md b/CLAUDE.md index 16fe64b..7f37f8e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,7 +19,7 @@ cp .env.dev .env docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build ``` -`.env.dev` is committed and every value in it is a dummy: local-only passwords, fake third-party keys, `DOMAIN=localhost`, background jobs that touch real accounts switched off. It has to be copied to `.env` because several services read `env_file: ./.env` directly. Never put a real credential in it. Dev mode seeds the database with test data (`SEED_DB=true`) and serves the site on both http and https (a certificate from Caddy's local CA), with no redirects or security headers. Visit `http://localhost`. +`.env.dev` is committed and every value in it is a dummy: local-only passwords, fake third-party keys, `DOMAIN=localhost`, background jobs that touch real accounts switched off. It has to be copied to `.env` because several services read `env_file: ./.env` directly. Never put a real credential in it. Dev mode seeds the database with test data (`SEED_DB=true`) and serves the site on both http and https (a certificate from Caddy's local CA), with no redirects or security headers. Visit `http://localhost`. Uploads stay on disk unless a dev stpcore is also running (from that repo, with `LAN_BIND=172.17.0.1` and the same dummy keys as `.env.dev`), which `GARAGE_UPSTREAM=host-gateway` reaches. ### Full stack (production, HTTPS) @@ -65,7 +65,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun **Gitea** (own repo, `adamf/stpgit`): git, Actions and the image registry (`/adamf/...`) run in their own Proxmox LXC since 2026-11-24, from the `adamf/stpgit` repo (this repo's `gitea/` directory until then) with their own Postgres (`gitea-db`) and `.env`, deployed by hand there and never by CI. Everything on stpvm reaches it as `GITEA_HOST` (`git.`, :3000 HTTP and :2222 SSH), pinned to the LXC's LAN IP (`GITEA_UPSTREAM`) by `extra_hosts` in containers and `/etc/hosts` on the host; public DNS for that name is Cloudflare, which carries only HTTPS. There is no Gitea container or forwarder in this stack since 2026-11-24. The act_runner stays on stpvm. Runbook: that repo's README, summarised in "Gitea LXC" in `DEPLOYMENT.md` §7. -**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. +**Uploads / Garage** (Garage itself on stpcore): 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 Garage (the `uploads` volume when `S3_ENDPOINT` is unset, or when Garage refuses a write). Garage and `garage-webui` are not in this stack: they run on the `stpcore` LXC, from the `adamf/stpcore` repo (the shared core other stacks depend on; its README is the runbook, including `garage/bootstrap.sh`), and the name `garage` is pinned to its LAN IP (`GARAGE_UPSTREAM`) by `extra_hosts` in `caddy`, `backend` and `usaco`. Caddy serves `/uploads/` from Garage's anonymous website endpoint (`garage:3902`) first and the volume second, so the bucket is the source of truth and a Garage or stpcore outage only affects bucket-only files. Private attachments (`/uploads/private/`) always stay on disk. `/garage/` (admin-gated) proxies to stpcore's Caddy on `garage:3909`, adding `X-Core-Token` (`GARAGE_WEBUI_TOKEN`), which that Caddy requires before it forwards to garage-webui. A new consumer of the store gets its own key and bucket on stpcore and the same `extra_hosts` pin. "Garage" in `DEPLOYMENT.md` §7 covers this side. **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 is not proxied any more: it lives at `git.` (its own tunnel, from the stpgit repo) and `/gitea/*` 301s there; only the registry at the apex's `/v2/` still goes through Caddy. `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. diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index b381153..71bc117 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -76,6 +76,26 @@ forwarder here published 3000/2222 and everything used `localhost`.) A new machine or container that talks to Gitea needs the same pin, or a `~/.ssh/config` entry pointing the name at the tailnet name `stpgit` for SSH. +### Garage runs on stpcore + +Garage (the S3 object store behind `/uploads/`) and garage-webui are not in +this stack either. They run on the `stpcore` LXC, from `adamf/stpcore`, the +shared core every other stack depends on; its README is the runbook. The name +`garage` is pinned to that LXC's LAN IP (`GARAGE_UPSTREAM`) by `extra_hosts` +in `caddy`, `backend` and `usaco`, so the configs still say `garage:3900` +(S3), `garage:3902` (website) and `garage:3909` (stpcore's Caddy in front of +garage-webui, which wants the `X-Core-Token` this Caddy adds after the admin +gate). Nothing here depends on it being up: see "Garage" in §7. + +``` + stpvm (pin: garage -> stpcore LAN IP) stpcore LXC (LAN IP) + backend S3 PUT (uploads) ------+ +----------------------+ + usaco S3 (usaco-audio) ------+--> garage:3900 ---> | garage :3900 S3 | + caddy /uploads/ -----------------> garage:3902 --> | :3902 web | + caddy /garage/ (+X-Core-Token) --> garage:3909 --> | caddy -> garage-webui| + +----------------------+ +``` + Gitea's public address is `https://git./` (its `ROOT_URL`), served by the LXC's own Cloudflare tunnel, not by this edge; Caddy only 301s the old `/gitea/*` URLs there and still proxies the registry at the apex's `/v2/`. @@ -101,8 +121,8 @@ Deploys of this stack never touch Gitea. | Partner Radar (adamf/cto, its own compose project) | `radar-web` (alias of that project's `web`, on app-network) | 80 | `radar.`, the whole host (its own login, no gate; zones `radar` and `radar_login`). Started from the cto checkout with `make stpvm`; 503 "offline" when that stack is down | no | | traffic (tails the payload log) | `traffic` | — (no network) | none; its stdout is what Dozzle shows | no | | autoheal (restarts unhealthy caddy) | `autoheal` | — (no network) | none; reads the Docker socket | no | -| garage (S3 object store) | `garage` | 3900 S3, 3902 web, 3903 admin | none directly; `/uploads/` falls back to its web endpoint for files not on the volume | no | -| garage-webui (Garage admin UI) | `garage-webui` | 3909 | `/garage/` (admin-gated by Caddy `forward_auth`) | no | +| garage (S3 object store, adamf/stpcore) | — (runs on the **stpcore** LXC; `garage` pinned to `GARAGE_UPSTREAM`) | 3900 S3, 3902 web | `/uploads/` from its website endpoint first, then the `uploads` volume; backend and usaco use S3 | no | +| garage-webui (Garage admin UI, adamf/stpcore) | — (on **stpcore**, behind its Caddy) | 3909 on stpcore | `/garage/` (admin-gated by Caddy `forward_auth`; Caddy adds `X-Core-Token`). 503 "offline" when stpcore is down | no | Container names come from `.env`, and Caddy builds its upstreams from the same variables (passed through the caddy service's `environment:` list). **Renaming @@ -407,8 +427,6 @@ Setup, once: | ---------- | ----------------------------------------------------- | -------------------------------------------------- | | `dbdata` | Postgres: the app database and the trackers' databases | All posts, users and messages, and the trackers' data | | `uploads` | Uploads from before Garage, private attachments, and any upload Garage refused | Those files | -| `garage_meta` | Garage's metadata: buckets, keys, object index, layout | Everything in the bucket (the bytes in `garage_data` are unreadable without it) | -| `garage_data` | The bucket's object bytes | Every upload stored in Garage | | `vue_dist` | The built SPA | Nothing — rebuilt on next deploy | | `caddy_config` | Caddy's autosaved JSON config | Nothing — rewritten on every start | @@ -621,43 +639,35 @@ The app schema is recreated by GORM auto-migration on backend start (there are n migration files). The job and activity trackers' databases are not auto-created; their READMEs have the commands. -**Garage (the `/uploads/` bucket).** Public uploads live in a Garage bucket, -with the `uploads` volume as a safety net. Nothing breaks while Garage is down -or not set up: +**Garage (the `/uploads/` bucket).** Public uploads live in a Garage bucket +on the stpcore LXC (`adamf/stpcore`, whose README is the runbook: setup, +keys, the move from this host, backups), with the `uploads` volume here as a +safety net. Nothing breaks while stpcore is down or not set up: - the backend writes to disk until `S3_ENDPOINT` is set, and falls back to - disk (with a log line) whenever Garage refuses a write; + disk (with a log line) whenever Garage refuses a write or can't be reached; - Caddy serves `/uploads/` from Garage and falls back to the volume when - Garage has no such file or is unreachable, and it starts without the - `garage` container. + Garage has no such file or is unreachable (2s connect timeout); +- `/garage/` answers 503 "offline". -Turning it on: - -1. Fill in `GARAGE_RPC_SECRET`, `GARAGE_ADMIN_TOKEN`, `S3_ACCESS_KEY_ID` and - `S3_SECRET_ACCESS_KEY` in `.env` **before** the deploy that adds the - containers (otherwise `garage` crash-loops on a blank secret until they - are set; nothing else is affected). `.env.example` says how to generate - each. -2. Deploy, then `garage/bootstrap.sh` (idempotent; it creates the layout, the - `uploads` bucket and the backend's key, and opens the bucket to the - website endpoint). -3. Set `S3_ENDPOINT=http://garage:3900` and `docker compose up -d backend`. - The backend logs `[upload] storing uploads in bucket uploads ...` on start. -4. Check: upload something through a canvas page or chat, then - `docker compose exec garage /garage bucket info uploads` shows the object - count going up, and the returned `/uploads/...` URL loads. +Pointing this stack at it: set `GARAGE_UPSTREAM` (stpcore's LAN IP), +`GARAGE_WEBUI_TOKEN` (same as stpcore's), `S3_ACCESS_KEY_ID` / +`S3_SECRET_ACCESS_KEY` (same as stpcore's, imported by its +`garage/bootstrap.sh`) and `S3_ENDPOINT=http://garage:3900`, then +`docker compose up -d caddy backend usaco`. The backend logs +`[upload] storing uploads in bucket uploads ...` on start. Moving the old files in (so they show in garage-webui, and so the bucket holds everything): ``` -export $(grep -E '^S3_(ACCESS_KEY_ID|SECRET_ACCESS_KEY)=' .env) -docker run --rm --network web_server_app-network \ +export $(grep -E '^(S3_ACCESS_KEY_ID|S3_SECRET_ACCESS_KEY|GARAGE_UPSTREAM)=' .env) +docker run --rm \ -v web_server_uploads:/data:ro \ -e AWS_ACCESS_KEY_ID="$S3_ACCESS_KEY_ID" -e AWS_SECRET_ACCESS_KEY="$S3_SECRET_ACCESS_KEY" \ -e AWS_DEFAULT_REGION=garage \ amazon/aws-cli:2.38.0 s3 sync /data s3://uploads --exclude 'private/*' \ - --endpoint-url http://garage:3900 + --endpoint-url "http://$GARAGE_UPSTREAM:3900" ``` The copies left on the volume are then only a fallback for when Garage is @@ -666,19 +676,14 @@ served from its disk copy, if it has one. Once the bucket has been trusted for a while, remove everything but `private/` from the volume. **Rollback:** blank `S3_ENDPOINT` and `docker compose up -d backend`. Files -written to the bucket in the meantime stay reachable as long as `garage` runs; +written to the bucket in the meantime stay reachable as long as stpcore runs; to drop Garage entirely, first copy them back (`aws s3 sync s3://uploads /data` with the volume mounted read-write). **Managing files:** garage-webui at `/garage/` (site admin login). Files uploaded there are public at `/uploads/` and skip the backend's type checks; keep them under a prefix such as `media/`. Uploads through it are -capped at 2 GB by Caddy. - -**Backups:** Garage here is one node on the same disk — it is not a backup. -Back up `garage_meta` and `garage_data` together (meta without data, or the -reverse, is useless); Garage also snapshots its metadata every 6h inside -`garage_meta`. +capped at 2 GB by Caddy, here and on stpcore. **Gitea LXC.** Gitea runs in its own Proxmox LXC (§1), from a checkout of its own repo, `adamf/stpgit` (until 2026-11-24 this repo's `gitea/` directory), diff --git a/backend/main.go b/backend/main.go index 36eb978..cbe0f34 100644 --- a/backend/main.go +++ b/backend/main.go @@ -96,7 +96,7 @@ func main() { } pythonURL := fmt.Sprintf("http://%s:%s", pythonHost, pythonPort) - // Defaults match garage/garage.toml and garage/bootstrap.sh. + // Defaults match stpcore's garage/garage.toml and garage/bootstrap.sh. s3Region := os.Getenv("S3_REGION") if s3Region == "" { s3Region = "garage" diff --git a/caddy/Caddyfile b/caddy/Caddyfile index 7651bbb..a830a59 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -159,6 +159,10 @@ handle @radar_offline { respond "Partner Radar is offline." 503 } + @garage_offline vars garage_upstream yes + handle @garage_offline { + respond "The Garage admin UI (stpcore) is offline." 503 + } } } diff --git a/caddy/routes.caddy b/caddy/routes.caddy index d948a28..7460233 100644 --- a/caddy/routes.caddy +++ b/caddy/routes.caddy @@ -124,14 +124,23 @@ handle /dozzle/* { } } -# Holds Garage's admin token. 2 GB for video uploads. +# garage-webui on stpcore, behind its Caddy, which wants X-Core-Token (header_up +# replaces any client-sent one). Holds Garage's admin token. 2 GB for video +# uploads. A `route` so garage_upstream is set only after the gate passes. handle /garage/* { - import admin_gate - request_body { - max_size 2GB - } - reverse_proxy garage-webui:3909 { - import proxy + route { + import admin_gate + request_body { + max_size 2GB + } + vars garage_upstream yes + reverse_proxy garage:3909 { + import proxy + header_up X-Core-Token {env.GARAGE_WEBUI_TOKEN} + transport http { + dial_timeout 3s + } + } } } @@ -269,8 +278,8 @@ handle /uploads/private/* { file_server } -# Garage first, disk second: a 404, 5xx or dial error falls back to the -# volume, so the bucket is the source of truth. +# Garage (on stpcore) first, disk second: a 404, 5xx or dial error falls back +# to the volume, so the bucket is the source of truth. handle /uploads/* { import upload_headers vars uploads_fallback yes diff --git a/docker-compose.yml b/docker-compose.yml index 017060d..8b31e3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,12 +23,8 @@ volumes: # Deleting this wipes posts, users and messages. dbdata: # Private attachments, plus any upload Garage refused. Caddy serves - # /uploads/ from the bucket first, then from here. + # /uploads/ from the bucket (on stpcore) first, then from here. uploads: - # Back up meta and data together: the bytes are unreadable without meta. - # A fresh pair needs garage/bootstrap.sh. - garage_meta: - garage_data: # Written by the one-shot `vue` build container, served by Caddy. vue_dist: # Named only so the image's VOLUME doesn't leave anonymous volumes behind. @@ -73,12 +69,15 @@ services: - RECEIPT_WEB_UPSTREAM=${RECEIPT_WEB_UPSTREAM:-127.0.0.1:9} - STPPRIV_LAN_IP=${STPPRIV_LAN_IP:-192.0.2.1} - RECEIPT_WEB_TOKEN=${RECEIPT_WEB_TOKEN:-} + - GARAGE_WEBUI_TOKEN=${GARAGE_WEBUI_TOKEN:-} # The adamf/cto stack's web container; "offline" while that stack is down. - RADAR_UPSTREAM=${RADAR_UPSTREAM:-radar-web:80} - CLOUDFLARE_DNS_API_TOKEN=${CLOUDFLARE_DNS_API_TOKEN:-} # Keeps the Gitea hop on the LAN; public DNS points at Cloudflare. + # `garage` is on stpcore; the 127.0.0.1 default fails fast to disk. extra_hosts: - "${GITEA_HOST}:${GITEA_UPSTREAM}" + - "garage:${GARAGE_UPSTREAM:-127.0.0.1}" networks: app-network: # So cloudflared's origin (https://www.DOMAIN) lands here under a name @@ -141,6 +140,7 @@ services: condition: service_healthy extra_hosts: - "${GITEA_HOST}:${GITEA_UPSTREAM}" + - "garage:${GARAGE_UPSTREAM:-127.0.0.1}" networks: - app-network env_file: @@ -286,6 +286,7 @@ services: - usaco-runner extra_hosts: - "${GITEA_HOST}:${GITEA_UPSTREAM}" + - "garage:${GARAGE_UPSTREAM:-127.0.0.1}" networks: - app-network - usaco-runner-net @@ -378,47 +379,3 @@ services: - AUTOHEAL_CONTAINER_LABEL=autoheal volumes: - /var/run/docker.sock:/var/run/docker.sock - - # Public uploads bucket. Nothing depends on it: Caddy and the backend fall - # back to the `uploads` volume. First run: garage/bootstrap.sh. - 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-gated at /garage/; holds the admin token, so never publish it. - # Files uploaded here are public at /uploads/ with no backend checks. - 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 - # No /tmp in the image; large multipart uploads spool there. - tmpfs: - - /tmp - volumes: - - ./garage/garage.toml:/etc/garage.toml:ro diff --git a/garage/bootstrap.sh b/garage/bootstrap.sh deleted file mode 100755 index 2723dc8..0000000 --- a/garage/bootstrap.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# One-time, idempotent setup of a fresh garage_meta volume, run on the host -# (the image has no shell): node layout, bucket, the backend's key imported -# from .env (so a wiped volume keeps the same credentials), and website access. -# Optional: S3_BUCKET, GARAGE_CAPACITY, COMPOSE (to add the dev override). -set -eu - -COMPOSE=${COMPOSE:-docker compose} - -# .env isn't guaranteed to be valid shell, so it isn't sourced. -envval() { - eval "current=\${$1:-}" - if [ -n "$current" ]; then - printf '%s' "$current" - return - fi - [ -f .env ] || return 0 - grep -E "^$1=" .env | tail -n 1 | cut -d= -f2- | sed -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'$/\1/" -} - -garage() { - $COMPOSE exec -T garage /garage "$@" -} - -KEY_ID=$(envval S3_ACCESS_KEY_ID) -SECRET=$(envval S3_SECRET_ACCESS_KEY) -BUCKET=$(envval S3_BUCKET) -BUCKET=${BUCKET:-uploads} -CAPACITY=$(envval GARAGE_CAPACITY) -CAPACITY=${CAPACITY:-20G} -KEY_NAME=site-backend - -# Garage rejects other shapes at import time with a less helpful message. -if ! printf '%s' "$KEY_ID" | grep -Eq '^GK[0-9a-f]{24}$'; then - echo "S3_ACCESS_KEY_ID must be GK followed by 24 hex chars (try: echo GK\$(openssl rand -hex 12))" >&2 - exit 1 -fi -if ! printf '%s' "$SECRET" | grep -Eq '^[0-9a-f]{64}$'; then - echo "S3_SECRET_ACCESS_KEY must be 64 hex chars (try: openssl rand -hex 32)" >&2 - exit 1 -fi - -# 1. Layout. `node id -q` prints "@"; the id is what -# `layout assign` takes. -if garage layout show 2>/dev/null | grep -q "No nodes currently have a role"; then - NODE_ID=$(garage node id -q 2>/dev/null | cut -d@ -f1) - echo "Assigning node $(printf '%s' "$NODE_ID" | cut -c1-16) (capacity $CAPACITY)" - garage layout assign -z dc1 -c "$CAPACITY" "$NODE_ID" - garage layout apply --version 1 -else - echo "Layout already applied" -fi - -# 2. Bucket. -if garage bucket info "$BUCKET" >/dev/null 2>&1; then - echo "Bucket $BUCKET exists" -else - garage bucket create "$BUCKET" -fi - -# 3. Key. -if garage key info "$KEY_ID" >/dev/null 2>&1; then - echo "Key $KEY_ID exists" -else - garage key import -n "$KEY_NAME" --yes "$KEY_ID" "$SECRET" -fi - -# 4 and 5 are idempotent in Garage itself. -garage bucket allow --read --write "$BUCKET" --key "$KEY_ID" -garage bucket website --allow "$BUCKET" - -echo "Garage ready: bucket $BUCKET, key $KEY_ID" diff --git a/garage/garage.toml b/garage/garage.toml deleted file mode 100644 index 662964c..0000000 --- a/garage/garage.toml +++ /dev/null @@ -1,29 +0,0 @@ -# Single node, replication_factor 1: back the volumes up like any other. -# No secrets here; they come from GARAGE_RPC_SECRET / GARAGE_ADMIN_TOKEN. -# 0.0.0.0 because bridge networks may lack IPv6. Ports: 3900 S3, 3901 RPC, -# 3902 website (bucket chosen by Host ""), 3903 admin. -metadata_dir = "/var/lib/garage/meta" -data_dir = "/var/lib/garage/data" -db_engine = "lmdb" -# LMDB can be left unreadable by a crash mid-write; a periodic snapshot of -# the metadata is what `garage meta` restores from. -metadata_auto_snapshot_interval = "6h" - -replication_factor = 1 - -rpc_bind_addr = "0.0.0.0:3901" -rpc_public_addr = "127.0.0.1:3901" - -[s3_api] -api_bind_addr = "0.0.0.0:3900" -# Any string works; it only has to match what clients sign with (S3_REGION). -s3_region = "garage" -root_domain = ".s3.garage" - -[s3_web] -bind_addr = "0.0.0.0:3902" -root_domain = ".web.garage" -index = "index.html" - -[admin] -api_bind_addr = "0.0.0.0:3903" diff --git a/vue/src/views/architecture/diagrams/edge/RouteMap.vue b/vue/src/views/architecture/diagrams/edge/RouteMap.vue index bf429b9..d02c6f8 100644 --- a/vue/src/views/architecture/diagrams/edge/RouteMap.vue +++ b/vue/src/views/architecture/diagrams/edge/RouteMap.vue @@ -158,15 +158,15 @@ - garage-webui:3909 - bucket admin + garage:3909 + stpcore · bucket admin /garage/ prefix kept · body up to 2G · unbuffered garage:3902 - S3 website endpoint + stpcore · S3 website /uploads/ strip · Host uploads.web.garage · 2s connect diff --git a/vue/src/views/architecture/diagrams/infra/HostOverview.vue b/vue/src/views/architecture/diagrams/infra/HostOverview.vue index 10ea827..4a903ea 100644 --- a/vue/src/views/architecture/diagrams/infra/HostOverview.vue +++ b/vue/src/views/architecture/diagrams/infra/HostOverview.vue @@ -162,7 +162,7 @@ GARAGE-WEBUI - :3909 + :3909 · on the stpcore LXC /garage/ @@ -211,7 +211,7 @@ GARAGE - S3 object store + S3 · on the stpcore LXC :3900 S3 API :3903 admin API :3902 website