CI pool

Deprecated: Move each repository to runner-up before you remove its CI pool slots. Keep Eagle and Iterative on the CI pool until a supported Ubuntu 24.04 runner-up host is available.

The CI pool runs GitHub Actions jobs on this host with no runner to register or remove by hand. runner-up replaces it one repository at a time. One list in .local/host.yml names each repository and its number of slots. Each slot is a systemd user unit that asks GitHub for a just-in-time (JIT) runner, runs one job in a fresh container, and exits. GitHub removes a JIT runner after its one job, and systemd starts the slot again for the next job.

Each runner slot gets a JIT configuration, runs one job, exits after GitHub removes the runner, and restarts through systemd

Opt a repository in

  1. Add the repository to crewship.ci_pool.repos in .local/host.yml:

    crewship:
      ci_pool:
        data_dir: /mnt/data/ci     # on a data disk, not the system disk
        # total_slots: auto        # or a number; see "Pool size"
        # job_cpus: 4              # CPU cap of each job container
        # job_memory_gb: 8         # memory cap of each job container
        # nice: 10                 # CI CPU priority; see "CPU priority"
        # image: crewship-ci-runner:latest   # see "What a job gets"
        repos:
          - repo: owner/name
            slots: 2
            labels: [my-label]
            # docker: dind           # a Docker daemon of its own in each slot; see "Docker in a job"
            # userns: true           # with docker: dind, on a host that restricts user namespaces
    
  2. Run ./ship.sh launch. To change only the pool, without a full apply, use Apply without the playbook.

  3. In the repository's workflow, run the job on the pool:

    runs-on: [self-hosted, my-label]
    

Every slot carries the self-hosted label and the labels of its repository entry. The account that runs the pool must have a gh login that can administer the repository's runners (the repo scope).

To remove a repository, delete its entry and apply again. Its idle slots stop and are disabled, and its work and cache directories are deleted. A slot that runs a job at that time is disabled but not stopped: it finishes the job, then leaves, and a later apply deletes its directories. To stop the whole pool, set repos: [] and apply. Removing the whole ci_pool section does not stop running slots, because apply then skips the pool.

Configuration

Key Default Meaning
data_dir required Parent of the pool's directory <data_dir>/ci-pool/, which holds every work directory and cache. Apply creates data_dir, owned by crewship.user. Put it on a data disk. The pool deletes only inside <data_dir>/ci-pool/, so data_dir may hold other data.
total_slots auto Most slots the pool runs. auto computes it at apply (see below). A number fixes it.
job_cpus 4 docker --cpus of each job container.
job_memory_gb 8 docker --memory and --memory-swap of each job container, in GiB.
nice 0 CPU priority of the pool, from 0 to 19. Above 0, CI work yields the CPU to the rest of the host. See CPU priority.
image crewship-ci-runner:latest Image of each job container. The default is built on the host (see What a job gets). Any other name is pulled hourly and used as it is.
repos[].repo required owner/name on github.com.
repos[].slots required Slots for this repository: the most jobs it runs at one time.
repos[].labels required Runner labels that the workflow's runs-on selects.
repos[].docker none dind gives each slot of the repository its own Docker daemon. See Docker in a job.
repos[].userns false With docker: dind: run the repository's sidecars under the AppArmor profile ci-dind-userns, which allows the user namespace that rootless Docker needs on a host with kernel.apparmor_restrict_unprivileged_userns=1. See Docker in a job.

./ship.sh inspect refuses the pool without the docker profile, a data_dir with .., userns without docker, and two repositories that make the same unit name.

Pool size

With total_slots: auto, apply takes half of the host's CPUs and memory. It reads the totals, not the load, so the size is the same on every apply and does not change while jobs run:

total_slots = floor(min(CPUs × 0.5 / job_cpus,
                        MemTotal GiB × 0.5 / job_memory_gb))

The other half stays free for the agents and for load peaks. Example: 96 CPUs and 247 GiB with the default caps give min(12, 15.4), so 12 slots.

Slots are assigned in list order. When the repository entries ask for more slots than the total, apply starts the first ones, prints a warning that names the slots it did not start, and starts nothing else.

When the total drops, apply stops the idle slots that are over it. A slot that runs a job is never stopped: apply disables it, and it leaves after its current job. A job is never killed by apply.

When apply changes pool.json, it restarts the idle slots, so they register again with the new labels and caps. A slot is idle only when GitHub shows its runner not busy and its container runs no job; a failed read counts as busy. A slot that runs a job keeps its settings until the job ends; its next start reads the new file. Apply restarts idle slots for labels, caps, and image only in the run that changes pool.json. A later apply does not try again for a slot that it skipped then (busy, or GitHub could not show its runner or did not list it). That slot gets the new settings, labels included, at its next start after a job. The one exception is the CPU slice: see CPU priority.

CPU priority

