nixos: Traefik and the CI runners as native services
Traefik keeps its role and its acme.json. Routes for the native services (Forgejo, Garage, the dashboard, the XMPP certificate) are written from Nix; the app containers keep declaring theirs as labels, which Traefik reads through Podman's socket as it did through Docker's. The asxpio runner uses the NixOS module and starts jobs through Podman; the interop runner is its own unit because it connects with a UUID and token instead of registering. Tried on the rehearsal pair: Forgejo and Garage through Traefik, a label-routed container, anonymous reads of the public bucket only, and a workflow with a nix-latest and an ubuntu-latest job. A restored Forgejo database still holds production's queued jobs, schedules and Actions secrets. The test runner tried to take a queued production job and was stopped only by the different secret key. migration/rehearsal-sanitize-forgejo.sh removes all of that and must run before a runner meets restored data. Assisted-by: Claude:fable-5-2
This commit is contained in:
parent
933b086bb1
commit
e95d97869f
2 changed files with 581 additions and 120 deletions
|
|
@ -40,6 +40,12 @@ install -d -m 700 /var/lib/garage
|
|||
mv "$src/var/lib/docker/volumes/storage_garage_meta/_data" /var/lib/garage/meta
|
||||
mv "$src/var/lib/docker/volumes/storage_garage_data/_data" /var/lib/garage/data
|
||||
|
||||
echo "== Traefik"
|
||||
install -d -o traefik -g traefik -m 700 /var/lib/traefik
|
||||
if [ -f "$src/opt/traefik/letsencrypt/acme.json" ]; then
|
||||
install -o traefik -g traefik -m 600 "$src/opt/traefik/letsencrypt/acme.json" /var/lib/traefik/acme.json
|
||||
fi
|
||||
|
||||
echo "== Starting"
|
||||
touch /var/lib/.data-in-place
|
||||
systemctl start postgresql.service
|
||||
|
|
@ -51,7 +57,7 @@ runuser -u postgres -- psql -q postgres < "$stage/pg_dumpall.sql" > /var/log/pg-
|
|||
echo "errors in /var/log/pg-restore.log: $(grep -c ERROR /var/log/pg-restore.log || true)"
|
||||
systemctl restart postgres-roles.service
|
||||
|
||||
systemctl start garage.service garage-bootstrap.service forgejo.service
|
||||
systemctl start garage.service garage-bootstrap.service forgejo.service traefik.service
|
||||
|
||||
echo "== Forgejo: hooks and SSH keys for the new paths"
|
||||
forgejo-admin regenerate hooks
|
||||
|
|
|
|||
33
nixos/migration/rehearsal-sanitize-forgejo.sh
Executable file
33
nixos/migration/rehearsal-sanitize-forgejo.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
# REHEARSAL HOSTS ONLY. Run after restoring production's Forgejo data and
|
||||
# before any runner is started against it.
|
||||
#
|
||||
# A restored database still has production's queued jobs, its schedules
|
||||
# and its Actions secrets (deploy keys, registry tokens). A runner would
|
||||
# pick the jobs up and deploy to production from the test server. This
|
||||
# cancels what is queued, removes the schedules and deletes every secret.
|
||||
set -euo pipefail
|
||||
|
||||
case "$(hostname)" in
|
||||
rehearsal-*) ;;
|
||||
*) echo "refusing: $(hostname) is not a rehearsal host" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
db=/var/lib/forgejo/data/forgejo.db
|
||||
systemctl stop forgejo.service
|
||||
sqlite3 "$db" <<'SQL'
|
||||
BEGIN;
|
||||
DELETE FROM secret;
|
||||
-- 3 = cancelled; 5 waiting, 6 running, 7 blocked
|
||||
UPDATE action_run_job SET status = 3 WHERE status IN (5, 6, 7);
|
||||
UPDATE action_run SET status = 3 WHERE status IN (5, 6, 7);
|
||||
UPDATE action_task SET status = 3 WHERE status IN (5, 6, 7);
|
||||
DELETE FROM action_schedule_spec;
|
||||
DELETE FROM action_schedule;
|
||||
DELETE FROM action_runner;
|
||||
DELETE FROM webhook;
|
||||
DELETE FROM push_mirror;
|
||||
COMMIT;
|
||||
SQL
|
||||
systemctl start forgejo.service
|
||||
echo "sanitized: no secrets, no queued jobs, no schedules, no runners, no webhooks"
|
||||
Loading…
Reference in a new issue