Skip to content
Get started
The Zoomies handbook

GitHub Actions cache on self-hosted runners

A fresh runner for every job means a fresh, empty disk, so every job downloads its dependencies again. This page covers how to stop that on a Zoomies fleet.

Keep runners ephemeral. Retain selected cache data outside the runner's writable filesystem so the next runner can reuse downloads and build outputs. Losing a cache must only make a build slower; workspaces, credentials, runner registration and job state must not depend on it.

The pool cache and actions/cache

They do different jobs, and a workflow can use both.

  • The pool cache is a directory on the host, mounted at /opt/zoomies-cache in every runner the pool starts and kept between them. It saves the download and the rebuild, and it is an accelerator only: nothing guarantees a hit and an operator may empty it at any time.
  • actions/cache is the step to use for anything a workflow depends on, because the workflow asks for it by key and carries on if it misses.

Either way, a missing cache must make a job slower and never make it fail.

Data Lifetime and location Sharing rule
Runner registration and writable workspace One ephemeral runner/job Never reused as cache
Package downloads Host directory or managed volume selected by the pool cache configuration Scope by repository/trust boundary; package managers must tolerate concurrent writers
Setup-action toolchains Agent-kept cache, read-only in runners, separate writable link view per runner Scope by pool/repository and resolved runner image
Preinstalled image tools/libraries Runner image layers Immutable image reference; inventory inside image
DinD daemon state One runner's isolated sidecar lifetime Do not share live /var/lib/docker between daemons
BuildKit build cache External registry, or another explicitly managed BuildKit cache service Separate cache reference and write credentials per repository and trust boundary
Actions cache (actions/cache, the setup-* actions) A cache service on the host, when the pool turns it on, in the host's shared folder The pool cache's scope; a pull request reads its base branch and writes only its own, checked from the token's claim and not verified, so code that can reach the pool's cache address can forge it

Enable a pool cache

Open the pool's cache settings when creating or editing a pool. Enable the cache, choose its scope and source, and leave space for runner images and workspaces. These are pool settings, not top-level keys to paste into zoomies.yaml; the configuration reference explains every field.

cache:
  enabled: true
  scope: pool
  source: ""
  size_limit: 0
  tools: false

An empty source selects a daemon-managed volume. A non-zero size_limit requires an absolute host path; zero sets no size target. In a container deployment, put a size-limited cache under the shared folder, /var/lib/zoomies/shared/cache/pools, which the controller's container already mounts at its own path: the agent enforces the limit by measuring the folder, so it has to see it. A folder anywhere else needs the same mount, which zoomies upgrade offers to add. Use a pool cache only for repositories that may share its data. For a repository-target installation, scope: repository selects that repository automatically; an organisation target also needs repository: owner/name, and matching labels still decide which jobs GitHub can assign. Read the trust limits below before sharing it.

The mount is /opt/zoomies-cache. Enable tools: true as well to retain setup-action toolchains; keeping a tool cache explains its image scope and how it differs from package downloads.

Local cache scopes

Use the pool's existing cache scope and source settings, described in Hosts and pools. Persistent host caches help subsequent runners on the same host; they do not follow a runner to another pool host automatically. A repository-scoped cache name is not a security boundary on an organisation installation: GitHub may assign a different matching repository's job to that runner. Use repository-target installations or explicit trust-separated pools for strong isolation.

Cache identities now hash the full scope, immutable pool ID and canonical repository tuple, with a readable prefix. Tool generations also hash the resolved image reference. Renaming a pool does not relocate its cache; changing image identity creates a new tool generation. Old cache namespaces remain untouched for active runners and must be retired after they drain.

The writable per-runner tool view links to retained tools read-only. The entrypoint also exposes missing image-baked tools there, including completion markers used by setup actions. Existing retained tool entries take precedence. The image inventory is /usr/local/share/zoomies/installed-software.json; it lists installed distribution package versions and completed tool-cache entries, not a complete dependency SBOM.

Set cache size targets and leave disk reserve for image pulls, workspaces, daemon metadata and logs. Maintenance honours cancellation but eviction is not a quota and a busy cache may defer eviction. Monitor both free bytes and inodes. Cache and Docker filesystems may differ from the agent work filesystem.

Keeping the cache in memory

The pool cache cannot be a tmpfs of each runner's own. It is kept between runners, and a tmpfs belongs to one container and is gone when it is, so every runner would start with an empty cache, which is no cache. The form that works is a directory the host mounts in memory, given as the cache's source. It is bind-mounted into every runner like any other host path, so sharing, the in-use check and eviction all keep working.

