How to Bake Dependencies Into a Self-Hosted Runner Image in GitHub Actions
Baking compilers, SDKs, and system packages into the runner image removes repeated install time from every job.
Build a golden image (an AMI with Packer, or a container image) that already has your toolchain. Jobs then start with everything installed instead of running apt or brew on every run.
Steps
- List the tools every job installs at runtime today.
- Add them to a Packer template or Dockerfile.
- Build a versioned image and roll it out to the runner fleet.
- Drop the per-job install steps from your workflows.
Dockerfile layer
Dockerfile
FROM ghcr.io/actions/actions-runner:latest
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake jq awscli \
&& rm -rf /var/lib/apt/lists/*
USER runnerGotchas
- Pin tool versions in the image so builds stay reproducible.
- Rebuild and re-roll the image on a schedule to pick up security updates.
- GitHub publishes the
actions/runner-imagesdefinitions you can mirror as a starting point.
Related guides
How to Run Self-Hosted Runners in Docker in GitHub ActionsRun a self-hosted GitHub Actions runner inside a Docker container with a JIT or ephemeral token, so each job…
How to Migrate GitHub-Hosted Jobs to Self-Hosted Runners in GitHub ActionsMove GitHub Actions jobs from hosted to self-hosted runners by changing runs-on labels, then reconciling pre-…