|
| 1 | +# `tools/ci-runner/` — self-hosted burst runners |
| 2 | + |
| 3 | +Spawn-per-job GitHub Actions runners for the `kvm` label, so the |
| 4 | +[VM end-to-end test](../vm-test/README.md) can run in CI. GitHub's hosted |
| 5 | +runners cannot: they have no nested virtualisation and not enough disk. |
| 6 | + |
| 7 | +Nothing runs while the queue is empty. One small autoscaler container watches |
| 8 | +for queued jobs and starts an **ephemeral** runner per job; each runner takes |
| 9 | +exactly one job, deregisters itself and exits. |
| 10 | + |
| 11 | +``` |
| 12 | +autoscaler (always on, ~20 MB) |
| 13 | + │ polls the repo for queued jobs asking for 'kvm' |
| 14 | + ▼ |
| 15 | +gha-burst-<ts>-<n> ephemeral runner container, one job then gone |
| 16 | + │ drives libvirt over the host socket |
| 17 | + ▼ |
| 18 | +steamos-install-test VM on the host, torn down by the test itself |
| 19 | +``` |
| 20 | + |
| 21 | +## Security: read this before pointing it at a public repo |
| 22 | + |
| 23 | +A self-hosted runner executes whatever the workflow says. On a **public** |
| 24 | +repository that is a real risk, because anyone can open a pull request. |
| 25 | + |
| 26 | +The protections here: |
| 27 | + |
| 28 | +- **`vm-test.yml` is `workflow_dispatch` only.** It never triggers on |
| 29 | + `pull_request`, so a fork cannot cause it to run. Nothing else uses the |
| 30 | + `kvm` label — every other job stays on GitHub's hosted runners. |
| 31 | +- **Ephemeral runners.** One job per container, then it is discarded. Nothing |
| 32 | + persists between jobs. |
| 33 | +- **The credential is never in the image or the environment.** It is |
| 34 | + bind-mounted read-only as a file and read at the moment it is used, so |
| 35 | + `docker inspect` does not reveal it. |
| 36 | + |
| 37 | +Worth also setting, once: |
| 38 | + |
| 39 | +```bash |
| 40 | +gh api -X PUT repos/OWNER/REPO/actions/permissions/workflow -f default_workflow_permissions=read |
| 41 | +``` |
| 42 | + |
| 43 | +and in **Settings → Actions → General → Fork pull request workflows**, choose |
| 44 | +*Require approval for all outside collaborators*. |
| 45 | + |
| 46 | +Do not add the `kvm` label to a workflow that runs on `pull_request` unless you |
| 47 | +have thought hard about it. The runner is privileged and sits on your LAN. |
| 48 | + |
| 49 | +## Setting it up |
| 50 | + |
| 51 | +On the libvirt host (not your laptop): |
| 52 | + |
| 53 | +```bash |
| 54 | +git clone https://github.com/louij2/steamos_custom_install.git |
| 55 | +cd steamos_custom_install |
| 56 | +sudo ./tools/ci-runner/deploy-unraid.sh |
| 57 | +``` |
| 58 | + |
| 59 | +It refuses to start without a credential and tells you how to create one. The |
| 60 | +token needs **`Administration: read and write`** on the one repository — that |
| 61 | +is what mints runner registration tokens. Create a fine-grained PAT scoped to |
| 62 | +that single repo at <https://github.com/settings/personal-access-tokens/new>, |
| 63 | +then put it in place yourself: |
| 64 | + |
| 65 | +```bash |
| 66 | +install -d -m 700 /mnt/user/appdata/gh-autoscaler |
| 67 | +printf '%s' 'YOUR_TOKEN' > /mnt/user/appdata/gh-autoscaler/gh_pat |
| 68 | +chmod 600 /mnt/user/appdata/gh-autoscaler/gh_pat |
| 69 | +``` |
| 70 | + |
| 71 | +## Configuration |
| 72 | + |
| 73 | +Every knob is an environment variable on `deploy-unraid.sh`: |
| 74 | + |
| 75 | +| Variable | Default | Meaning | |
| 76 | +|---|---|---| |
| 77 | +| `GITHUB_REPO` | `louij2/steamos_custom_install` | Repository to serve | |
| 78 | +| `RUNNER_LABEL` | `kvm` | Label a job must request | |
| 79 | +| `MAX_RUNNERS` | `3` | Ceiling on concurrent burst runners | |
| 80 | +| `POLL_SECONDS` | `30` | Seconds between queue checks | |
| 81 | +| `METRICS_PORT` | `9826` | Prometheus endpoint | |
| 82 | +| `VM_WORKDIR` | `/mnt/user/isos/steamos-vm-test` | Image cache, must be real storage | |
| 83 | +| `MAX_RUNNERS=1` | | Effectively serialises, if the host is busy | |
| 84 | + |
| 85 | +Raise `MAX_RUNNERS` only as far as the host can take: each concurrent VM test |
| 86 | +wants ~8 GB RAM, 4 vCPU and ~21 GB of disk. |
| 87 | + |
| 88 | +Unlike the Azure DevOps equivalent there is **no billing ceiling** — self-hosted |
| 89 | +runners on a public repository have unlimited concurrency, so the only limit is |
| 90 | +the hardware. |
| 91 | + |
| 92 | +## Metrics |
| 93 | + |
| 94 | +Prometheus endpoint on `:9826/metrics`: |
| 95 | + |
| 96 | +| Metric | Meaning | |
| 97 | +|---|---| |
| 98 | +| `gha_ci_queued_jobs` | Queued jobs asking for the label | |
| 99 | +| `gha_ci_burst_running` | Burst containers alive now | |
| 100 | +| `gha_ci_max_runners` | Configured ceiling | |
| 101 | +| `gha_ci_spawned_total` | Runners started since the autoscaler booted | |
| 102 | +| `gha_ci_errors_total` | Poll or spawn failures | |
| 103 | +| `gha_ci_last_tick_timestamp_seconds` | Staleness check for the loop | |
| 104 | + |
| 105 | +Alert on `time() - gha_ci_last_tick_timestamp_seconds > 300` (the loop is dead) |
| 106 | +and on `gha_ci_queued_jobs > 0 and gha_ci_burst_running == 0` sustained (jobs |
| 107 | +are queuing but nothing is starting — usually an expired credential). |
| 108 | + |
| 109 | +## Why the runner container is privileged |
| 110 | + |
| 111 | +The VM test needs `losetup`, `mount` and `btrfs property` against real devices |
| 112 | +to inject the harness into the recovery image. It does **not** run qemu: it |
| 113 | +talks to the host's libvirt over the mounted socket, so the VM belongs to the |
| 114 | +host. That is also why the work directory is bind-mounted at the *same path* |
| 115 | +inside and out — libvirt resolves the disk image paths on the host, not in the |
| 116 | +container. |
| 117 | + |
| 118 | +## Operating it |
| 119 | + |
| 120 | +```bash |
| 121 | +docker logs -f gh-autoscaler # what it is deciding |
| 122 | +docker ps --filter label=gha-burst=1 # runners alive right now |
| 123 | +curl -s localhost:9826/metrics # current state |
| 124 | +docker rm -f gh-autoscaler # stop scaling; running jobs finish |
| 125 | +``` |
| 126 | + |
| 127 | +Runners that vanish mid-job leave a registration behind; they are ephemeral so |
| 128 | +GitHub clears them, but `gh api repos/OWNER/REPO/actions/runners` shows what is |
| 129 | +registered if you suspect otherwise. |
0 commit comments