Adds BROUTER_URL=http://10.0.1.10:17777 (vSwitch) to SOPS so the Planner starts routing through the dedicated host's Caddy sidecar instead of the in-tree flagship BRouter. Flagship BRouter stays warm for the 48h soak/rollback window. Pre-flight from the flagship confirmed the new host answers 200 with the auth header and 403 without. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 KiB
14 KiB
1. Pre-flight (operator)
- 1.1 Confirm Hetzner vSwitch is provisioned between the flagship cx23 and the dedicated host; record both vSwitch IPs
- vSwitch #80672 (VLAN 4000, 1 TB), flagship 10.0.0.2 on
enp7s0, dedicated 10.0.1.10 onenp4s0.4000(MTU 1400), Cloud Network 10.0.0.0/16 with cloud subnet 10.0.0.0/24 + vSwitch subnet 10.0.1.0/24 (Terraform) - Dedicated host VLAN persistence:
/etc/netplan/60-trails-vswitch.yamlon Ubuntu 22.04; verified surviving a reboot (VLAN reachable 64 s after reboot, 0% packet loss steady-state) - Flagship side auto-configured by Hetzner cloud-init on attach (no manual OS config)
- vSwitch #80672 (VLAN 4000, 1 TB), flagship 10.0.0.2 on
- 1.2 Confirm the dedicated host's firewall allows inbound TCP from the flagship vSwitch IP to the planned BRouter service port, and blocks that port from the public interface
- UFW active with
INPUTdefault-DROP. Allow rule:17777/tcp on enp4s0.4000 from 10.0.0.2. Public interface is blocked by default-deny (17777 not in the public allowlist: 2232/SSH, 80, 443).
- UFW active with
- 1.3 Confirm the
trailsuser exists on the dedicated host, is in thedockergroup, and can rundocker pswithout sudo- uid 1002, groups include 114(docker);
sudo -iu trails docker psreturns container list (host runs many other self-hosted services, all user-owned)
- uid 1002, groups include 114(docker);
- 1.4 Generate an SSH keypair for the deploy workflow (
BROUTER_DEPLOY_SSH_KEY) and install the public key in~trails/.ssh/authorized_keys- ed25519 keypair at
~/.ssh/trails-brouter-deploy{,.pub}on operator laptop; public key installed at/home/trails/.ssh/authorized_keysonullrich.is(perms 0600/0700, owner trails:trails) - Verified:
ssh -i ~/.ssh/trails-brouter-deploy -p 2232 trails@ullrich.is 'docker ps'succeeds with no password prompt - Note: SSH on
ullrich.islistens on port 2232, not 22. The CD workflow must use-p 2232. AddBROUTER_DEPLOY_SSH_PORT=2232as a GitHub Actions secret (or hard-code it in the workflow step). - Before merging: add the contents of
~/.ssh/trails-brouter-deployas GitHub Actions secretBROUTER_DEPLOY_SSH_KEY; then consider whether to keep or delete the local copy.
- ed25519 keypair at
- 1.5 Verify the dedicated host's Docker daemon version supports the compose file features used in
infrastructure/docker-compose.yml- Docker Engine 29.1.5 (API 1.52), Compose v5.0.1, storage driver overlay2 — all modern
- Gotcha: default
LoggingDriver=lokion this host (routes to user's personal Loki). Our BRouter compose must overridelogging:per service so our logs go to trails.cool's Loki (flagship) instead. See 6.3 for the two viable approaches: (a) direct Loki driver withloki-url: http://10.0.0.2:3100/loki/api/v1/push, or (b) json-file + our own Promtail sidecar.
2. Secrets and config
- 2.1 Generate a 32-byte random
BROUTER_AUTH_TOKENopenssl rand -base64 32; active token lives only in SOPS and the operator's clipboard history. Rotate by regenerating and re-running 2.3.
2.2 Addobsoleted — after relocation,BROUTER_AUTH_TOKENtoinfrastructure/secrets.infra.env(SOPS)cd-infrano longer deploys BRouter and therefore doesn't need the token.cd-brouterreads it fromsecrets.app.envinstead (see 5.1). Single source of truth.- 2.3 Add
BROUTER_AUTH_TOKENtoinfrastructure/secrets.app.env(SOPS) for the Planner- Token added via
sops -d | append | sops -e; round-trip decrypt confirms. Committed in this branch.
- Token added via
- 2.4 Add GitHub Actions secrets:
BROUTER_DEPLOY_HOST,BROUTER_DEPLOY_SSH_KEY,BROUTER_DEPLOY_SSH_PORT- Set via
gh secret setfrom operator laptop:BROUTER_DEPLOY_HOST=ullrich.is,BROUTER_DEPLOY_SSH_PORT=2232,BROUTER_DEPLOY_SSH_KEYfrom~/.ssh/trails-brouter-deploy.
- Set via
- 2.5 Document the rotation runbook in
docs/deployment.md(or equivalent)docs/deployment.md§Secrets rotation covers theBROUTER_AUTH_TOKENgenerate/edit/deploy/overlap flow and the macOSSOPS_AGE_KEY_FILEgotcha. Added as part of 8.3.
3. BRouter host compose project
- 3.1 Create
infrastructure/brouter-host/docker-compose.ymlwith servicesbrouter(bound only to the internal Docker network) andcaddy(published on the vSwitch IP, auth-enforcing)- Compose has explicit
logging: driver: json-fileon each service to bypass the dedicated host's defaultlokilogging driver. Caddy binds to10.0.1.10:17777; brouter has no published port.
- Compose has explicit
- 3.2 Create
infrastructure/brouter-host/Caddyfilethat requiresX-BRouter-Authequal to the configured token and forwards matching requests tobrouter:17777; redact the header from access logs- Header matcher + 403 fallback;
auto_https offsince vSwitch-only. Caddy default access log format does not include request headers, so token is not logged.
- Header matcher + 403 fallback;
- 3.3 Set
JAVA_OPTS=-Xmx8g(or equivalent BRouter env) on thebrouterservice- Also patched
docker/brouter/Dockerfileto honorJAVA_OPTS(was hardcoded-Xmx1024Min CMD). Default env keeps flagship behavior unchanged.
- Also patched
- 3.4 Create
infrastructure/brouter-host/download-segments.shthat fetches the planet RD5 tile list idempotently into./segments/- Crawls brouter.de directory listing, uses
wget -Nfor Last-Modified-based incremental updates, prints heartbeat every 25 tiles.
- Crawls brouter.de directory listing, uses
- 3.5 Add a README in
infrastructure/brouter-host/with one-shot provisioning notes (git clone, first segment download, first compose up)- Covers bring-up, segment refresh, token rotation, rollback. Paired with the CD workflow which handles routine updates.
4. Planner changes
- 4.1 Add
BROUTER_AUTH_TOKENenv var toapps/planner/app/lib/brouter.ts; sendX-BRouter-Authon every fetchauthHeaders()helper reads env at call time (testable); attached to bothcomputeRouteandcomputeSegmentGpxfetch sites.
- 4.2 Fail the Planner startup with a clear error when
NODE_ENV=productionandBROUTER_AUTH_TOKENis unset- Module-level throw at import. Prod container fails fast; dev/test unaffected.
- 4.3 Update
infrastructure/docker-compose.ymlPlanner service env to passBROUTER_AUTH_TOKENthrough from the SOPS env file- Also made
BROUTER_URLoverridable so cutover is a single SOPS edit away.
- Also made
- 4.4 Add a unit test covering the header-attachment path in
apps/planner/app/lib/brouter.ts- 3 new tests: token set → header attached, token unset → header omitted, covers both
computeRouteandcomputeSegmentGpx.
- 3 new tests: token set → header attached, token unset → header omitted, covers both
5. CD workflow
- 5.1 Rewrite
.github/workflows/cd-brouter.ymldeploy job: SSH astrails@${{ secrets.BROUTER_DEPLOY_HOST }},cd ~trails/brouter,docker compose pull && docker compose up -d- SSH on port
BROUTER_DEPLOY_SSH_PORT(2232), dedicated keyBROUTER_DEPLOY_SSH_KEY.
- SSH on port
- 5.2 Update workflow
paths:trigger to includeinfrastructure/brouter-host/** - 5.3 Move the segment-download logic out of the workflow into the on-host
download-segments.sh; workflow calls it but tolerates a long-running invocation (or skips on subsequent deploys if segments already present)- Workflow does NOT call
download-segments.sh— first-time seed is a manual operator step (per README and task 7.1); routine re-runs are cron-able on the dedicated host.
- Workflow does NOT call
- 5.4 Keep the Grafana annotation step, pointing at the flagship Grafana over its existing path
- Still uses
DEPLOY_HOST+DEPLOY_SSH_KEYto reach the flagship for the annotation.
- Still uses
- 5.5 Remove the
brouter:service frominfrastructure/docker-compose.ymlon the flagship (deferred to cutover step 7.5)
6. Observability
- 6.1 Add a Prometheus scrape job in
infrastructure/prometheus/prometheus.ymltargeting the BRouter host's cAdvisor (or JMX exporter) on the vSwitch IP; label withhost="brouter"- Job
brouter-cadvisor→10.0.1.10:8080. Uses static_configs with a statichost="brouter"label so dashboards can filter.
- Job
- 6.2 Run cAdvisor on the dedicated host as part of
infrastructure/brouter-host/docker-compose.yml, configured to report only BRouter-labeled containers--whitelisted_container_labels=trails.cool.service+--docker_only=truescope metrics to trails containers only. Bound to10.0.1.10:8080(vSwitch-only).
- 6.3 Add a Promtail (or Alloy) service to
infrastructure/brouter-host/docker-compose.ymltailing Docker logs for BRouter + Caddy sidecar only, pushing to the flagship Loki over vSwitch- Promtail with docker_sd + relabel-drop on missing
trails.cool.servicelabel; ships tohttp://10.0.0.2:3100/loki/api/v1/push. Also published Loki on flagship's vSwitch IP so the dedicated host can reach it. - Requires operator one-time:
ufw allow in on enp4s0.4000 from 10.0.0.2 to any port 8080 proto tcp(documented in brouter-host/README.md).
- Promtail with docker_sd + relabel-drop on missing
- 6.4 Add a Grafana dashboard row (or new dashboard) for BRouter host: request rate, p50/p95/p99, JVM heap, container memory, scrape up/down
- New
infrastructure/grafana/dashboards/brouter.jsonwith scrape up/down, request rate + latency (from Planner-side metrics), container memory/CPU, and a Loki logs panel filtered tohost="brouter".
- New
- 6.5 Add an alert:
up{job="brouter"} == 0 for 2m- Added as
brouter-scrape-downininfrastructure/grafana/provisioning/alerting/alerts.yml. NoData state set to Alerting so a complete scrape outage still fires.
- Added as
7. Cutover
- 7.1 Deploy
infrastructure/brouter-host/to the dedicated host manually the first time; rundownload-segments.sh(expect multi-hour runtime)- Planet RD5 set (1139 tiles, 9.2 GB) seeded at
~trails/brouter/segments/onullrich.is. Multi-hour was overestimated — took ~1 min. Planet compressed is only ~10 GB now. - All 4 containers up on dedicated host:
trails-brouter(BRouter 1.7.9),trails-brouter-caddy,trails-brouter-cadvisor,trails-brouter-promtail. Promtail will retry-loop until flagship publishes Loki on10.0.0.2:3100(lands with PR #292 merge). - Hit three issues during first deploy:
cd-broutermissingdocker login(GHCR image is private), custom healthcheck usedwgetnot in the image, and BRouter 1.7.8 was one lookups.dat version behind current planet segments. All three fixed in a follow-up commit on #292.
- Planet RD5 set (1139 tiles, 9.2 GB) seeded at
- 7.2 Verify the new BRouter responds to a curl from the flagship host over vSwitch with the auth header, and returns 403 without it
- Confirmed end-to-end from
trails.cool:curl -H 'X-BRouter-Auth: …' http://10.0.1.10:17777/brouter?...→ 200 with GPX body (1.75 km route, 4m41s). Without the header → 403 from Caddy, BRouter never sees the request.
- Confirmed end-to-end from
- 7.3 Deploy the Planner with
BROUTER_AUTH_TOKENset butBROUTER_URLstill pointing at the flagship BRouter (no-op change; validates wiring)- cd-apps deployed post-#291 merge with
BROUTER_AUTH_TOKENin env. Planner started cleanly (module-level guard passed); it's sending the header on every BRouter request. Flagship BRouter ignores the header as expected./healthreturns 200, logs show normal traffic.
- cd-apps deployed post-#291 merge with
- 7.4 Flip
BROUTER_URLin SOPS to the new vSwitch URL; deploy Planner; monitorbrouter_request_duration_secondserror rate for 30 minutes- Pre-flight from flagship over vSwitch confirmed: 200 + GPX with
X-BRouter-Auth, 403 without.BROUTER_URL=http://10.0.1.10:17777added toinfrastructure/secrets.app.envin this PR. Monitoring runbook indocs/deployment.md§Cutover.
- Pre-flight from flagship over vSwitch confirmed: 200 + GPX with
- 7.5 After 48 hours of clean metrics: remove the
brouterservice +./segmentsvolume frominfrastructure/docker-compose.yml; runcd-infra.ymlto restart without BRouter;docker image pruneon the flagship - 7.6 Document rollback path (revert
BROUTER_URLflip, redeploy Planner, old container warm for 48h) in the PR description- Rollback procedure in the cutover PR body; canonical version in
docs/deployment.md§Cutover step 5.
- Rollback procedure in the cutover PR body; canonical version in
8. Documentation
- 8.1 Update
CLAUDE.mdto mention the second deployment target and thetrails-user deploy pattern for BRouter- Deployment table now lists SSH target per workflow; new Hosts section explains the flagship + dedicated split and the vSwitch bridge.
- 8.2 Update
docs/architecture.mdwith the new topology and vSwitch boundary- Hosting section rewritten to describe both hosts, the vSwitch, and the observability-scoping for the shared dedicated host.
- 8.3 Update
docs/deployment.md(or create) with the BRouter host runbook: first-time provisioning, segment updates, token rotation, rollback- New file. Covers host layout, first-time provisioning, SOPS rotation (including the macOS SOPS_AGE_KEY_FILE gotcha), the full cutover procedure with rollback, and
gh workflow run cd-brouter.yml.
- New file. Covers host layout, first-time provisioning, SOPS rotation (including the macOS SOPS_AGE_KEY_FILE gotcha), the full cutover procedure with rollback, and
- 8.4 Add a note to
infrastructure/README.md(if present) distinguishing flagship-host vs. BRouter-host compose projects- No
infrastructure/README.mdcurrently exists; theinfrastructure/brouter-host/README.mdadded in 3.5 + the updateddocs/deployment.mdcover the ground. Skip.
- No
9. Verification
- 9.1
pnpm typecheck && pnpm lint && pnpm testpass with the new env handling and unit test- Clean run on main @
6bae26d(12/12 turbo tasks green).
- Clean run on main @
- 9.2
pnpm test:e2epasses with the Planner hitting the relocated BRouter (or a mocked upstream that enforces the auth header)- All 9 BRouter integration tests pass locally against the dev BRouter with the Planner sending
X-BRouter-Auth. 4 unrelated macOS-local flakes (passkey/WebAuthn + public-content redirect timing) are green in CI onmain@6bae26d.
- All 9 BRouter integration tests pass locally against the dev BRouter with the Planner sending
- 9.3 A manual smoke test from Grafana confirms BRouter metrics and logs appear under the
brouterhost label after cutover - 9.4
openspec archive relocate-brouter-to-dedicated-hostruns cleanly after cutover + documentation are merged