No description
  • Shell 91.1%
  • Dockerfile 8.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Razvan M. a88f6943a7
Some checks failed
/ image (push) Failing after 12m22s
release skill: watch runs, not tasks, and push once
actions/tasks doesn't list queued jobs, and a second push cancels the build
already running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:33:04 +02:00
.claude/skills/release release skill: watch runs, not tasks, and push once 2026-11-27 20:33:04 +02:00
.forgejo/workflows Version images as YYYY.MM-<run> and release every build 2026-11-27 20:31:52 +02:00
test End a VM when Forgejo deletes its runner mid-job 2026-11-27 20:32:04 +02:00
compose.yaml Start VMs on demand for sizes RUNNERS doesn't list 2026-11-26 23:31:33 +02:00
Dockerfile Start VMs on demand for sizes RUNNERS doesn't list 2026-11-26 23:31:33 +02:00
entrypoint.sh End a VM when Forgejo deletes its runner mid-job 2026-11-27 20:32:04 +02:00
LICENSE Initial commit 2026-11-17 14:30:49 +02:00
README.md Version images as YYYY.MM-<run> and release every build 2026-11-27 20:31:52 +02:00
runner.yml kinda agi, builds itself 2026-11-17 18:26:59 +02:00
vm-init.sh Start VMs on demand for sizes RUNNERS doesn't list 2026-11-26 23:31:33 +02:00

Forgejo Actions in Firecracker microVMs

Every CI job runs in its own throwaway VM with its own kernel and its own Docker. You pick the VM size per job, Blacksmith-style:

jobs:
  build:
    runs-on: fc-4vcpu-16gb # 4 vCPUs, 16 GB of RAM
host
└─ runner container         (entrypoint.sh: network, base disk, templates, one loop per runner slot)
   ├─ Firecracker microVM   (vm-init.sh: dockerd + forgejo-runner one-job)
   │  └─ job containers
   └─ … one VM per slot in RUNNERS, plus one per queued job of any other size (on demand)

Use it

  1. Check that the host has KVM: ls /dev/kvm. On a cloud VM, this needs nested virtualization.
  2. In Forgejo, go to Settings → Actions → Runners → Show registration token and copy the token. This works at site, org or repo level. Don't use Create new runner: it gives a UUID and token for a single fixed runner, which isn't what this setup needs. From the server shell, forgejo actions generate-runner-token gives the same registration token.
  3. Put FORGEJO_URL and RUNNER_TOKEN into compose.yaml, set RUNNERS, then run docker compose up -d --build. The first build compiles the kernel, which takes about 3 minutes.
  4. In your workflows, use runs-on: fc-<N>vcpu-<M>gb for any size listed in RUNNERS.
  5. Optional, for any other size on demand: create an API token (Settings → Applications) that can read the level the registration token came from (read:admin for site level), put it into FORGEJO_TOKEN, and set FORGEJO_SCOPE to match. Needs Forgejo 15 or later.

docker compose logs runner shows every VM's console, prefixed with its slot, e.g. [fc-4vcpu-16gb#3].

Settings (compose environment)

Variable Default
FORGEJO_URL (required)
RUNNER_TOKEN (required) Registration token. It stays in the container and never enters a VM, and neither does FORGEJO_TOKEN.
RUNNERS 2vcpu-8gb=1 How many VMs of each size to keep warm, e.g. 2vcpu-8gb=4 8vcpu-32gb=1. Each one runs one job at a time and gets the label fc-<N>vcpu-<M>gb. RAM is a ceiling: a VM only uses what it touches, and an idle one sits at about 250 MB. Empty (RUNNERS: "") keeps none warm, so every job is on demand.
JOB_IMAGE ghcr.io/catthehacker/ubuntu:act-24.04 The job container when a workflow doesn't set container:. It's pulled into the base disk at startup, so jobs don't pull it. The default is Ubuntu 24.04 with what workflows expect from GitHub's runner: sudo, the Docker CLI, Node 20/24, jq, Python, and the env vars setup-* actions read.
VM_DISK_GB 20 Disk per VM. Sparse: it only uses what the job writes.
FORGEJO_TOKEN (unset) API token that turns on on-demand sizes. Read access is enough.
FORGEJO_SCOPE admin Where to look for queued jobs: admin (whole site), orgs/<org>, repos/<owner>/<repo> or user. Use the level the registration token came from.
REGISTRY_MIRROR (unset) Docker Hub pull-through cache. The compose file points it at the bundled registry.

Limits for all VMs together: set cpus: and mem_limit: on the runner service. Every VM is a process inside the container, so Docker's limits cover all of them at once. At startup the log prints what RUNNERS adds up to next to the limit.

  • CPU: going over is fine. Each VM still sees its full vCPU count, but busy VMs share the CPU time and run slower.
  • RAM: going over is a bet that not every VM is busy at once. A VM only uses the RAM it touches, but a long build can touch nearly all of it, because Linux fills spare RAM with cache. If the busy VMs together go over mem_limit, the kernel kills one of them and its job fails. To rule that out, set mem_limit to at least the sum of the RAM in RUNNERS plus about 1 GB.

On-demand sizes