Set nice above 0 to lower the CPU priority of all CI work. CI still uses every CPU that nothing else wants; this is not a cap. nice: 10 gives:

The per-job job_cpus and job_memory_gb caps stay as they are.

A change of nice between two values above 0 changes the CPUWeight of ci.slice at once, for every container that is already in ci.slice, busy ones included. Nice= on the slot unit and the move into or out of ci.slice apply only when a slot starts again. When nice goes back to 0, apply does not change ci.slice, so jobs that still run in it keep its weight until their slots start again. Apply restarts a slot only when GitHub shows its runner not busy and its container runs no job; when a read fails, it counts the slot as busy. A busy slot keeps its job, its container, and its unit priority, and its next start after the job uses the new setting. Every apply also reads the cgroup parent of each slot's job container (one docker inspect). It restarts a slot whose container is outside the slice that nice asks for when that slot is idle, also when pool.json did not change. A slot that apply skipped because it was busy or a read failed is thus restarted by a later apply once it is idle. A container that does not exist or that docker inspect does not show counts as in place. A change between two values above 0 keeps the slice, so it does not cause a restart, and the unit Nice= waits for the next start. To see where a job runs:

cat /sys/fs/cgroup/ci.slice/cpu.weight                                  # 11
sudo docker inspect ci-runner-<slot> --format '{{.HostConfig.CgroupParent}}'   # ci.slice

What a job gets

Headless GPU rendering

The built pool image includes mesa-vulkan-drivers for headless rendering through Mesa's software Vulkan adapter. It needs no display server or /dev/dri device. libvulkan-dev supplies headers and the loader, but it does not supply a Vulkan driver. Custom images need a Vulkan loader and a software Vulkan driver for these tests.

Postgres in the pool's image

The image has a main cluster for Postgres 17 and for Postgres 18. Both clusters use port 5432 and do not start at boot, so a job starts only the version it needs, with one command:

Version Start command
17 sudo pg_ctlcluster 17 main start
18 sudo pg_ctlcluster 18 main start

Stop the other version first (sudo pg_ctlcluster 17 main stop), or the start fails on port 5432. Postgres 18 has pgvector: CREATE EXTENSION vector; works after the start.

Docker in a job

A repository entry with docker: dind gives each of its slots a Docker daemon of its own, for example for docker compose up in an end-to-end test. The job never gets the host's Docker socket.

The sidecar runs with --privileged, also in its rootless form. Code that gets root in the sidecar has root on the host. The job's code reaches only the daemon, which runs as a non-root user in a user namespace, so a container that a job starts is not root on the host. The job container itself is never privileged. Use docker: dind only for a private repository whose pull requests come from its own branches. The job-started hook already refuses code from forks.

