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

The deploy goes up on each push, main gated by the merge queue

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:deploy/queue-gated
.knotless/workflows/deploy.yml+15−54
@@ -1,4 +1,10 @@
# Deploys main to next.opensocial.fyi once this commit's checks all pass.
# Deploys main to next.opensocial.fyi on each push.
#
# Main takes pulls only through the merge queue, which lands a pull once
# its batch, the commit that lands, passes every check; so what reaches
# main has passed, and this does not wait for main's own checks. It
# couldn't: a step can't read a private repository's checks (knotless
# issue at://did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzlv5ic46umh).
#
# The host runs on the grain box as the compose project /etc/group-host
# (hetzner-infra's stacks/opensocial). This run reaches it with
@@ -9,41 +15,29 @@
# ci.knotless.dev, the runner that runs only its owner's repositories, for
# pushes to main alone, so no other run sees it.
#
# The image is built first, while the checks run, as a candidate,
# group-host:build-<commit>, which changes nothing that runs. Once every
# check passes it goes up: the running image is kept as
# group-host:before-<commit> to roll back to, and the host must then name
# this commit in /xrpc/_health. A check that fails drops the candidate.
#
# A newer commit's deploy waits for this one (superseded: finish), so a
# deploy is never cut off halfway. Before the build and again before going
# up, this one asks where main is: once main has moved past it, it drops
# its candidate and passes, leaving the deploy to the newer one.
#
# group-host is private, so reading main and its checks signs in as the
# owner, KNOTLESS_IDENTIFIER, with KNOTLESS_PASSWORD, an app password of
# theirs, granted as the key is.
# The commit is built on the box as group-host:build-<commit>, then goes
# up: the running image is kept as group-host:before-<commit> to roll back
# to, and the host must name this commit in /xrpc/_health, on the box and
# then as the network reaches it. 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: [GROUP_HOST_DEPLOY_KEY, KNOTLESS_PASSWORD]
secrets: [GROUP_HOST_DEPLOY_KEY]
env:
# The grain box, which serves next.opensocial.fyi, and its host key, as
# hetzner-infra's ci/known_hosts pins it.
GROUP_HOST_BOX: root@opensocial.fyi
GRAIN_HOST_KEY: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINaUk4YyxTjCsPg1XOsCIJiB1NlEakc9/tnS+QeYRRNQ
GROUP_HOST_URL: https://next.opensocial.fyi
KNOTLESS_IDENTIFIER: chadtmiller.com
# The checks that must pass, each this repository's workflow of that name.
CHECKS: check test web lexicons e2e docs
steps:
- name: tools
run: |
apk add --no-cache curl git openssh-client >/dev/null
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
echo "opensocial.fyi $GRAIN_HOST_KEY" > ~/.ssh/known_hosts
@@ -53,47 +47,14 @@ steps:
#!/bin/sh
exec ssh "$GROUP_HOST_BOX" "$1 $KNOTLESS_RUN_SHA"
EOF
# Whether main has moved past this commit: 0 if it has, 1 if not, 2
# if it cannot tell.
cat > /usr/local/bin/moved <<'EOF'
#!/bin/sh
tip=$(knotless refs "knotless://$KNOTLESS_RUN_REPO" | awk -F '\t' -v ref="$KNOTLESS_RUN_REF" '$2 == ref { print $1 }')
[ -n "$tip" ] || exit 2
[ "$tip" != "$KNOTLESS_RUN_SHA" ] || exit 1
echo "$KNOTLESS_RUN_REF is at $tip now, not $KNOTLESS_RUN_SHA: the newer commit deploys"
EOF
chmod +x /usr/local/bin/box /usr/local/bin/moved
chmod +x /usr/local/bin/box
- name: build
run: |
moved && { touch ~/.moved; exit 0; } || true
git config --global --add safe.directory "$PWD"
git archive --format=tar "$KNOTLESS_RUN_SHA" | box build
timeout: 30
- name: checks
run: |
[ ! -e ~/.moved ] || exit 0
end=$(($(date +%s) + 1500))
for wf in $CHECKS; do
left=$((end - $(date +%s)))
[ "$left" -gt 0 ] || left=1
out=$(knotless checks "knotless://$KNOTLESS_RUN_REPO" --ref "$KNOTLESS_RUN_REF" \
--commit "$KNOTLESS_RUN_SHA" --workflow "$wf" --wait "$left") || true
echo "$out"
case "$out" in
success*) ;;
*) echo "$wf has not passed: not deploying"; box drop; exit 1 ;;
esac
done
timeout: 30
- name: deploy
run: |
[ ! -e ~/.moved ] || exit 0
at=0
moved || at=$?
case $at in
0) box drop; exit 0 ;;
2) echo "cannot tell where $KNOTLESS_RUN_REF is: not deploying"; box drop; exit 1 ;;
esac
box up
# As the network reaches it, through the proxy: the host names this
# commit within a minute, as it restarts, or the deploy fails.
docs/deploying.md+3−3
@@ -143,11 +143,11 @@ On SIGTERM the host answers the requests already under way, within its 30-second
## Deploying on each merge
The host at next.opensocial.fyi deploys itself: `.knotless/workflows/deploy.yml` runs on each push to `main`. It sends a `git archive` of the commit to the machine over SSH, which builds it as a candidate image, `group-host:build-<commit>`, while the commit's checks run. Nothing that runs changes until then. Once `check`, `test`, `web`, `lexicons`, `e2e` and `docs` have all passed for the commit, the candidate becomes `group-host:current`, the image it replaces is kept as `group-host:before-<commit>`, and compose brings the host and the console up from the compose file at that commit, as the upgrade above does. The deploy then checks that `/xrpc/_health` names the commit. A check that fails throws the candidate away.
The host at next.opensocial.fyi deploys itself: `.knotless/workflows/deploy.yml` runs on each push to `main`. `main` takes pulls only through the merge queue, which lands a pull once its batch, the commit that reaches `main`, has passed `check`, `test`, `web`, `lexicons`, `e2e` and `docs`, so the deploy does not wait for `main`'s own checks. It sends a `git archive` of the commit to the machine over SSH, which builds it as `group-host:build-<commit>`. That image then becomes `group-host:current`, the image it replaces is kept as `group-host:before-<commit>`, and compose brings the host and the console up from the compose file at that commit, as the upgrade above does. The deploy passes once `/xrpc/_health` names the commit, on the machine and then through the proxy, within a minute.
One deploy runs at a time, and a newer commit's waits for the one before it to finish rather than cutting it off. A deploy whose commit is no longer `main`'s tip, before it builds or before it goes up, stops and leaves the deploy to the newer commit.
One deploy runs at a time, in the order `main` moved, and a newer commit's waits for the one before it to finish rather than cutting it off.
The workflow runs only on `ci.knotless.dev`, the runner that runs its owner's repositories alone; every other workflow names `runner.knotless.dev`. Two secrets are sealed to `ci.knotless.dev` for `refs/heads/main`: `GROUP_HOST_DEPLOY_KEY`, an SSH key the machine accepts only to run its deploy command, which can build, bring up or throw away a group-host image and do nothing else; and `KNOTLESS_PASSWORD`, an app password of the repository's owner, for reading `main` and its checks, as the repository is private. The deploy command, how its key is installed, and how to roll back are in the machine's own configuration (hetzner-infra's `stacks/opensocial`).
The workflow runs only on `ci.knotless.dev`, the runner that runs its owner's repositories alone; every other workflow names `runner.knotless.dev`. One secret is sealed to `ci.knotless.dev` for `refs/heads/main`: `GROUP_HOST_DEPLOY_KEY`, an SSH key the machine accepts only to run its deploy command, which can build, bring up or throw away a group-host image and do nothing else. The deploy command, how its key is installed, and how to roll back are in the machine's own configuration (hetzner-infra's `stacks/opensocial`).
## Backing up
AGENTS.md+2−2
@@ -189,8 +189,8 @@ Two more check nothing. `mirror`: each push to `main` or a tag pushes
the same commit to a private copy on GitHub
(github.com/bluesky-social/group-host), for those who read the code
there. Nothing is pushed to that copy but from here. `deploy`: each push
to `main` is built on the machine serving next.opensocial.fyi while the
checks run, and goes up there once they all pass
to `main`, which takes pulls only once the merge queue's checks pass,
is built on the machine serving next.opensocial.fyi and goes up there
(`docs/deploying.md`). Every workflow but `deploy` names
`runner.knotless.dev`; `deploy` alone runs on `ci.knotless.dev`, which
runs only its owner's repositories, and holds its secrets.