With FORGEJO_TOKEN set, a job can ask for any size, not only the ones in RUNNERS. Every 3 s the container asks Forgejo for queued jobs. For each job whose runs-on is a single fc-<N>vcpu-<M>gb label that RUNNERS doesn't list, it starts one VM. That VM claims exactly that job by its handle (forgejo-runner one-job --handle) and is thrown away afterwards.

  • The first job of a new size builds that size's template first, which adds a few seconds. Later jobs of that size restore it like a warm slot does.
  • Sizes in RUNNERS stay with their warm slots. On-demand VMs never start for them, even when those slots are busy. An on-demand VM racing an idle slot for a job would leave an unused runner behind.
  • RAM cap: on-demand VMs together never get more RAM than mem_limit (or the host's RAM if it isn't set). A job that doesn't fit waits until one finishes, and the log says so once. Warm VMs don't count against this cap, so warm and on-demand VMs together can still go over mem_limit, with the same risk as above.

How it works

At startup:

  1. mke2fs -d turns the guest filesystem shipped in the image into a 20 GB sparse base.ext4.
  2. A one-time "bake" VM boots on base.ext4, pulls JOB_IMAGE into it, and shuts down. From then on, base.ext4 is never written again.
  3. For each size in RUNNERS, a template VM boots up to "Docker is running, waiting for a job". Firecracker snapshots it there. The snapshot only stores the memory the VM touched, about 500 MB for an 8 GB VM.

Per job, in each slot:

  1. Register an ephemeral runner. Forgejo deletes it after one job, so a job that breaks out into the VM finds no reusable credential.
  2. Restore a VM from its size's template. That skips the boot and the Docker startup entirely.
    • Its root disk is a device-mapper snapshot: reads come from the shared base.ext4, and writes go to a private sparse cow.img. Each job starts with a copy of the template's ~30 MB cow.img.
    • Clones share the template's memory file through the host page cache.
  3. The VM fetches its config over vsock: IP, current time, and the runner file. It runs forgejo-runner one-job --wait, reports the exit code over vsock, and reboots, which ends Firecracker. The slot deletes the VM's files and starts over.
  4. A non-zero exit code means the runner itself broke (a failed job still exits 0), so the slot waits 30 s before retrying.

Networking: VM n is 172.16.1.n on tap<n>, behind NAT. Every tap has the same gateway address, so all clones of a snapshot see an identical network. VMs can't reach each other. Their DNS goes to dnsmasq in the container, so compose service names such as registry resolve from VMs and job containers.

Measured with test/run.sh (3 jobs on 2vcpu-8gb=2 4vcpu-16gb=1, node:22-bookworm):

Version Wall time for 3 jobs
Cold boot, fresh disk 25 s
+ shared disk with baked image 7 s
+ snapshot restore 6 s

The image went from 1.5 GB to 553 MB.

Files

  • Dockerfile: builds the kernel (kernel.org 6.18 with Firecracker's guest config, plus device-mapper), the guest filesystem (Alpine + Docker + git + forgejo-runner), and the final Alpine image. All versions are at the top.
  • entrypoint.sh: startup and the per-slot loop.
  • vm-init.sh: PID 1 inside every VM.
  • runner.yml: forgejo-runner settings inside every VM. It mounts the VM's Docker into job containers, so jobs can docker build, docker run and docker push. That's safe because the VM is thrown away after the job.
  • compose.yaml: what you deploy.
  • .forgejo/workflows/image.yml: builds this image on its own fc-4vcpu-8gb runners and pushes it to pkg.bar/firecracker-forgejo-actions (:<year>.<month>-<run number> and :<commit> always, :latest from main) and creates a Forgejo release for every push to main (a prerelease for every PR). It needs the repo secrets REGISTRY_USERNAME and REGISTRY_PASSWORD. A build takes about 6 minutes on 4 vCPUs, mostly the kernel.
  • test/run.sh: end-to-end test. It spins up a throwaway Forgejo, pushes jobs of two warm sizes and one on-demand size, and checks each job's vCPU count, RAM and clock, and that a job can docker build. KEEP=1 ./run.sh leaves the stack running afterwards for poking around.

Known limits

  • Jobs can reach anything the container can, such as your LAN and Forgejo. Cloud metadata (169.254.0.0/16) and other VMs are blocked. Add iptables -A FORWARD -i tap+ -d <net> -j DROP lines in entrypoint.sh to fence off more.
  • Stopping the container leaves one offline runner per idle slot in Forgejo's list. They never ran a job, so Forgejo never deleted them. The same happens when a job is cancelled after its on-demand VM registered. Remove these by hand if they bother you.
  • Sizes are fixed per slot. A queued fc-8vcpu-32gb job waits for that exact size even if smaller slots are idle. Without FORGEJO_TOKEN, a size that isn't in RUNNERS never runs.
  • JOB_IMAGE is pulled once per container start. Restart the container to pick up a newer image under the same tag.
  • Snapshots use Firecracker's "diff" type, which Firecracker labels developer preview. It works here, but if a Firecracker upgrade breaks restore, switch make_template to a Full snapshot.
  • Clones of one template share state the kernel doesn't reseed. Firecracker's VMGenID reseeds the kernel's random numbers on every restore, and the runner starts fresh after restore. But dockerd was already running in the template, so its own in-memory state is identical across clones. That only affects things like generated container names.
  • The kernel has a one-line patch that allows the snapshot target in dm-mod.create=.
  • actions/cache starts empty every job, because its cache server lives and dies with the VM. The same goes for Docker's build cache, so every image build starts from scratch.
  • The mirror only caches Docker Hub. Pulls from ghcr.io, quay.io and others go straight out.
  • arm64 is wired in but untested. The Dockerfile picks the right kernel config, kernel image and binaries via uname -m/TARGETARCH. Build it on an arm64 machine: cross-building the kernel under QEMU emulation takes hours.

AI disclosure

Project was made using an LLM, the idea around it is human