# Deploys main to hud.place on each push, on the grain box, where HUD runs # as the compose project /etc/hud (hetzner-infra's services/hud). # # A pull lands on main only through the merge queue, whose batch runs every # check on the tree that lands, so this does not wait for main's own checks. # It couldn't: they are runner.knotless.dev's, which `after` does not see # from another runner, and a step can't read a private repository's checks. # # This run reaches the box with HUD_DEPLOY_KEY, a key the box takes only for # its forced command, hud-deploy (hetzner-infra's services/hud/hud-deploy.sh), # which can build HUD from an archive, bring a build up, or drop one, and # nothing else. The key is sealed to ci.knotless.dev, the runner that runs # only its owner's repositories, for pushes to main alone, so no other run # sees it. # # The commit is built on the box as hud:build-, beside what serves, # with the cargo cache the Dockerfile mounts. It then goes up: the running # image is kept as hud:before to roll back to, the candidate becomes # hud:current, and hud.place must answer /_health through the proxy. # Deploys run one at a time, in the order main moved (superseded: finish), # so none is cut off halfway and an older commit never goes up after a # newer one. on: push: refs: [refs/heads/main] superseded: finish runners: [ci.knotless.dev] image: alpine:3.22 secrets: [HUD_DEPLOY_KEY] env: # The grain box, which serves hud.place. HUD_BOX: root@167.233.237.163 HUD_URL: https://hud.place steps: - name: tools run: | apk add --no-cache curl git openssh-client >/dev/null # The box's forced command, given what to do and this commit. cat > /usr/local/bin/box <<'EOF' #!/bin/sh exec ssh -o ServerAliveInterval=30 "$HUD_BOX" "$1 $KNOTLESS_RUN_SHA" EOF chmod +x /usr/local/bin/box # The box's host key, as hetzner-infra's ci/known_hosts pins it. - uses: chadtmiller.com/steps/ssh-key@1 name: key with: {known-hosts: "167.233.237.163 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINaUk4YyxTjCsPg1XOsCIJiB1NlEakc9/tnS+QeYRRNQ"} secrets: {SSH_KEY: HUD_DEPLOY_KEY} - name: build # A build with a cold cargo cache compiles every dependency. timeout: 45 run: | git config --global --add safe.directory "$PWD" git archive --format=tar "$KNOTLESS_RUN_SHA" | box build - name: deploy run: | box up # As the network reaches it, through the proxy, which holds requests # for a moment while the container is replaced. for i in $(seq 30); do health=$(curl -fsS "$HUD_URL/_health" || true) [ "$health" != ok ] || { echo "$HUD_URL is up at $KNOTLESS_RUN_SHA"; exit 0; } sleep 2 done echo "$HUD_URL does not answer /_health: ${health:-no answer}" echo "the box runs hud:current at this commit, but it is not healthy;" echo "to roll back: docker tag hud:before hud:current, then docker compose up -d in /etc/hud" exit 1