On a host with kernel.apparmor_restrict_unprivileged_userns=1 (Ubuntu's default), the kernel moves the sidecar's rootlesskit, which is not root, into the unprivileged_userns profile when it creates its user namespace, and that profile denies the capabilities it needs: the sidecar exits a few seconds after it starts, and the slot fails after the daemon timeout. Leave the sysctl alone and set userns: true on the repository entry instead. Apply then loads the profile ci-dind-userns with sudo -n apparmor_parser and writes it to /etc/apparmor.d/ci-dind-userns, before it changes any unit or pool.json: a profile that confines nothing and allows only the user namespace. When sudo refuses or the parser rejects the profile, apply exits with an error and leaves the pool as it was; the account needs a passwordless sudo rule for apparmor_parser and install. Only the sidecars of that repository run under it (--security-opt apparmor=ci-dind-userns); every other sidecar, every job container, and the host's setting stay as they are. apparmor.service loads the file again at boot.

Files on the host

Path Contents
~/.local/bin/ci-pool.py The script: apply converges the slots, run <slot> is each slot's ExecStart, watch is the timer's command.
~/.config/systemd/user/ci-runner@.service The one unit template. Apply writes it; instances are ci-runner@<owner>-<name>-<n>.service.
~/.config/systemd/user/ci-pool-watch.{service,timer} The watch timer (see Stalled slots). Apply writes and enables it.
~/.config/systemd/user/ci-pool-image.{service,timer} The hourly image build. Apply writes and enables it.
~/.config/ci-pool/pool.json The ci_pool section as apply last wrote it. Each slot reads it when it starts.
~/.config/ci-pool/job-started.sh The job-started hook. Apply writes it; each job container mounts it read-only. A slot whose hook file is missing does not start a job.
<data_dir>/ci-pool/work/<slot>/ The slot's job work directory.
<data_dir>/ci-pool/cache/<slot>/tool/, home/, cargo-registry/, cargo-git/ The slot's tool cache, ~/.cache, and cargo directories. A cache/<owner>-<name>/ directory from an older pool, which all slots of a repository shared, stays while the repository is in the pool; delete it once no container that started before the upgrade runs.
<data_dir>/ci-pool/scratch/<slot>/ The slot's /tmp, Postgres cluster directory, and ~/.bun, deleted at each job start.
<data_dir>/ci-pool/apt/<slot>/ The slot's downloaded apt packages and lists.
<data_dir>/ci-pool/dind/<slot>/ With docker: dind: the slot's Docker daemon data and TLS certificates, deleted at each job start.
/etc/apparmor.d/ci-dind-userns With userns: true: the sidecar's AppArmor profile. Apply loads it with sudo -n apparmor_parser, then installs the file.
/etc/systemd/system.control/ci.slice.d/ With nice above 0: the CPUWeight of ci.slice. Apply writes it with sudo -n systemctl set-property.

No token is stored. Each slot reads the host's gh login when it starts. When an account is not in the docker group, the script runs sudo -n docker.

See what runs

systemctl --user list-units 'ci-runner@*'          # the slots and their state
journalctl --user -u 'ci-runner@*' -f              # runner names, job progress, errors
sudo docker ps --filter label=crewship.ci-pool # one container for each slot, two with docker: dind
gh api repos/OWNER/NAME/actions/runners            # the runners GitHub knows

A slot that waits for a job shows as an online runner that is not busy. In a job log, the "Set up job" step names the runner: pool-<slot>-<unix time>.

Stalled slots

On a loaded host the Docker daemon can stall a call for good. A slot then holds a registered runner that shows offline and has no container, so jobs wait in the queue. Two guards stop this:

Jobs create the container with --pull missing. ci-pool-image.timer refreshes the image once an hour instead, so the slots do not pull at the same time.

Apply without the playbook

The playbook is not necessary for the pool. On a host where you do not want a full apply, run the same steps by hand:

sudo install -d -o "$USER" -g "$USER" -m 0755 /mnt/data/ci
install -m 0755 blueprint/maintenance/ci-pool.py ~/.local/bin/ci-pool.py
echo '{"data_dir": "/mnt/data/ci", "repos": [{"repo": "owner/name", "slots": 2, "labels": ["my-label"]}]}' \
  | python3 blueprint/maintenance/ci-pool.py apply --check   # preview; then run it without --check

apply prints one line for each change and nothing when the pool already matches the config.

Public repositories

A self-hosted runner runs the code of the workflow that selects it. On a public repository, a pull request from a fork can change the workflow. The job-started hook ends such a job's container before any of its steps run. That is the first barrier; the trigger rule below is the second. The job container limits CPU, memory, and processes, and has no Docker socket, but it shares the host's network, and its caches stay for the next job in the same slot.

macOS runner

The pool runs Linux jobs only. For macOS jobs, blueprint/maintenance/mac-runner.sh runs just-in-time runners on a Mac that you reach with ssh mac (see SSH to a Mac). Each repository gets one launchd user agent. The agent asks GitHub for a JIT runner, runs one job, and exits; launchd then starts it again. The agent reads the Mac's own gh login, so the Mac needs gh signed in with the repo scope. No token is stored. Every file is in one folder, ~/actions-runner-<name>/, except one plist for each repository in ~/Library/LaunchAgents/.

Install, from this repository on the host (the folder name is free; this example uses i098):

ssh mac 'mkdir -p ~/actions-runner-i098 && cat > ~/actions-runner-i098/mac-runner.sh && chmod +x ~/actions-runner-i098/mac-runner.sh' \
  < blueprint/maintenance/mac-runner.sh
ssh mac '~/actions-runner-i098/mac-runner.sh install owner/name another/repo'

install downloads the latest official osx-arm64 runner and checks its SHA-256 digest from the GitHub release. Run it again to update the runner or to add a repository. It restarts the agents that it names, and a job that runs on one of them stops.

In the workflow, run the job on the runner, and start the workflow only for files that can change the macOS result:

on:
  pull_request:
    paths: [.github/workflows/mac.yml, "**/*.swift", "**/*.plist", "**/*[mM]ac[oO][sS]*"]
jobs:
  test:
    runs-on: [self-hosted, macOS, mac-name]   # mac-<repository name>

What a job gets:

A job runs as the account on the Mac, without a container. It can read what that account can read. Opt in only repositories whose code you trust, and see Public repositories.

See what runs:

ssh mac 'launchctl list | grep mac-runner'                          # one agent for each repository
ssh mac 'tail ~/actions-runner-i098/<owner>-<name>/agent.log'        # runner IDs and job results
gh api repos/OWNER/NAME/actions/runners                             # mac-<name>-<unix time> runners

Remove everything (the agents, their plists, and the folder):

ssh mac '~/actions-runner-i098/mac-runner.sh remove'

A runner that waited for a job then shows as offline in the repository settings. GitHub deletes an offline JIT runner within one day. To delete it at once, run gh api -X DELETE repos/OWNER/NAME/actions/runners/ID.