Self-Hosted GitHub Actions Runners as a Pattern

One ephemeral runner per repo

Contents

Three runners in, I noticed I was doing the same setup by hand each time. I set up the first self-hosted runner for one of my projects. It worked, I moved on. A few weeks later I set up a second and did the same routine: spin up a VM, install Docker, download the runner, paste the registration token, configure a systemd unit. By the time I got to the third, I'd accepted that this wasn't a one-off. This post covers the pattern I landed on: ephemeral runners in Ubuntu VMs on Proxmox, provisioned by a single bash script, one runner per repo. Nothing "wow", just the operational shape of running a small fleet without every server becoming its own snowflake.

Self-hosting it

GitHub-hosted runners are fine. If you only have one or two repos, a handful of builds a day, and nothing that needs to touch your LAN, use them and save yourself the ops overhead.

Self-hosting is well worth it if:

  • You have two or more repos that justify a consistent build environment.
  • Your builds need to reach something on your internal network: a private registry, a test database, an internal package server.
  • You run heavy builds where GitHub's minutes budget becomes restrictive.
  • You want faster cold starts because everything is already cached on local disk.

Both projects needed to deploy into my homelab, and doing that from a GitHub-hosted runner would have meant exposing an ingress I didn't want to expose.

The pattern

One Ubuntu Server VM per repo, on Proxmox. Each VM is ephemeral only in the sense that the runner is ephemeral. The VM stays up, but every job runs in a clean runner state because --ephemeral tells the runner to deregister and exit after one job, and a systemd unit immediately re-registers it with a fresh token.

Why a VM rather than an LXC? Docker in LXC works, but it's fiddly with nesting and cgroups, and I'd rather not spend my time on those. A VM is predictable. You pay a little RAM for the kernel and get clean isolation with no other downsides.

Why one VM per repo rather than one shared runner? Isolation. If a workflow in one repo goes rogue or pulls a dodgy dependency, I don't want it seeing another repo's secrets, Docker socket, or workspace. Runners are cheap to stand up; the blast radius of a compromise is not.

The provisioning script

The setup is one script that takes these three arguments:

  • OWNER: your GitHub username or org.
  • REPO: the repo name, used for labelling and the VM hostname.
  • TOKEN: a registration token from Settings > Actions > Runners > New self-hosted runner (tokens expire in about an hour).

You run it once on a freshly installed Ubuntu Server VM. It installs Docker, pulls the latest runner, registers it as ephemeral, and sets up a systemd unit that re-registers after each job.

#!/usr/bin/env bash
set -euo pipefail

# Usage:   ./provision-runner.sh <OWNER> <REPO> <TOKEN>
# Example: ./provision-runner.sh myorg myrepo AABBCC...

OWNER="${1:?owner required}"
REPO="${2:?repo required}"
TOKEN="${3:?registration token required}"

RUNNER_USER="runner"
RUNNER_HOME="/home/${RUNNER_USER}"
RUNNER_DIR="${RUNNER_HOME}/actions-runner"

echo "[*] Installing base packages"
apt-get update
apt-get install -y curl jq ca-certificates gnupg lsb-release

echo "[*] Installing Docker"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
  | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

echo "[*] Creating runner user"
id -u "${RUNNER_USER}" &>/dev/null || useradd -m -s /bin/bash "${RUNNER_USER}"
usermod -aG docker "${RUNNER_USER}"

