While SELFHOSTED_RUNNERS is true, trusted Linux jobs in ci.yml and language-smoke.yml run on the openidea-selfhosted runners and fall back to ubuntu-latest otherwise. The runner image moves to Ubuntu 24.04, E2E installs Chromium on the runner, and the smoke tests resolve fixtures from the runtime CARGO_MANIFEST_DIR.
7.8 KiB
Self-Hosted GitHub Actions Runners
Runs N persistent, isolated GitHub Actions runners via Docker Compose on a single Docker named volume (runner-persist) without requiring repository admin Personal Access Tokens.
In .github/workflows/ci.yml and .github/workflows/language-smoke.yml, every Linux job routes to ["self-hosted", "openidea-selfhosted"] on trusted events (push, merge_group, workflow_dispatch, and same-repo pull requests) while the SELFHOSTED_RUNNERS repository variable is true. Fork pull requests, and every run while the variable is unset, fall back to ubuntu-latest. Workflows triggered on pull_request_target with write-scoped GITHUB_TOKEN permissions (pr-check.yml, cancel-on-close.yml) stay on ubuntu-latest.
Availability requirement: GitHub Actions
runs-oncannot fall back to GitHub-hosted runners when no matching self-hosted runner is online; jobs stay queued until one connects. SetSELFHOSTED_RUNNERS=true(Settings → Secrets and variables → Actions → Variables) only once the runners are up, and delete it before taking the host down.
Security Constraints
Because this repository is public and these runners retain persistent build caches and credentials across runs, workflows and runner hosts must follow these rules:
- Trusted events only: Route jobs to
openidea-selfhostedonly forpush,merge_group,workflow_dispatch, orpull_requestevents wheregithub.event.pull_request.head.repo.full_name == github.repository. Fork pull requests must stay on GitHub-hosted runners so untrusted code never reaches persistent caches or runner credentials. - Read-only
GITHUB_TOKEN: Jobs targetingopenidea-selfhostedmust setpermissions: { contents: read }(least privilege). - No secret-bearing jobs: Never pass repository or organization
secrets.*to jobs running onopenidea-selfhosted. - Never feed releases: Artifacts or outputs from
openidea-selfhostedrunners must never be uploaded for consumption by release or nightly workflows. - Container isolation: Jobs run as the
runneruser (RUN_AS_ROOT=false) from a pinned image tag and digest, but the image grants that user passwordlesssudo(CI needs it forapt-get), so a job can become root inside its container. The container is the isolation boundary: never mount/var/run/docker.sockor host directories into it, and never run it--privileged. - Shared build state: Same-repo pull requests and
mainshare each slot's Cargo target directory, so only collaborators you trust withmain's build should push branches to this repository. - Network isolation: Run the Docker host on an isolated network segment away from sensitive devices or internal services.
How It Works
On startup, each container replica acquires an exclusive flock on a numeric slot (1..N) before dropping privileges to the runner user, isolating its persistent state under /persist/slot-<N>/:
| Path | Purpose |
|---|---|
runner-data/ |
Saved .runner and .credentials reused across container restarts (CONFIGURED_ACTIONS_RUNNER_FILES_DIR) |
work/ |
Runner workspace and repository checkouts (RUNNER_WORKDIR) |
cargo-target/ |
Pre-compiled Rust build artifacts (CARGO_TARGET_DIR), kept outside checkouts so actions/checkout cleanup does not wipe it |
cargo/ |
Cargo crate registry and git cache (CARGO_HOME) |
rustup/ |
Installed Rust toolchains (RUSTUP_HOME) |
pnpm-store/ |
Content-addressable pnpm store on the same filesystem as work/ for fast hardlinks into node_modules |
toolcache/ |
Tools cached by actions/setup-* (/opt/hostedtoolcache) |
cache/ |
General /home/runner/.cache directory |
All slots also share /persist/shared/npm-cache for downloaded npm tarballs.
Prerequisites (First-Time Registration Only)
Ask a repository admin to generate one 1-hour registration token from:
GitHub Repository → Settings → Actions → Runners → New self-hosted runner
A single registration token can register multiple runner slots within its 1-hour validity window. Once registered, each slot saves its own runner credentials and reconnects across restarts without needing a token again.
Quick Start
Run all commands from scripts/selfhost-runner/:
-
Initial registration (registers slots
1..4and saves credentials):RUNNER_TOKEN=<one-time-token> docker compose up -d -
Normal start, restart, or recreate (no token needed once slots are registered):
docker compose up -d docker compose restart -
Scale down (for example
4→2):RUNNER_COUNT=2 docker compose up -dDocker Compose does not guarantee which container replicas it removes, so scaling
4→2may leave slots3and4running rather than1and2. Stopped slots keep their saved credentials and caches on disk and will be reclaimed on the next restart or scale-up. -
Scale up (for example
4→6):-
If slots
5..6were previously registered:RUNNER_COUNT=6 docker compose up -d -
If slots
5..6have never been registered:RUNNER_COUNT=6 RUNNER_TOKEN=<new-token> docker compose up -d
-
Configuration
You can pass variables on the command line or place them in a local .env file in this directory (git-ignored):
| Variable | Default | Description |
|---|---|---|
RUNNER_COUNT |
4 |
Number of concurrent runner replicas |
RUNNER_NAME_PREFIX |
openidea-runner |
Runner name prefix; registers as <prefix>-1, <prefix>-2, … |
RUNNER_LABELS |
openidea-selfhosted |
Comma-separated labels attached to each runner |
REPO_URL |
https://github.com/l0ng-ai/openidea |
Target GitHub repository URL |
RUNNER_TOKEN |
(empty) | One-time registration token (required only when registering new slots) |
Troubleshooting & Tips
-
Offline expiry (> 14 days) or deleted runner: GitHub automatically removes runners that stay offline for more than 14 days. To clear a stale slot
<N>and re-register it:docker compose run --rm --entrypoint /bin/bash github-runner \ -c "rm -rf /persist/slot-<N>/runner-data/*" RUNNER_TOKEN=<new-token> docker compose up -d -
Full reset (wipes all saved runner credentials and cached build artifacts):
docker compose down -v -
Workflow caching tips:
CARGO_TARGET_DIRpersists automatically across runs; CI enables incremental compilation on these runners and clears a slot's target directory once it exceeds 40 GB. To also preserve in-reponode_modules/across runs without re-linking, passclean: falsetoactions/checkout(otherwisepnpm installquickly re-hardlinks packages frompnpm-store/).