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

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

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:deploy/workflow
.knotless/workflows/check.yml+2−0
@@ -5,6 +5,8 @@
# lints land on purpose. The build and the toolchain's components are kept
# between runs, so a push lints only what it changed.
image: rust:1.98
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
# A pre-flight: the merge queue takes a pull into a batch only once this
# has passed at its head, so one that does not build fails no batch.
queue: first
.knotless/workflows/deploy.ymlnew+108−0
@@ -0,0 +1,108 @@
# Deploys main to next.opensocial.fyi once this commit's checks all pass.
#
# The host runs on the grain box as the compose project /etc/group-host
# (hetzner-infra's stacks/opensocial). This run reaches it with
# GROUP_HOST_DEPLOY_KEY, a key the box takes only for its forced command,
# group-host-deploy, which can build group-host from an archive, bring a
# build up, or drop one, and nothing else (hetzner-infra's
# stacks/opensocial/files/group-host-deploy.sh). 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 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.
on:
push:
refs: [refs/heads/main]
superseded: finish
runners: [ci.knotless.dev]
image: alpine:3.22
secrets: [GROUP_HOST_DEPLOY_KEY, KNOTLESS_PASSWORD]
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
printf 'Host *\n StrictHostKeyChecking yes\n ServerAliveInterval 30\n' > ~/.ssh/config
# The box's forced command, given what to do and this commit.
cat > /usr/local/bin/box <<'EOF'
#!/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
- 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.
for i in $(seq 30); do
health=$(curl -fsS "$GROUP_HOST_URL/xrpc/_health" || true)
case "$health" in *"\"$KNOTLESS_RUN_SHA\""*) echo "$health"; exit 0 ;; esac
sleep 2
done
echo "$GROUP_HOST_URL names no $KNOTLESS_RUN_SHA: ${health:-no answer}"
echo "the box runs group-host:current at this commit, but it is not healthy;"
echo "to roll back: docker tag group-host:before-$(echo "$KNOTLESS_RUN_SHA" | cut -c1-12) group-host:current, then docker compose up -d in /etc/group-host"
exit 1
.knotless/workflows/docs.yml+2−0
@@ -5,6 +5,8 @@
# run could sign in with, cannot write. The site's packages are kept
# between runs and installed again only when its lockfile changes.
image: node:24.22.1
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
# Pushes to main, and pulls that change the docs, their check, the site,
# the lexicons and tokens it takes, or this file. A pull changing none
# passes at once, noted as skipped.
.knotless/workflows/e2e.yml+2−0
@@ -11,6 +11,8 @@
# kept between runs, as main's runs leave them: nothing is fetched again
# until what it is made from changes.
image: rust:1.98
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
# Every push to main, and pulls into it or a feature/ branch that change
# the console, the host it asks, the lexicons, the harness it runs over, or
# this file. A pull changing none passes at once, noted as skipped.
.knotless/workflows/lexicons.yml+2−0
@@ -2,6 +2,8 @@
# see, and that they only grow from main's (harness/lexicons.mjs). goat is
# kept between runs.
image: node:24.22.1
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
on:
push: {refs: [refs/heads/main]}
pull:
.knotless/workflows/mirror.yml+2−0
@@ -10,6 +10,8 @@
on:
push: {refs: [refs/heads/main, refs/tags/*]}
image: debian:stable-slim
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
secrets: [MIRROR_KEY]
env: {MIRROR: git@github.com:bluesky-social/group-host.git}
steps:
.knotless/workflows/test.yml+2−0
@@ -8,6 +8,8 @@
# are kept between runs; each is made again only when what it is made from
# changes.
image: rust:1.98
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
# A pre-flight, as check is: the merge queue takes a pull into a batch only
# once this has passed at its head.
queue: first
.knotless/workflows/web.yml+2−0
@@ -4,6 +4,8 @@
# which fails on any warning. The packages are kept between runs and
# installed again only when the lockfile changes.
image: node:24.22.1
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml.
runners: [runner.knotless.dev]
# Pushes to main, and pulls that change the pages, the lexicons their types
# are made from, the layers' or dialogs' check or this file. A pull changing none passes
# at once, noted as skipped.
docs/deploying.md+9−1
@@ -139,7 +139,15 @@ docker compose up -d host
docker compose up -d console
```
On SIGTERM the host answers the requests already under way, within its 30-second grace period, then exits. The proxy holds new requests until the new host answers. Compose replaces the console the same way. It keeps no state, so a rollout could start a new console beside the old one instead; neither service sets `container_name`, which leaves that possible. Stopped, the console finishes its requests within a 35-second grace period. Scripts to build on the machine and roll out, and a workflow that deploys, are not in the repository yet.
On SIGTERM the host answers the requests already under way, within its 30-second grace period, then exits. The proxy holds new requests until the new host answers. Compose replaces the console the same way. It keeps no state, so a rollout could start a new console beside the old one instead; neither service sets `container_name`, which leaves that possible. Stopped, the console finishes its requests within a 35-second grace period.
## 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.
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.
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`).
## Backing up
AGENTS.md+7−2
@@ -185,10 +185,15 @@ pulls into it or into a `feature/` branch:
- `docs`: `just docs`, every link and anchor landing, and the docs site's
build.
One more, `mirror`, checks nothing: each push to `main` or a tag pushes
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.
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
(`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.
On a pull, `web`, `lexicons`, `e2e` and `docs` run only when it changes
what they read; otherwise each passes at once, noted as skipped.