Github Actions
This guide will walk you through setting up self-hosted GitHub Actions runners with Docker on your machine.
Create self hosted runner
A GitHub Actions self-hosted runner is a machine (physical or virtual) that runs workflows from GitHub Actions. Instead of using GitHub’s default cloud runners, you can self-host your own runner inside a Docker container to have more control over the environment.
Base runner image
Create the following Dockerfile:
|
|
Run the following command to create base runner image:
docker build -f Dockerfile.ga-base -t ga-base-image:latest .How to fix docker build error on macOS
Forcing docker to use linux/amd64 platform by default on macOS, during the build add this extra option:
--platform linux/amd64Runner image
Create the following Dockerfile:
|
|
Create the following entry point file:
|
|
Get the latest runner version from here, and then use the following command to create the runner image:
docker build --build-arg RUNNER_VERSION=2.321.0 -f Dockerfile.ga-runner -t ga-runner-image:latest .Run a Docker image as a container
Run the following command to start a container from the Ubuntu image and launch an interactive Bash shell:
docker run -i -t ubuntu:latest /bin/bashRun the runners
Create the following Docker-compose:
|
|
Create .env file as following:
|
|
Get the GH_TOKEN from here, and then run the following commnad to s:
docker compose -f docker-compose.yml up --scale runner=1 --no-recreate -dRun github workflows in local
Using the GitHub Act package, we can run actions locally, enabling faster feedback without the need to commit and push changes to GitHub for testing.
Getting started
Install Act on your machine using the following command:
brew install act # install act
act -l # list workflowsCreate actrc file in repo:
|
|
Create secrets file in repo and make sure it is added in .gitignore:
|
|
|
|