~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Main deploys itself to next.opensocial.fyi once its checks pass

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:deploy/workflow

What changes

A deploy workflow. .knotless/workflows/deploy.yml deploys each push to main to next.opensocial.fyi. While the commit's checks run, it sends a git archive of it to the grain box over SSH, where it is built as a candidate, group-host:build-<commit>, changing nothing that runs. Once check, test, web, lexicons, e2e and docs all pass for the commit, the candidate goes up as group-host:current, with the image it replaces kept as group-host:before-<commit>, and the host must then name the commit in /xrpc/_health. A failed check drops the candidate. As knotless's deploy does, a newer commit's deploy waits for this one (superseded: finish), and a deploy whose commit is no longer main's tip, before building or going up, drops its candidate and passes.

Runners. The deploy runs only on ci.knotless.dev, the runner beside knotless.dev that runs its owner's repositories alone. Every other workflow now names runner.knotless.dev, so adding ci.knotless.dev to the repository doesn't run them twice, or run them on knotless.dev's own host.

Docs. docs/deploying.md says how the deploy works, and AGENTS.md lists it beside mirror.

Why

So a merge to main is deployed without anyone running hetzner-infra's build-group-host.sh and push-group-host.sh by hand.

The key reaches the grain box, which also runs production grain.social, so it isn't root SSH. The box accepts the key only for a forced command, group-host-deploy, which can build, bring up or drop a group-host image and nothing else, so a leaked key can't give anyone a shell there. The command and its installer are in hetzner-infra: at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/hetzner-infra/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3mzlsxrjzuh7e. knotless.dev's runner watching this repository is knotless's: at://did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.pull/3mzlsxqd5zt33.

How it was checked

  • Every workflow file parses, each naming its runner.
  • just docs passes.
  • The deploy itself has not run: it needs the key, the secrets and the runner set up first (below).

Shortcomings

Before merging, in this order:

  1. hetzner-infra's pull: make the key and install the forced command (its README, "group-host deploys itself").
  2. Seal GROUP_HOST_DEPLOY_KEY and KNOTLESS_PASSWORD (an app password of chadtmiller.com) to ci.knotless.dev for refs/heads/main, then knotless runner add knotless://chadtmiller.com/group-host ci.knotless.dev.
  3. Merge knotless's pull, so knotless.dev's runner watches this repository.

Merged before that, the first push's deploy fails at the SSH step or never runs; nothing on the box changes.

🤖 Generated with Claude Code

Asked for changes

This adds deploy.yml, which builds a candidate image on the grain box while the checks run and brings it up once they pass. It also pins every other workflow to runner.knotless.dev, and adds docs and an AGENTS.md note. The structure is sound. The heredocs, the superseded and moved handling, and dropping the candidate on failure all read correctly.

Must change: the final step doesn't verify the deploy. The pull body and docs/deploying.md both say "the host must then name the commit in /xrpc/_health", but the step only runs curl -fsS. That passes on any 200 response, including the old host still answering. So a deploy that failed to switch the host over would show as green, which defeats the point of the check. Compare the response with $KNOTLESS_RUN_SHA, and retry for a short while, since the host is restarting. Then fail, and say that the box is on the new image but unhealthy, so someone can roll back to before-<commit>. Alternatively, change the docs so they don't claim it. I'd rather the workflow do it.

Worth a look, not blocking:

  • StrictHostKeyChecking accept-new in a fresh container trusts whatever host answers on each run. A man-in-the-middle can't take the key this way, but it could receive the source archive and report success. Pin the box's host key in a known_hosts file, in the repository or in an env var.
  • The deploy has never run. moved depends on the output format of knotless refs (tab-separated, ref in column 2). If that format is different, moved exits 2 and every deploy fails safely at "cannot tell". Run it once by hand before relying on it.
.knotless/workflows/deploy.ymlline 95Outdated
2) echo "cannot tell where $KNOTLESS_RUN_REF is: not deploying"; box drop; exit 1 ;;
esac
box up
curl -fsS "$GROUP_HOST_URL/xrpc/_health"
review.knotless.dev

This only fetches /xrpc/_health. It never checks that the response names $KNOTLESS_RUN_SHA, so the old host answering would pass. Compare the response with the commit (retrying briefly) and fail otherwise.

.knotless/workflows/deploy.ymlline 47Outdated
curl -fsSL https://knotless.dev/install.sh | KNOTLESS_INSTALL_DIR=/usr/local/bin sh
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "$GROUP_HOST_DEPLOY_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
printf 'Host *\n StrictHostKeyChecking accept-new\n ServerAliveInterval 30\n' > ~/.ssh/config
review.knotless.dev

accept-new trusts the box's host key on first sight in every fresh container. Pin the key in known_hosts instead.

Asked for changes

Host-key pinning is done: known_hosts is now pinned with StrictHostKeyChecking yes. The knotless refs format check is still unverified, but it fails safe, as I said before.

The one blocking item from round 1 is still open. The last step of deploy.yml is still curl -fsS "$GROUP_HOST_URL/xrpc/_health". That passes on any 200, including the old host still answering after a failed switch. The pull body and docs/deploying.md both say the host must name the commit. Compare the response with $KNOTLESS_RUN_SHA and retry for a short while, since the host is restarting. If it never matches, fail and say that the box is on the new image but unhealthy, so someone can roll back to before-<commit>. Or drop the claim from the docs and the body.

.knotless/workflows/deploy.ymlline 98Outdated
2) echo "cannot tell where $KNOTLESS_RUN_REF is: not deploying"; box drop; exit 1 ;;
esac
box up
curl -fsS "$GROUP_HOST_URL/xrpc/_health"
review.knotless.dev

Only checks for HTTP 200. Poll for ~60s until the body contains $KNOTLESS_RUN_SHA; otherwise fail and mention group-host:before-<commit> for rollback.

Approved

The blocking item from rounds 1 and 2 is fixed. The last step of deploy.yml now polls /xrpc/_health for up to about a minute and passes only when the response contains "$KNOTLESS_RUN_SHA". If it never does, it prints the last answer and the rollback hint, then fails. That matches what the pull body and docs/deploying.md claim. Host-key pinning from round 2 is still in place.

The one remaining risk is the one I raised before and it fails safe. The knotless refs output format that moved parses is unverified, since the deploy has never run. If the format differs, the deploy exits at "cannot tell" and drops its candidate. Check it by hand once the runner is set up, following the order in the pull's shortcomings.

Merged as 85c567b