# on each host that should keep it in memory; add it to /etc/fstab to survive a reboot
sudo mount -t tmpfs -o size=8g,mode=0777 tmpfs /var/lib/zoomies/shared/cache/pools
cache:
  enabled: true
  scope: pool
  source: /var/lib/zoomies/shared/cache/pools   # the mounted tmpfs
  size_limit: 6442450944                        # 6 GiB, inside the mount's 8g

Three things are different from a cache on disk:

  • Set a size limit. Memory is the host's disk here, and the limit is the only thing evicting from it. With none, the cache grows until the host has no memory left, which takes every runner and the agent with it. A source under /dev/shm with no limit is warned about as pool.cache_memory_unbounded. Keep the limit inside the mount's own size=, with room to spare.
  • It is lost at a reboot. A cache is disposable accelerator data and a missing one is recreated empty, so nothing breaks; the first runner after a restart just pays for the downloads again.
  • It is not charged to a runner's memory limit. The mount belongs to the host, so a job's cgroup is not where it is counted, but page cache a job dirties may be. Leave memory beyond the limit for the runners themselves.

A tool cache lives under the host's shared folder rather than the cache source, so it stays on disk unless that folder is the mount.

Serving the Actions cache from the host

The recipes below point a tool at /opt/zoomies-cache, which means editing every workflow. For the caches that go through GitHub's own cache protocol, which is actions/cache and the caches the setup-* actions keep, a pool can turn on Serve the Actions cache from the host instead (cache.service, or zoomies pools edit --cache-service) and change nothing: the cache calls go to a service on the host, and artifact calls still go to GitHub. How it works, what it needs and what it shares are in the configuration reference; the short version is that it needs one of the Zoomies runner images, it redirects JavaScript actions only, and a host that cannot run it leaves the runner on GitHub's cache.

It does not reach a plain run: step: go build, npm ci and docker build without a cache flag never ask the Actions cache for anything. Nor does it reach Buildx's type=gha layer cache by default, which BuildKit reads for itself; an experimental setting sends it to the host too. The registry and local recipes below are still how an image build is kept warm everywhere else, or a workflow that restores through an action.

Keeping the images a docker-in-docker job pulls

A pool with docker_mode: dind gets a fresh Docker daemon for every runner, and its storage starts empty, so every job pulls again the images it names, and Docker Hub limits anonymous pulls by the address they come from. A host can keep those images instead: turn on agent.registry_mirror.enabled and the agent keeps the public Docker Hub images its sidecars pull on the host's own disk and serves the next pull from there. How it works, what it holds and how to size it are in the configuration reference. What it does and does not cover:

  • Public Docker Hub images only. docker pull alpine, FROM node:22 and a service container from Docker Hub go through it. Images on ghcr.io, quay.io, a cloud registry or a private Docker Hub repository do not, because a daemon's registry-mirrors setting covers Docker Hub alone, and the mirror never holds a credential, so nothing private is ever kept.
  • The default sidecar image only. A pool that runs a sidecar image of its own, from agent.dind_image or the pool's dind_image, is where you keep your own daemon.json, and a mirror named in two places stops the daemon starting. So that pool is left exactly as you made it, and the advice to bake a mirror into your own sidecar image stays the right one for it. Zoomies tells you with pool.registry_mirror_unused when the mirror is on and a pool will not use it.
  • Not the host's own Docker daemon. A pool that uses the host's Docker socket pulls through that daemon, which the mirror does not touch. The mirror's port is chosen each time it starts, so it changes when the agent restarts, and an address written into /etc/docker/daemon.json would go stale. For those pools, run a pull-through cache of your own and point the daemon's registry-mirrors at it.
  • Not tested with Buildx builders. A docker-container builder runs its own BuildKit, which may not read the daemon's mirror.

A mirror only ever slows a pull down: if it cannot start, stops or cannot reach Docker Hub, the sidecar pulls from Docker Hub as it did before and no job fails. host.registry_mirror_degraded says when that is happening on a host that has a pool that would have used it, and what to do. The host's card says whether its mirror is on and, when it is not working, why and what to change; a host with no mirror says nothing. The mirror's figures (requests, hits, bytes served and kept, how long Docker Hub has been failing, and evictions) are the zoomies_registry_mirror_* series on /metrics, one set for each host, and are not on the card: they change with every pull, and a card that repainted for each would never be still.

It has not been measured on a real fleet, so this page makes no claim about how much time it saves. Measure it the way Verify the benefit says: the same job cold and warm, on a host with the mirror on and off.

Using the pool cache from a workflow

