GitHub Actions Runner Images: A Software Engineer's Guide


GitHub Actions Runner Images: A Software Engineer's Guide

actions/runner-images

2025-07-20

Hello there! As a software engineer, you're likely familiar with the importance of automation in your development workflow. GitHub Actions provides a fantastic way to automate tasks directly within your GitHub repository, and at the heart of this automation are "runners." Think of a runner as a server with the GitHub Actions runner application installed, waiting to pick up and execute your workflow jobs.

The term "actions/runner-images" primarily refers to the pre-built virtual machine (VM) images that GitHub provides for its hosted runners. These images come with a vast collection of pre-installed tools and software, making it incredibly convenient to get started with CI/CD (Continuous Integration/Continuous Delivery) pipelines without having to configure everything from scratch.

Reduced Setup Time
Instead of spending time installing dependencies and tools for your build, test, or deployment processes, you can leverage the pre-installed software on these images. This dramatically speeds up the initial setup of your CI/CD pipelines.

Consistency
Using standardized runner images ensures that your workflows run in a consistent environment every time, regardless of who triggers them or when they are executed. This helps prevent "it works on my machine" issues.

Wide Range of Tools
GitHub-hosted runner images include a comprehensive set of development tools, SDKs, and runtimes for various programming languages (e.g., Node.js, Python, Java, .NET, Go) and operating systems (Ubuntu Linux, Windows, macOS). This broad support covers most software development needs.

Cost-Effective (for GitHub-hosted)
For public repositories, GitHub-hosted runners are free for a certain amount of usage minutes per month. For private repositories, you get a generous allowance before incurring charges, which can be more cost-effective than managing your own build infrastructure.

Self-Hosted Flexibility
While GitHub provides excellent hosted runners, you might encounter scenarios where you need more control, specific hardware, custom software, or to run workflows within your private network. This is where "self-hosted runners" come in, allowing you to create and manage your own runner images. You can customize these images to include exactly what your projects need, even caching tools for faster execution.

For most scenarios, you'll simply specify the desired operating system in your GitHub Actions workflow file (.github/workflows/*.yml). GitHub will automatically pick an appropriate hosted runner image.

Here's how you typically specify a GitHub-hosted runner

jobs:
  build:
    runs-on: ubuntu-latest # Or windows-latest, macos-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test

In this example

runs-on: ubuntu-latest tells GitHub Actions to use the latest Ubuntu Linux runner image.

The actions/setup-node@v4 action utilizes the pre-installed Node.js on the runner image (or installs a specific version if not present) and configures the environment.

If you need a custom environment or want to run on your own infrastructure, you can set up a self-hosted runner. This involves creating your own runner image. While the actions/runner-images repository provides the definitions for GitHub's hosted images, you would typically build your own Docker image for a self-hosted runner.

Here's a simplified example of a Dockerfile for a custom self-hosted runner, extending the official GitHub Actions runner image and adding some custom tools

# Start from the official GitHub Actions runner base image
FROM ghcr.io/actions/actions-runner:latest

# Set environment variables for the runner user
ENV UID=1001
ENV GID=121
ENV USERNAME="runner"
ENV HOME="/home/${USERNAME}"

# Create the runner user and set up the home directory
RUN groupadd --gid $GID $USERNAME \
    && useradd --uid $UID --gid $GID -m $USERNAME \
    && usermod -aG sudo $USERNAME \
    && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME

# Switch to the runner user
USER $USERNAME

# Set the working directory
WORKDIR $HOME/actions-runner

# Install any additional tools your workflow needs (example: Python and pip)
# You'd typically do this as root before switching user, but for simplicity
# we'll show it here. In a real scenario, you'd want to keep the image lean.
USER root
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

# Back to runner user for runner application
USER $USERNAME

# Copy your runner application files (usually downloaded from GitHub)
# In a real scenario, you'd download and install the runner application here.
# For example:
# RUN curl -o actions-runner-linux-x64-2.308.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.308.0/actions-runner-linux-x64-2.308.0.tar.gz \
#    && tar xzf actions-runner-linux-x64-2.308.0.tar.gz \
#    && rm actions-runner-linux-x64-2.308.0.tar.gz

# This part is for running the runner agent (simplified)
CMD ["./run.sh"]

How to Use This Custom Image

Build the Docker Image

docker build -t my-custom-runner:latest .

Run the Self-Hosted Runner
You'll typically run this Docker image on a server or VM, register it with your GitHub repository or organization, and provide a Personal Access Token (PAT).

docker run -e RUNNER_NAME="my-awesome-runner" \
           -e REPO_URL="https://github.com/your-org/your-repo" \
           -e ACCESS_TOKEN="YOUR_PAT_TOKEN" \
           my-custom-runner:latest

(Note: The exact environment variables and registration process will depend on the self-hosted runner application. Refer to the official GitHub Actions documentation for the most up-to-date instructions.)

Specify in Workflow
In your .github/workflows/*.yml file, you would then specify your custom runner using labels

jobs:
  my-custom-build:
    runs-on: [self-hosted, linux, my-custom-label] # Use labels you defined during runner registration
    steps:
      - uses: actions/checkout@v4
      - name: Run custom script
        run: |
          echo "Hello from my custom runner!"
          # Use your custom installed tools here

In essence, actions/runner-images represents the diverse, pre-configured environments that empower your GitHub Actions workflows, whether you're using GitHub's hosted solutions or building your own custom runners for specialized needs!


actions/runner-images