Environments stop being machines. Until now each box WAS an environment --
"beta" named both a deploy target and a host, "the desktop" named both the
operator's computer and the dev server -- so every path could assume one
environment per host and hardcode /opt/thermograph, /etc/thermograph.env and
ports 8137/8080. That assumption ends here:
vps1 75.119.132.91 Forgejo, Grafana/Loki, the portfolio site, and DEV
(own Postgres, mesh-only on 10.10.0.2:8137)
vps2 169.58.46.181 PROD and BETA as two Swarm stacks sharing one
TimescaleDB instance, plus Centralis, Postfix, backups
desktop AI model hosting + flex Swarm capacity, no environment
Nothing live has moved; the ordered cutover is in
infra/deploy/RUNBOOK-vps1-vps2-cutover.md.
deploy/env-topology.sh is the single source of truth: env -> host, checkout,
branch, deploy mode, stack name, env file, LB ports, DB role/database, service
prefix. THERMOGRAPH_ENV is the input, and on vps2 it is the only thing
distinguishing a beta deploy from a prod one -- deploy.sh refuses to run when it
disagrees with the checkout it was invoked from. The host-wide secrets-env and
deploy-mode markers survive only as a fallback for a single-environment box.
Beta gets its own stack file rather than an overlay (a merge cannot REMOVE the
db service, and beta having no database of its own is the point). Its services
are prefixed beta-*: Swarm registers a service's short name as a DNS alias on
every network it joins, so two stacks both calling a service `web` on the shared
data network would let prod's frontend resolve a beta task. Prod's stack, env
and LB config are untouched.
One Postgres, two databases with two roles: deploy/db/provision-env-db.sh
creates thermograph_beta (NOSUPERUSER, owns only its own database, CONNECT
revoked from PUBLIC) plus a <role>_ro for ad-hoc queries, and refuses to run for
the environment that owns the instance -- doing so would demote prod's bootstrap
superuser.
Fixes that co-residency would otherwise have broken silently:
- CI secrets are keyed by host (VPS1_SSH_*, VPS2_SSH_*). SSH_* meant "beta" and
also "the Forgejo box" because those shared a machine; that conflation is what
once had the prod backup dumping beta.
- The nightly backup dumps BOTH application databases to separate off-box
prefixes, and fails loudly on a missing one instead of skipping it.
- Alloy stopped deriving the `host` label from the node -- on vps2 that would
have filed every beta line as prod, feeding prod's alert rules with beta's
traffic. It is now derived per source, with a new `node` label for the machine,
and beta's log volume is mounted via a vps2-only overlay.
- ops/dbq.sh, ops/iceberg.sh and the secrets seed scripts derived their SSH
target and env-file path from the topology instead of hardcoding beta to
75.119.132.91 -- which is vps1's address now.
- Dev's overlay binds DEV_BIND_ADDR (loopback by default, the mesh address on
vps1) instead of 0.0.0.0: correct for a home LAN box, a public exposure of
unreviewed branches on a VPS.
Terraform's hosts variable is keyed by machine with a nested environments map,
and main.tf flattens (host, environment) pairs so two environments on one box
cannot share a checkout. Caddy's single reference config is split per host.
Docs, onboarding and the runbooks are updated throughout, including the security
rationales that co-residency makes false: separate SSH credentials no longer put
a host boundary between beta and prod, and the boundary that remains is the
database and the filesystem.
4.4 KiB
Off-box backups → Contabo Object Storage
Durable, encrypted, off-box copies of the state that would otherwise die with a
single VPS. Driven by .forgejo/workflows/ops-cron.yml (03:00 UTC daily +
workflow_dispatch).
What is backed up
Prefix in bucket era5-thermograph |
Source | Job | Host / secrets | Retention off-box |
|---|---|---|---|---|
backups/db/prod/ |
prod's thermograph database (pg_dump --format=custom) |
backup |
vps2, VPS2_SSH_* |
30 days |
backups/db/beta/ |
beta's thermograph_beta database, same shared instance |
backup |
vps2, VPS2_SSH_* |
30 days |
backups/forgejo/db/ |
Forgejo Postgres (forgejo_db) |
forgejo-backup |
vps1, VPS1_SSH_* |
30 days |
backups/forgejo/data/ |
Forgejo data volume (repos/LFS/config) | forgejo-backup |
vps1, VPS1_SSH_* |
30 days |
Both application databases live on the ONE shared TimescaleDB instance on
vps2 now (separate roles/databases, not separate boxes) — the backup job
dumps each by name so beta isn't silently left uncovered. Forgejo moved to
vps1 with the vps1/vps2 rename (it used to be co-located with beta on the
box now called vps2's predecessor); its backup targets vps1 accordingly. See
ops-cron.yml's own header comment for the history: an earlier revision keyed
these secrets by environment name rather than host, which is what let "the
prod backup" silently dump the wrong box for a while.
Everything is streamed through age encryption before upload — encrypted to the
vault recipient age1xx4dz…, so the private key each host already has at
/etc/thermograph/age.key (and the operator's ~/.config/sops/age/keys.txt)
decrypts it. Nothing plaintext leaves the box.
Access layer
- S3 endpoint/bucket/keys are Forgejo Actions secrets (
S3_ENDPOINT,S3_BUCKET,S3_ACCESS_KEY,S3_SECRET_KEY) — the CI job's credential home (also mirrored into the SOPS vaultdeploy/secrets/{prod,beta}.yamlfor host-side use). Contabo needs path-style addressing (force_path_style=true,provider=Other,region=default). rclone+agemust be installed on vps1 and vps2 (one-time:apt-get install -y rclone age). The prod/beta job on vps2 apt-installs them if missing; check whether the Forgejo-backup job's user on vps1 has the sudo to do the same, or whether they need pre-installing there.
Restore (DR runbook)
Prereq on the restoring host: rclone + age + the age key at
/etc/thermograph/age.key (or the operator key), and rclone configured for the
archive: remote (env vars RCLONE_CONFIG_ARCHIVE_* or /etc/rclone/rclone.conf).
Prod / beta database
Both restore into the SAME shared instance on vps2 (<db-container> is that
one instance's container/task, resolved the same way dbq.sh does) — only
the bucket prefix and the target database/role differ:
# list available encrypted dumps
rclone ls archive:era5-thermograph/backups/db/prod/
rclone ls archive:era5-thermograph/backups/db/beta/
# download newest, decrypt, restore into a fresh db
OBJ=archive:era5-thermograph/backups/db/prod/<name>.dump.age
rclone cat "$OBJ" | sudo age -d -i /etc/thermograph/age.key \
| docker exec -i <db-container> pg_restore -U thermograph -d thermograph --clean --if-exists
# beta: same instance, its own role/database
OBJ=archive:era5-thermograph/backups/db/beta/<name>.dump.age
rclone cat "$OBJ" | sudo age -d -i /etc/thermograph/age.key \
| docker exec -i <db-container> pg_restore -U thermograph -d thermograph_beta --clean --if-exists
Forgejo (restore on vps1)
# database
rclone cat archive:era5-thermograph/backups/forgejo/db/<name>.dump.age \
| sudo age -d -i /etc/thermograph/age.key \
| docker exec -i forgejo_db sh -c 'PGPASSWORD=$POSTGRES_PASSWORD pg_restore -U $POSTGRES_USER -d $POSTGRES_DB --clean --if-exists'
# data volume (repos/lfs/config) — restore into the volume with Forgejo stopped
rclone cat archive:era5-thermograph/backups/forgejo/data/<name>.tar.age \
| sudo age -d -i /etc/thermograph/age.key \
| docker run --rm -i -v forgejo_forgejo_data:/data busybox tar -C /data -xf -
Verify a backup is restorable (quick)
rclone cat archive:era5-thermograph/backups/db/prod/<name>.dump.age \
| sudo age -d -i /etc/thermograph/age.key | head -c 5 # -> PGDMP = valid custom-format dump
Manual run
workflow_dispatch the "Ops cron (backup + IndexNow)" workflow, or run the same
age | rclone rcat pipeline by hand (see the workflow script).