Zoomies mounts the cache and nothing more: it does not know which package manager a job runs, so a workflow has to point its tools at /opt/zoomies-cache. The recipes below do that in one step, and each keeps the rule the cache is built on; a missing or broken cache makes a job slower and never makes it fail. Every one creates its own folder under the cache and only uses it if that folder turned out writable, so the same workflow still runs on GitHub's hosted runners, on a pool with the cache off, on a cache folder whose permissions went wrong, and on the morning an operator emptied it.

The pool's scope names the cache namespace; it does not restrict which job GitHub assigns to an organisation runner. A workflow cannot turn a shared mount into a security boundary. Keep untrusted jobs on a separate pool without access to a trusted cache.

Go. The module and build caches are both safe to share between concurrent jobs; the Go toolchain locks and verifies them itself.

- name: Use the pool cache for Go
  run: |
    d=/opt/zoomies-cache/go
    if mkdir -p "$d/mod" "$d/build" 2>/dev/null && [ -w "$d/mod" ] && [ -w "$d/build" ]; then
      echo "GOMODCACHE=$d/mod" >> "$GITHUB_ENV"
      echo "GOCACHE=$d/build" >> "$GITHUB_ENV"
    fi

Set it before actions/setup-go, and give that action cache: false, so the job does not also upload the same modules to GitHub's cache.

npm. npm's cache is content-addressed and tolerates concurrent writers. Keep npm ci: it still installs node_modules fresh, it only stops downloading the tarballs again.

- name: Use the pool cache for npm
  run: |
    d=/opt/zoomies-cache/npm
    if mkdir -p "$d" 2>/dev/null && [ -w "$d" ]; then
      echo "npm_config_cache=$d" >> "$GITHUB_ENV"
    fi

pip. pip keeps downloads and built wheels in one folder, and a wheel built once is not built again.

- name: Use the pool cache for pip
  run: |
    d=/opt/zoomies-cache/pip
    if mkdir -p "$d" 2>/dev/null && [ -w "$d" ]; then
      echo "PIP_CACHE_DIR=$d" >> "$GITHUB_ENV"
    fi

Maven. The local repository is the one of the four that two jobs writing at once can corrupt, so the recipe turns on the file locking Maven 3.9 and later ship. On an older Maven, or a pool with max_runners above one and no locking, prefer actions/cache instead. It adds to any MAVEN_OPTS an earlier step set rather than replacing it.

- name: Use the pool cache for Maven
  run: |
    d=/opt/zoomies-cache/maven
    if mkdir -p "$d" 2>/dev/null && [ -w "$d" ]; then
      echo "MAVEN_OPTS=${MAVEN_OPTS:+$MAVEN_OPTS }-Dmaven.repo.local=$d -Daether.syncContext.named.factory=file-lock -Daether.syncContext.named.nameMapper=file-gav" >> "$GITHUB_ENV"
    fi

BuildKit. A pool with docker_mode: dind gives each runner a daemon that dies with it, so its layer cache goes too. Buildx can export that cache to a folder and read it back on the next runner. The local exporter needs a docker-container builder, which is what docker/setup-buildx-action creates.

The exporter writes a whole cache at once, and two jobs exporting to one folder (two runs, or two jobs of one matrix, which share a run ID) can leave a half-written one. So each job exports to a folder mktemp made for it alone, and when its build succeeds it publishes that folder by renaming a link over current, which is atomic: a reader sees the old cache or the new one, never half of either. When two jobs finish together the last one to rename wins, and the other's export is simply not used. ignore-error=true keeps a failed export from failing a build that otherwise succeeded, and a reader that finds its cache replaced mid-build gets a slower build, not a failed one.

The build itself always runs. Only the cache flags depend on the cache being usable, and a pull request reads the cache without writing to it (see below).

- uses: docker/setup-buildx-action@<pinned commit>
- name: Build, with the pool cache when it is usable
  run: |
    base=/opt/zoomies-cache/buildkit/app
    args=() src="" out=""
    if mkdir -p "$base" 2>/dev/null && [ -w "$base" ]; then
      if [ -f "$base/current/index.json" ]; then
        src=$(readlink -f "$base/current")
        args+=(--cache-from "type=local,src=$src")
      fi
      if [ "$GITHUB_EVENT_NAME" != pull_request ] && out=$(mktemp -d "$base/export.XXXXXX"); then
        args+=(--cache-to "type=local,dest=$out,mode=max,ignore-error=true")
      fi
    fi
    docker buildx build "${args[@]}" --tag app:ci .
    if [ -n "$out" ] && [ -f "$out/index.json" ]; then
      if ln -s "$out" "$out.link" && mv -T "$out.link" "$base/current"; then
        if [ -n "$src" ]; then rm -rf "$src"; fi
      else
        rm -rf "$out" "$out.link"
      fi
    elif [ -n "$out" ]; then
      rm -rf "$out"
    fi

