From d09cd5c0262b48b58ccb656eb7f89fe739b363ab Mon Sep 17 00:00:00 2001 From: Chandarith Chea <45872539+chandarith-chea@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:20:32 +0700 Subject: [PATCH 1/4] CI: run Build and test on a self-hosted Dockiva runner The job runs on an ephemeral actions/runner (linux/arm64) in a Dockiva container on a maintainer's Mac. Fork PRs, and runs while the repository variable CI_RUNNER is 'hosted', stay on GitHub-hosted ubuntu-24.04. Setup and the runner image are in scripts/ci-runner. --- .github/workflows/ci.yml | 4 +- scripts/ci-runner/Dockerfile | 26 +++++++ scripts/ci-runner/README.md | 75 +++++++++++++++++++ scripts/ci-runner/dev.dockiva.gh-runner.plist | 14 ++++ scripts/ci-runner/run-dockiva-runner.sh | 30 ++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 scripts/ci-runner/Dockerfile create mode 100644 scripts/ci-runner/README.md create mode 100644 scripts/ci-runner/dev.dockiva.gh-runner.plist create mode 100755 scripts/ci-runner/run-dockiva-runner.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b2df67..5ba9637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,9 @@ concurrency: jobs: test: name: Build and test - runs-on: ubuntu-24.04 + # Self-hosted Dockiva runner (scripts/ci-runner/README.md); fork PRs and + # the CI_RUNNER=hosted fallback use GitHub-hosted ubuntu-24.04. + runs-on: ${{ (github.event.pull_request.head.repo.fork || vars.CI_RUNNER == 'hosted') && 'ubuntu-24.04' || 'dockiva' }} steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 with: diff --git a/scripts/ci-runner/Dockerfile b/scripts/ci-runner/Dockerfile new file mode 100644 index 0000000..535b37c --- /dev/null +++ b/scripts/ci-runner/Dockerfile @@ -0,0 +1,26 @@ +# Self-hosted GitHub Actions runner for Dockiva (linux/arm64). +# One container = one job: run-dockiva-runner.sh starts it with a single-use +# JIT config and removes it when the job ends. +FROM ubuntu:24.04 + +ARG RUNNER_VERSION=2.338.2 +ARG RUNNER_SHA256=670adb2f268fe21dcbb58b3db0e0aa9d5b3bddfe2c651481336e561ff86de945 + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git jq sudo tar unzip xz-utils zstd \ + && useradd -m -s /bin/bash runner \ + && echo 'runner ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/runner \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /home/runner +RUN curl -fsSL -o runner.tgz \ + "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz" \ + && echo "${RUNNER_SHA256} runner.tgz" | sha256sum -c - \ + && tar xzf runner.tgz && rm runner.tgz \ + && ./bin/installdependencies.sh \ + && rm -rf /var/lib/apt/lists/* \ + && chown -R runner:runner /home/runner + +USER runner +ENTRYPOINT ["./run.sh"] diff --git a/scripts/ci-runner/README.md b/scripts/ci-runner/README.md new file mode 100644 index 0000000..3a5484f --- /dev/null +++ b/scripts/ci-runner/README.md @@ -0,0 +1,75 @@ +# Self-hosted CI runner on Dockiva + +CI's `Build and test` job (`.github/workflows/ci.yml`) runs on a self-hosted +GitHub Actions runner with the label `dockiva`. The runner is GitHub's +`actions/runner` (linux/arm64) in a Dockiva container on a maintainer's Mac. + +## How it works + +- `Dockerfile` builds `dockiva-gh-runner:`: Ubuntu 24.04, the pinned + runner release (SHA-256 checked), passwordless `sudo` for `apt-get`. +- `run-dockiva-runner.sh` loops on the Mac: it asks GitHub for a single-use + JIT runner config (`generate-jitconfig`) with the Mac's `gh` login, runs one + job in a fresh container (`docker run --rm`), then starts over. Each job gets + a clean container, and no GitHub credential lives in the image. +- A launchd agent keeps the loop running. When Dockiva is stopped, the loop + waits; jobs stay queued on GitHub until a runner comes back (GitHub fails a + job that waits more than 24 hours). + +## Which runs use it + +```yaml +runs-on: ${{ (github.event.pull_request.head.repo.fork || vars.CI_RUNNER == 'hosted') && 'ubuntu-24.04' || 'dockiva' }} +``` + +- Pull requests from forks always run on GitHub-hosted `ubuntu-24.04`, so + outside code never runs on the Mac. +- Pushes to `main` and pull requests from branches in this repository run on + Dockiva. +- Fallback: set the repository variable `CI_RUNNER` to `hosted` to send every + run to `ubuntu-24.04` (for example, when the Mac is away for a while): + + ```sh + gh variable set CI_RUNNER --body hosted --repo Tomnerb/Dockiva + gh variable delete CI_RUNNER --repo Tomnerb/Dockiva # back to Dockiva + ``` + + Runs that are already queued keep their runner; re-run them after the switch. + +`release.yml` stays on GitHub-hosted runners: its macOS and Windows jobs can't +run in Linux containers, and its protected environments sign and publish. + +## Setup (once per Mac) + +Needs Dockiva running (docker context `dockiva`) and `gh` logged in as a user +with admin access to the repository (`gh auth status`; scope `repo`). + +```sh +cd scripts/ci-runner +sed "s|__SCRIPT__|$PWD/run-dockiva-runner.sh|" dev.dockiva.gh-runner.plist \ + > ~/Library/LaunchAgents/dev.dockiva.gh-runner.plist +launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/dev.dockiva.gh-runner.plist +``` + +The first start builds the image (about 2 minutes). Check it: + +```sh +tail -f /tmp/dockiva-gh-runner.log +gh api repos/Tomnerb/Dockiva/actions/runners --jq '.runners[] | [.name, .status, .busy] | @tsv' +``` + +Stop it: + +```sh +launchctl bootout gui/$(id -u)/dev.dockiva.gh-runner +``` + +Upgrade the runner: change `RUNNER_VERSION` and `RUNNER_SHA256` in the +Dockerfile (checksum from the release notes), and `IMAGE` in the script. + +## Limits + +- One runner, one job at a time: concurrent runs queue. +- The runner is arm64; GitHub-hosted `ubuntu-24.04` is amd64. +- Repository settings keep "Require approval for first-time contributors" + on, as a second guard for fork PRs. diff --git a/scripts/ci-runner/dev.dockiva.gh-runner.plist b/scripts/ci-runner/dev.dockiva.gh-runner.plist new file mode 100644 index 0000000..44414be --- /dev/null +++ b/scripts/ci-runner/dev.dockiva.gh-runner.plist @@ -0,0 +1,14 @@ + + + + + + Labeldev.dockiva.gh-runner + ProgramArguments + /bin/sh__SCRIPT__ + RunAtLoad + KeepAlive + StandardOutPath/tmp/dockiva-gh-runner.log + StandardErrorPath/tmp/dockiva-gh-runner.log + + diff --git a/scripts/ci-runner/run-dockiva-runner.sh b/scripts/ci-runner/run-dockiva-runner.sh new file mode 100755 index 0000000..c3244d7 --- /dev/null +++ b/scripts/ci-runner/run-dockiva-runner.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Keeps one ephemeral GitHub Actions runner (label "dockiva") available in a +# Dockiva container. Each loop: mint a single-use JIT config with the host's +# `gh` login, run one job in a fresh container, remove the container. +# No GitHub credential is stored in the image or container. +set -u + +REPO=${REPO:-Tomnerb/Dockiva} +CONTEXT=${DOCKER_CONTEXT:-dockiva} +IMAGE=${IMAGE:-dockiva-gh-runner:2.338.2} +HERE=$(cd "$(dirname "$0")" && pwd) +export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" + +docker_() { docker --context "$CONTEXT" "$@"; } + +while :; do + # Dockiva not running: wait for it. Queued jobs wait on GitHub meanwhile. + if ! docker_ info >/dev/null 2>&1; then sleep 30; continue; fi + if ! docker_ image inspect "$IMAGE" >/dev/null 2>&1; then + docker_ build -t "$IMAGE" "$HERE" || { sleep 60; continue; } + fi + + name="dockiva-$(hostname -s)-$(date +%s)" + jit=$(gh api -X POST "repos/$REPO/actions/runners/generate-jitconfig" \ + -f name="$name" -F runner_group_id=1 -f work_folder=_work \ + -f 'labels[]=dockiva' --jq .encoded_jit_config) || { sleep 60; continue; } + + echo "$(date '+%F %T') $name waiting for a job" + docker_ run --rm --name "$name" "$IMAGE" --jitconfig "$jit" || sleep 10 +done From 98694ce1a280773c082939b36bb27a4313f103b7 Mon Sep 17 00:00:00 2001 From: Chandarith Chea <45872539+chandarith-chea@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:26:11 +0700 Subject: [PATCH 2/4] CI runner: run as root so sudo keeps working after apt --- scripts/ci-runner/Dockerfile | 10 +++++----- scripts/ci-runner/README.md | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/ci-runner/Dockerfile b/scripts/ci-runner/Dockerfile index 535b37c..316703c 100644 --- a/scripts/ci-runner/Dockerfile +++ b/scripts/ci-runner/Dockerfile @@ -9,8 +9,6 @@ ARG RUNNER_SHA256=670adb2f268fe21dcbb58b3db0e0aa9d5b3bddfe2c651481336e561ff86de9 RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ ca-certificates curl git jq sudo tar unzip xz-utils zstd \ - && useradd -m -s /bin/bash runner \ - && echo 'runner ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/runner \ && rm -rf /var/lib/apt/lists/* WORKDIR /home/runner @@ -19,8 +17,10 @@ RUN curl -fsSL -o runner.tgz \ && echo "${RUNNER_SHA256} runner.tgz" | sha256sum -c - \ && tar xzf runner.tgz && rm runner.tgz \ && ./bin/installdependencies.sh \ - && rm -rf /var/lib/apt/lists/* \ - && chown -R runner:runner /home/runner + && rm -rf /var/lib/apt/lists/* -USER runner +# Root, not a sudo user: on Dockiva Engine, once apt drops to _apt (which sets +# no_new_privs), later sudo calls in the container can't regain root. Each job +# gets a fresh container, so root here doesn't outlive the job. +ENV RUNNER_ALLOW_RUNASROOT=1 ENTRYPOINT ["./run.sh"] diff --git a/scripts/ci-runner/README.md b/scripts/ci-runner/README.md index 3a5484f..dee532c 100644 --- a/scripts/ci-runner/README.md +++ b/scripts/ci-runner/README.md @@ -6,8 +6,9 @@ GitHub Actions runner with the label `dockiva`. The runner is GitHub's ## How it works -- `Dockerfile` builds `dockiva-gh-runner:`: Ubuntu 24.04, the pinned - runner release (SHA-256 checked), passwordless `sudo` for `apt-get`. +- `Dockerfile` builds `dockiva-gh-runner:`: Ubuntu 24.04 and the + pinned runner release (SHA-256 checked). The runner runs as root (`sudo` + still works for steps that call it); see the Dockerfile for why. - `run-dockiva-runner.sh` loops on the Mac: it asks GitHub for a single-use JIT runner config (`generate-jitconfig`) with the Mac's `gh` login, runs one job in a fresh container (`docker run --rm`), then starts over. Each job gets From e9e67b386b36027a93cca53b725b02f856a8879a Mon Sep 17 00:00:00 2001 From: Chandarith Chea <45872539+chandarith-chea@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:35:33 +0700 Subject: [PATCH 3/4] CI runner: add C toolchain; skip case-colliding netfilter headers go test -tags gtk3 needs cgo (gcc, pkg-config), as on hosted Ubuntu. On Dockiva releases without the case-sensitive engine store, dpkg can't install linux-libc-dev's xt_CONNMARK.h/xt_connmark.h pairs; exclude the uppercase ones until that store ships. --- scripts/ci-runner/Dockerfile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/ci-runner/Dockerfile b/scripts/ci-runner/Dockerfile index 316703c..1e46eac 100644 --- a/scripts/ci-runner/Dockerfile +++ b/scripts/ci-runner/Dockerfile @@ -6,9 +6,20 @@ FROM ubuntu:24.04 ARG RUNNER_VERSION=2.338.2 ARG RUNNER_SHA256=670adb2f268fe21dcbb58b3db0e0aa9d5b3bddfe2c651481336e561ff86de945 +# ponytail: Dockiva <= 0.6.7 keeps container files on case-insensitive APFS, so +# linux-libc-dev's xt_CONNMARK.h / xt_connmark.h pairs collide and dpkg fails. +# Skip the uppercase netfilter target headers; drop this once Dockiva ships +# the case-sensitive engine store (engine af61a4e). +RUN printf '%s\n' \ + 'path-exclude=/usr/include/linux/netfilter/xt_[A-Z]*' \ + 'path-exclude=/usr/include/linux/netfilter_ipv4/ipt_[A-Z]*' \ + 'path-exclude=/usr/include/linux/netfilter_ipv6/ip6t_[A-Z]*' \ + > /etc/dpkg/dpkg.cfg.d/dockiva-case-insensitive + RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git jq sudo tar unzip xz-utils zstd \ + build-essential ca-certificates curl git jq pkg-config sudo tar unzip \ + xz-utils zstd \ && rm -rf /var/lib/apt/lists/* WORKDIR /home/runner From e7a6ee329be0a12e2c880644bbe29625014c1c87 Mon Sep 17 00:00:00 2001 From: Chandarith Chea <45872539+chandarith-chea@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:46:46 +0700 Subject: [PATCH 4/4] CI runner: give the job container 8 GiB Dockiva's 2 GiB default container budget killed the runner during a cold cgo go test ./... (engine: out of memory: killed process). --- scripts/ci-runner/README.md | 2 ++ scripts/ci-runner/run-dockiva-runner.sh | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/ci-runner/README.md b/scripts/ci-runner/README.md index dee532c..1546dc6 100644 --- a/scripts/ci-runner/README.md +++ b/scripts/ci-runner/README.md @@ -70,6 +70,8 @@ Dockerfile (checksum from the release notes), and `IMAGE` in the script. ## Limits +- The job container gets 8 GiB (`MEMORY` in the script; Dockiva's default is + 2 GiB, too little for a cold cgo `go test ./...`). - One runner, one job at a time: concurrent runs queue. - The runner is arm64; GitHub-hosted `ubuntu-24.04` is amd64. - Repository settings keep "Require approval for first-time contributors" diff --git a/scripts/ci-runner/run-dockiva-runner.sh b/scripts/ci-runner/run-dockiva-runner.sh index c3244d7..73a4f7d 100755 --- a/scripts/ci-runner/run-dockiva-runner.sh +++ b/scripts/ci-runner/run-dockiva-runner.sh @@ -8,6 +8,8 @@ set -u REPO=${REPO:-Tomnerb/Dockiva} CONTEXT=${DOCKER_CONTEXT:-dockiva} IMAGE=${IMAGE:-dockiva-gh-runner:2.338.2} +# Dockiva gives containers 2 GiB by default; a cold cgo `go test ./...` needs more. +MEMORY=${MEMORY:-8g} HERE=$(cd "$(dirname "$0")" && pwd) export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" @@ -26,5 +28,5 @@ while :; do -f 'labels[]=dockiva' --jq .encoded_jit_config) || { sleep 60; continue; } echo "$(date '+%F %T') $name waiting for a job" - docker_ run --rm --name "$name" "$IMAGE" --jitconfig "$jit" || sleep 10 + docker_ run --rm -m "$MEMORY" --name "$name" "$IMAGE" --jitconfig "$jit" || sleep 10 done