echo "[*] Fetching latest runner release"
RUNNER_VERSION=$(curl -fsSL https://api.github.com/repos/actions/runner/releases/latest | jq -r .tag_name | sed 's/^v//')
RUNNER_TARBALL="actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz"
RUNNER_URL="https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/${RUNNER_TARBALL}"

echo "[*] Installing runner ${RUNNER_VERSION}"
sudo -u "${RUNNER_USER}" mkdir -p "${RUNNER_DIR}"
cd "${RUNNER_DIR}"
sudo -u "${RUNNER_USER}" curl -fsSL -o "${RUNNER_TARBALL}" "${RUNNER_URL}"
sudo -u "${RUNNER_USER}" tar xzf "${RUNNER_TARBALL}"
rm -f "${RUNNER_TARBALL}"

echo "[*] Installing runner dependencies"
./bin/installdependencies.sh

echo "[*] Registering runner (ephemeral)"
sudo -u "${RUNNER_USER}" ./config.sh --unattended \
  --url "https://github.com/${OWNER}/${REPO}" \
  --token "${TOKEN}" \
  --name "${REPO}-runner-$(hostname -s)" \
  --labels "self-hosted,linux,x64,${REPO}" \
  --work "_work" \
  --ephemeral

echo "[*] Installing as systemd service"
./svc.sh install "${RUNNER_USER}"
./svc.sh start

echo "[*] Done. Runner is online and will re-register after each job."

Save it, chmod +x, run it with sudo.

The --ephemeral flag is the important part here, after each job the runner exits, the systemd unit restarts it, and it re-registers. Every job starts with the runner's own state clean, though the VM's disk is persistent. If you want a dedicated workspace per job, wrap your steps in a container using container: in your workflow, or add a cleanup step that runs rm -rf _work before each run.

The built-in svc.sh install approach re-registers after an ephemeral exit using the runner's stored credentials, which GitHub refreshes automatically as long as the runner deregisters cleanly. If you see runners stuck "stale" in the GitHub UI after a reboot, check journalctl -u actions.runner.*. Most of the time it's due to the registration credential that expired because the runner was offline too long, and re-running the provisioning script fixes it.

Labels, and routing jobs to the right runner

Labels are how you tell GitHub which runner to use. The default labels (self-hosted, linux, x64) aren't specific enough once you have more than one runner, because any job targeting self-hosted could land on any of them.

The script adds a repo-name label (${REPO}), which gives you a clean way to pin a workflow to its intended runner:

jobs:
  build:
    runs-on: [self-hosted, linux, x64, myrepo]

If you want a job to be able to land on any of your runners, say a quick linting job that doesn't care where it runs, drop the repo label and just use [self-hosted, linux, x64]. I don't do this in practice. The whole point of one runner per repo is to keep things deterministic, and "any runner could pick this up" leaks state across boundaries again.

Secrets!

Three places GitHub will let you store secrets: repo, environment, org. Don't place all secrets at org-level.

  • Repo secrets are the default. A workflow in that repo can read them; a workflow in another repo cannot. This is where most things should live.
  • Environment secrets add a second gate. The workflow has to target that environment, and you can require approvals, restrict branches, or wait for a timer before they're accessible. Use these for anything touching production.
  • Org secrets are shared across repos. Convenient for something like a shared container registry token, but a compromised workflow in any repo with access can exfiltrate them. Use sparingly and scope aggressively.

On the runner itself, avoid writing secrets to disk. ${{ secrets.FOO }} in a workflow is fine; it's masked in logs and lives in the process env only. Writing it to ~/.something/creds is asking for it to outlive the job.

Network posture

Self-hosted runners connect out to GitHub. They don't need inbound from the public internet, which is the whole reason this works behind a domestic NAT without port forwards.

What they do need is outbound HTTPS to api.github.com, *.actions.githubusercontent.com, and wherever your workflows actually pull from (Docker Hub, ghcr.io, npmjs.com, pypi.org, and so on). If you run an egress firewall, and you should, those are the domains that matter. GitHub publishes the current list in the meta API endpoint if you want to automate it.

What they also have is access to your LAN. A runner VM can reach your internal registry, your Postgres, and your Proxmox API if you're not careful. Decide what each runner needs to reach and put it on a VLAN that can only reach those things. Mine sit on a network that can talk to my internal registry and nothing else. Deployments happen by the runner pushing an image, and a separate pull-based mechanism picks it up on the target host.

Resource sizing

Real numbers from mine, measured during actual builds rather than guessed:

  • A SvelteKit + Fastify + PostgreSQL app: peaks around 2.5 GB RAM, 2 vCPU is fine, builds finish in a couple of minutes.
  • A Python + FastAPI service with Postgres tests: similar RAM footprint, but the test suite is CPU-bound; 4 vCPU is noticeably faster than 2.
  • Idle (the runner waiting for work): about 200 MB RAM, pretty much zero CPU.

I give each VM 4 vCPU and 4 GB RAM with ballooning enabled, and in Proxmox terms that costs almost nothing when they're idle. If you're tight on RAM, 2 GB is enough for most Node/Python builds as long as you're not doing anything exotic.

The runner workspace grows with every checkout, every pulled image, every built artifact, so you do need to watch the disk space. A periodic docker system prune -af and a workspace cleanup keeps it under control. I have a weekly cron on each runner VM:

0 4 * * 0 docker system prune -af --volumes && find /home/runner/actions-runner/_work -maxdepth 2 -mindepth 2 -type d -exec rm -rf {} +

It's aggressive, but it keeps 32 GB disks healthy.

Failure Modes

A few things before you encounter them:

  • The runner registers but never picks up jobs. Almost always a label mismatch between your workflow's runs-on and the runner's configured labels. Check the runner in the GitHub UI; the labels are shown there, and they need to be a superset of what the workflow asks for.
  • The runner goes offline after a Proxmox host reboot and won't come back. The actions.runner.* systemd unit should bring it back automatically, but the registration credentials can expire if the runner is offline too long. Re-run the provisioning script with a fresh token. It's idempotent enough that this works without tearing things down.
  • Docker-in-Docker jobs break. If a workflow uses services: or tries to start its own containers, they'll try to talk to the Docker socket. Mounting /var/run/docker.sock into a build container gives it root on the host, which is fine for your own code and dangerous for anything else. Prefer docker compose calls made from the runner directly over nested Docker inside a container step.
  • Disk fills up and jobs fail with cryptic errors. The cron above handles this. Also worth running df -h the first time a job fails for no obvious reason.

Wrapping Up

This pattern works well up to about five or six repos. Past that you're managing enough VMs that the per-repo isolation stops being worth the overhead, and you should probably look at Actions Runner Controller on Kubernetes, or ephemeral runner-per-job solutions like the official runner scale sets. But for a homelab or a small team with a handful of projects, five VMs you can each describe in one sentence is a perfectly fine operational surface.

Anyhow, the script means a new repo takes about ten minutes end to end: clone the VM template, run the provisioner, point the workflow at the right label. And most of that ten minutes is the Ubuntu installer, the actual runner setup is seconds.