Name the folder after the image and, if the pool builds for more than one platform, the platform too, so two builds do not replace each other's cache. The cache is not pruned by Buildx; the pool's size_limit is what bounds it. To share a cache across hosts rather than across runners on one host, use a registry cache instead, the recipe below shares layers without sharing a live daemon.

Pull requests. Everything a job writes to the cache is read by the jobs after it, so a pull request that can change the build can put something in the cache a later build on the default branch will use. GitHub's own cache stops that by letting a pull request read its base branch's entries and write only its own; a folder cannot. For workflows you control, the BuildKit recipe above reads but does not export on a pull request. Add if: github.event_name != 'pull_request' to the package-manager steps to leave those jobs using their normal cache folders. These are workflow conventions, not access controls: code with a writable mount can bypass them. Keep untrusted pull requests on a separate pool with no trusted cache mounted. Security explains why a public repository needs particular care with self-hosted runners.

DinD and BuildKit

A runner's DinD sidecar stays disposable. To benefit across runners and hosts, configure workflow-level BuildKit cache export/import to a registry. Example for an already authenticated registry and a Buildx builder:

# Set these to repository-specific references under your registry account.
: "${IMAGE_REF:?image reference required}"
: "${CACHE_REF:?repository-specific cache reference required}"
docker buildx build --push \
  --tag "$IMAGE_REF" \
  --cache-from "type=registry,ref=$CACHE_REF" \
  --cache-to "type=registry,ref=$CACHE_REF,mode=max" \
  .

This example requires a Buildx builder supporting the registry cache backend. Keep the cache reference separate from the image output. Grant cache publication credentials only to trusted workflows; untrusted pull requests should have no trusted-cache write credentials, and must not populate a cache consumed by privileged builds. Use distinct references for relevant architecture/toolchain/platform differences. Multiple concurrent writers to one reference can replace each other's cache manifest; use branch/job-specific write references and explicit shared trusted read references where needed.

Do not put secrets in build arguments, copied layers or cached outputs. Use BuildKit secret mounts for build-time credentials. Set registry retention separately from local Docker build-cache targets: the agent cannot prune a remote registry's cache.

The existing agent.docker_build_cache_mb policy acts on the outer daemon and defaults to zero (disabled); it does not manage isolated DinD caches or registry retention. Enabling daemon-wide pruning on a shared host needs an explicit ownership decision. Avoid broad docker system prune as an automatic cache policy.

Verify the benefit

Measure identical cold and warm jobs on the same host and across hosts. Record dependency download time, image preparation, BuildKit cached steps, queue-to-start time and total job time. Delete the cache and rerun to verify correctness. Compare storage/registry costs with time saved before expanding retention or baking more libraries into the image.

Cache size and the active shared folder

cache.size_limit is shared by packages, retained tool generations and the Actions cache service for a pool on each host. Idle maintenance runs on the agent's reconciliation tick, independently of new runner creation, so disk pressure that prevents placement no longer prevents cleanup. It checks both the daemon's containers and local starts/tool fills before deleting package or tool entries. Service eviction goes through its live budget and index. Active jobs can exceed this target; an uninterrupted stream of jobs can defer package/tool eviction until the pool is idle. A changed limit reaches the agent on its next heartbeat. Controller and agent both need this release for background maintenance and host-card measurements.

The Hosts card and host detail show cache bytes, with a package/tools/service breakdown in the tooltip, the measurement age and any deferral. These are apparent file sizes in each configured namespace, not allocated filesystem blocks. An older agent has no measurement, not a zero-sized cache. Incomplete measurements and daemon-managed package volumes are labelled partial or unknown. Old namespaces left after changing the source or scope are not included.

A folder under .config is not necessarily obsolete. A non-root Linux agent uses $XDG_CONFIG_HOME/zoomies or $HOME/.config/zoomies as its state directory unless ZOOMIES_STATE_DIR overrides it. With /var/lib/zoomies as the service account's home, its active shared directory can therefore be /var/lib/zoomies/.config/zoomies/shared. Package caches follow the pool's absolute cache.source; tools and the service follow that active shared folder. Maintenance includes both in the same pool budget even when the paths differ.

Before retiring a second shared folder, inspect the running service's ZOOMIES_STATE_DIR, HOME and XDG_CONFIG_HOME, and the daemon's container mount sources. Drain jobs and tool fills first. Move data only while the agent is stopped, update the service environment and any Compose bind mounts together, then verify the next runner's mounts before removing old data. Zoomies does not automatically delete or migrate an unidentified folder that could still be in use.

Last edited 2026-11-17 Improve this page Read as Markdown