Preview deployment: test a PR batch before it reaches deploy #60

Closed
opened 2026-11-05 16:46:32 +00:00 by maximus · 3 comments
Member

Today a PR batch can only be clicked through after it is merged into deploy and an image is built. Add a wanderer-preview environment so a branch or batch can be tested first.

  • Image build for an arbitrary ref: the existing image workflow dispatch with a ref input, tagged preview-<sha>.
  • homelab-flux: a wanderer-preview Deployment plus Service and ingress (tailnet-only, e.g. wanderer-preview.bearoverse.com), behind the same auth as wanderer.
  • Data: a copy of pb_data (a snapshot restored into its own PVC) and its own Meilisearch index. Never share the live DB, because migrations in a preview must not touch production. A refresh script re-copies on demand.
  • Scale it to 0 when idle, and document the "deploy branch X to preview" steps in a runbook.
  • Optional: CI comment on the PR with the preview link.

Motivation: the 2026-11-05 batch (#52–#59) could not be clicked through before merging, and the shared browser cannot reach internal hosts by design (the browser-session NetworkPolicy is internet-only).

🤖 Generated with Claude Code

Today a PR batch can only be clicked through after it is merged into `deploy` and an image is built. Add a **`wanderer-preview`** environment so a branch or batch can be tested first. - [ ] Image build for an arbitrary ref: the existing `image` workflow dispatch with a `ref` input, tagged `preview-<sha>`. - [ ] homelab-flux: a `wanderer-preview` Deployment plus Service and ingress (tailnet-only, e.g. wanderer-preview.bearoverse.com), behind the same auth as wanderer. - [ ] Data: a **copy** of pb_data (a snapshot restored into its own PVC) and its own Meilisearch index. Never share the live DB, because migrations in a preview must not touch production. A refresh script re-copies on demand. - [ ] Scale it to 0 when idle, and document the "deploy branch X to preview" steps in a runbook. - [ ] Optional: CI comment on the PR with the preview link. Motivation: the 2026-11-05 batch (#52–#59) could not be clicked through before merging, and the shared browser cannot reach internal hosts by design (the browser-session NetworkPolicy is internet-only). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

Design + prepared pieces (nothing live yet)

homelab-flux PR: jmz/homelab-flux#838 (needs Bear review): apps/wanderer-preview/ with web, db and search, all replicas: 0.

  • Data = a copy. wanderer-preview-pb-data (nfs-nas) holds a copy of live pb_data. The live PVC is never mounted, so migrations in a preview (#62) touch only the copy. Search is its own Meilisearch on an emptyDir and is rebuilt from the copy on every start.
  • Hosts: wanderer-preview.bearoverse.com + wanderer-preview-pb.bearoverse.com. They use websecure on the k3s Traefik, like live, so they are tailnet/LAN only. Login is the same as live (PocketBase password or Authentik OIDC), and /_/ and the _superusers API are denied the same way. Sign-up is off in the preview UI (PUBLIC_DISABLE_SIGNUP).
  • NetworkPolicies: live wanderer has none, so the preview gets an explicit allow-list. Preview pods can reach each other, DNS, Traefik (for OIDC and PUBLIC_POCKETBASE_URL), valhalla, brouter and trail-analyze-web. They have no internet egress, because the copied settings may hold SMTP credentials and federation from a copy would be wrong. They never reach wanderer-db or wanderer-search.
  • GitOps vs. on-demand: the Deployments carry kustomize.toolkit.fluxcd.io/ssa: IfNotPresent. Flux creates them once, then the script owns image and replicas. Without this, Flux would undo each up within 10 minutes.

Runbook / script: /root/wanderer-preview.sh. Every changing step asks for a typed yes.

wanderer-preview.sh --check                      # read-only preflight
wanderer-preview.sh build <ref>                  # image.yml for web, plus db if <ref>'s db/ differs from the live db code; waits, prints digests
wanderer-preview.sh refresh-data                 # copy live pb_data -> preview PVC, re-index
wanderer-preview.sh up <web-digest> [db-digest]  # set images, scale to 1, wait, smoke test (no db digest = the live db image)
wanderer-preview.sh down                         # scale to 0 (the idle state)
  • Snapshot without live downtime: refresh-data never opens the live SQLite DB and never stops wanderer-db. On the nas it takes btrfs subvolume snapshot -r /mnt/hdd0/@k3s, which is atomic, so data.db, its WAL and storage/ are captured at one instant (crash-consistent). It reflink-copies those files into the preview PVC and deletes the snapshot. Then, on the copy only, it runs a WAL checkpoint and integrity_check and rotates the token secrets of the auth collections, so preview tokens are not valid on live and live tokens are not valid on the preview.
  • Write guard: the script only scales and sets images on the three wanderer-preview-* Deployments. It fingerprints the live Deployments before and after each step and warns on any change.
  • Screenshots: /root/wanderer-shot.sh --host preview <path> uses the same strict allow-list, switched to the two preview hosts, with its own session cache.

Cost: 0 pods when idle. When up, requests are 115m CPU / 640Mi on prodesk, which moves memory requests from 82% to 84%; up refuses above 90%. The disk copy is a reflink (about 260 MB logical).

Open points / follow-ups:

  1. Building an arbitrary ref: image.yml only builds main*/deploy* branches. Those are push-protected, and a branch's Dockerfile RUN steps can read the registry token. So a batch has to be pushed to a protected name first (e.g. git push origin batch/2026-11-05:deploy-preview, done by jmz), which then builds as deploy-preview-<sha8>. To build any ref safely (the preview-<sha> tag this issue asks for), image.yml would need a two-phase build: kaniko --no-push --tar-path with no credentials in the workspace, then a separate trusted push step. That is a separate public/wanderer change.
  2. DNS for Bear: qotom net.nix rewrites (both names → .240), then the tailnet MagicDNS records (gen-tailnet-dns.py → homelab-flux sites/sospel/apps/headscale/config, → .28). Cloudflare needs nothing. Optional: add the Authentik redirect URI https://wanderer-preview.bearoverse.com/login/redirect for SSO on the preview. Until the DNS records exist, the script and the screenshot tool pin the preview names to the shared k3s Traefik address.
  3. Optional CI comment with the preview link: not done yet.

🤖 Generated with Claude Code

## Design + prepared pieces (nothing live yet) **homelab-flux PR: jmz/homelab-flux#838** (needs Bear review): `apps/wanderer-preview/` with web, db and search, all `replicas: 0`. - **Data = a copy.** `wanderer-preview-pb-data` (nfs-nas) holds a copy of live pb_data. The live PVC is never mounted, so migrations in a preview (#62) touch only the copy. Search is its own Meilisearch on an emptyDir and is rebuilt from the copy on every start. - **Hosts:** `wanderer-preview.bearoverse.com` + `wanderer-preview-pb.bearoverse.com`. They use websecure on the k3s Traefik, like live, so they are tailnet/LAN only. Login is the same as live (PocketBase password or Authentik OIDC), and `/_/` and the `_superusers` API are denied the same way. Sign-up is off in the preview UI (`PUBLIC_DISABLE_SIGNUP`). - **NetworkPolicies:** live wanderer has none, so the preview gets an explicit allow-list. Preview pods can reach each other, DNS, Traefik (for OIDC and PUBLIC_POCKETBASE_URL), valhalla, brouter and trail-analyze-web. They have **no internet egress**, because the copied settings may hold SMTP credentials and federation from a copy would be wrong. They never reach wanderer-db or wanderer-search. - **GitOps vs. on-demand:** the Deployments carry `kustomize.toolkit.fluxcd.io/ssa: IfNotPresent`. Flux creates them once, then the script owns image and replicas. Without this, Flux would undo each `up` within 10 minutes. **Runbook / script:** `/root/wanderer-preview.sh`. Every changing step asks for a typed `yes`. ``` wanderer-preview.sh --check # read-only preflight wanderer-preview.sh build <ref> # image.yml for web, plus db if <ref>'s db/ differs from the live db code; waits, prints digests wanderer-preview.sh refresh-data # copy live pb_data -> preview PVC, re-index wanderer-preview.sh up <web-digest> [db-digest] # set images, scale to 1, wait, smoke test (no db digest = the live db image) wanderer-preview.sh down # scale to 0 (the idle state) ``` - **Snapshot without live downtime:** `refresh-data` never opens the live SQLite DB and never stops wanderer-db. On the nas it takes `btrfs subvolume snapshot -r /mnt/hdd0/@k3s`, which is atomic, so data.db, its WAL and storage/ are captured at one instant (crash-consistent). It reflink-copies those files into the preview PVC and deletes the snapshot. Then, on the copy only, it runs a WAL checkpoint and `integrity_check` and **rotates the token secrets** of the auth collections, so preview tokens are not valid on live and live tokens are not valid on the preview. - **Write guard:** the script only scales and sets images on the three `wanderer-preview-*` Deployments. It fingerprints the live Deployments before and after each step and warns on any change. - **Screenshots:** `/root/wanderer-shot.sh --host preview <path>` uses the same strict allow-list, switched to the two preview hosts, with its own session cache. **Cost:** 0 pods when idle. When up, requests are 115m CPU / 640Mi on prodesk, which moves memory requests from 82% to 84%; `up` refuses above 90%. The disk copy is a reflink (about 260 MB logical). **Open points / follow-ups:** 1. **Building an arbitrary ref:** image.yml only builds `main*`/`deploy*` branches. Those are push-protected, and a branch's Dockerfile RUN steps can read the registry token. So a batch has to be pushed to a protected name first (e.g. `git push origin batch/2026-11-05:deploy-preview`, done by jmz), which then builds as `deploy-preview-<sha8>`. To build any ref safely (the `preview-<sha>` tag this issue asks for), image.yml would need a two-phase build: kaniko `--no-push --tar-path` with no credentials in the workspace, then a separate trusted push step. That is a separate public/wanderer change. 2. DNS for Bear: qotom `net.nix` rewrites (both names → .240), then the tailnet MagicDNS records (gen-tailnet-dns.py → homelab-flux `sites/sospel/apps/headscale/config`, → .28). Cloudflare needs nothing. Optional: add the Authentik redirect URI `https://wanderer-preview.bearoverse.com/login/redirect` for SSO on the preview. Until the DNS records exist, the script and the screenshot tool pin the preview names to the shared k3s Traefik address. 3. Optional CI comment with the preview link: not done yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

Design update after the security review (jmz/homelab-flux#838, commit ce8b336)

The preview runs unreviewed branch code. It therefore holds no live credentials and can reach no live service. Each point below replaces the corresponding part of the earlier comment.

  • Secrets: the preview uses its own random wanderer-preview-secrets, which wanderer-preview.sh refresh-data generates with every fresh copy. It is not in git, and the script can write only that one Secret name. No value of the live wanderer-secrets is used. The live encryption key isn't needed either, because the copy's settings row (encrypted with the live key, may hold SMTP) and the ActivityPub private keys are dropped.
  • No Traefik egress, no OIDC:
    • Through Traefik a pod could reach every live host by Host header, so no preview pod gets Traefik egress.
    • OIDC can't be narrowed to sso.bearoverse.com, so it is off: OAuth2 is disabled in the copy and the Authentik client secret is gone. The preview is password login only (claude_test).
    • Server-side rendering reaches the preview PocketBase through an in-pod TLS sidecar (private cert-manager CA) and then the wanderer-preview-db Service, never through Traefik.
  • trail-analyze-web is out: it has no auth of its own, so heatmap and pace analysis are unavailable in the preview.
  • Copy hardening: done in a staging directory before the preview db ever starts; the copy only replaces the old one if every assertion passes.
    • Every record of every auth collection, _superusers included, gets a new tokenKey, and every auth collection gets new token secrets.
    • _superusers is emptied.
    • users.createRule = null, so PocketBase itself refuses sign-up.
    • api_tokens, share-link tokens, OTPs and MFAs are deleted.
    • Assertions against a pre-hardening reference check that no token key or secret survived.
  • Checked at up:
    • claude_test's cached live token is rejected by the preview (401).
    • claude_test's password login works on the preview.
    • The resulting preview token is rejected by live wanderer-pb (401).
  • Authentik: step 5 of the DNS/auth list is dropped. The DNS steps are unchanged.
  • Cost: 120m CPU / 656Mi when up (82% → 85% of prodesk's memory requests); 0 pods when idle.

🤖 Generated with Claude Code

## Design update after the security review (jmz/homelab-flux#838, commit ce8b336) The preview runs **unreviewed** branch code. It therefore holds no live credentials and can reach no live service. Each point below replaces the corresponding part of the earlier comment. - **Secrets:** the preview uses its own random `wanderer-preview-secrets`, which `wanderer-preview.sh refresh-data` generates with every fresh copy. It is not in git, and the script can write only that one Secret name. No value of the live `wanderer-secrets` is used. The live encryption key isn't needed either, because the copy's settings row (encrypted with the live key, may hold SMTP) and the ActivityPub private keys are dropped. - **No Traefik egress, no OIDC:** - Through Traefik a pod could reach every live host by Host header, so no preview pod gets Traefik egress. - OIDC can't be narrowed to sso.bearoverse.com, so it is off: OAuth2 is disabled in the copy and the Authentik client secret is gone. The preview is **password login only** (claude_test). - Server-side rendering reaches the preview PocketBase through an in-pod TLS sidecar (private cert-manager CA) and then the `wanderer-preview-db` Service, never through Traefik. - **trail-analyze-web is out:** it has no auth of its own, so heatmap and pace analysis are unavailable in the preview. - **Copy hardening:** done in a staging directory before the preview db ever starts; the copy only replaces the old one if every assertion passes. - Every record of every auth collection, `_superusers` included, gets a new `tokenKey`, and every auth collection gets new token secrets. - `_superusers` is emptied. - `users.createRule = null`, so PocketBase itself refuses sign-up. - api_tokens, share-link tokens, OTPs and MFAs are deleted. - Assertions against a pre-hardening reference check that no token key or secret survived. - **Checked at `up`:** - claude_test's cached **live** token is rejected by the preview (401). - claude_test's password login works on the preview. - The resulting **preview** token is rejected by live wanderer-pb (401). - **Authentik:** step 5 of the DNS/auth list is dropped. The DNS steps are unchanged. - **Cost:** 120m CPU / 656Mi when up (82% → 85% of prodesk's memory requests); 0 pods when idle. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

First real run done 2026-11-06, the preview works end to end:

  • refresh-data (reworked for local-path pb_data, hf #919): an online sqlite3 .backup of live in a network-less pod on prodesk, then the copy is hardened (1103 trails, 2 users); live unchanged.
  • build deploy-preview (PR #77 head e5a57df8, web only; db = live image).
  • up: smoke all green; tokens are separate both ways; search re-indexed.
  • Acceptance t8 (loop-generator panels) on the preview: 14/14 PASS. #75 is fixed (8e finds own trails without the test workaround) and #76 too (8l: one candidate instead of two duplicates).

Flow for a PR: push its head to deploy-preview (jmz, protected) -> wanderer-preview.sh build deploy-preview -> up <digest> -> tests (WANDERER_TARGET=preview for the acceptance scripts, wanderer-shot.sh --host preview) -> down.

🤖 Generated with Claude Code

First real run done 2026-11-06, the preview works end to end: - `refresh-data` (reworked for local-path pb_data, hf #919): an online sqlite3 `.backup` of live in a network-less pod on prodesk, then the copy is hardened (1103 trails, 2 users); live unchanged. - `build deploy-preview` (PR #77 head e5a57df8, web only; db = live image). - `up`: smoke all green; tokens are separate both ways; search re-indexed. - Acceptance t8 (loop-generator panels) **on the preview: 14/14 PASS**. #75 is fixed (8e finds own trails without the test workaround) and #76 too (8l: one candidate instead of two duplicates). Flow for a PR: push its head to `deploy-preview` (jmz, protected) -> `wanderer-preview.sh build deploy-preview` -> `up <digest>` -> tests (`WANDERER_TARGET=preview` for the acceptance scripts, `wanderer-shot.sh --host preview`) -> `down`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer#60
No description provided.