Skip to content

pavlovic-ivan/ephemeral-github-runner-image

Repository files navigation

GCP Build AWS Build GCP Lint AWS Lint Latest release releases licence Awesome

Introduction

This repository is used to build a GCP Machine Image for ephemeral Github Actions self-hosted runners using Packer. The image is based on Ubuntu 20.04 v20220308, with NVIDIA drivers v510.47.03 and GitHub Actions Runner v2.288.1. Check Usage section for how to use this image within your IaaC.

Guidelines

Local development

For local development, you can use Visual Studio Code dev container to open your local checkout in a container.

You will then need to init Packer with:

packer init .

The next step is to create a GCP service account and save its credentials in JSON format as gcp.json.

You can then create a local .env file with the following content:

export GOOGLE_APPLICATION_CREDENTIALS=gcp.json
export PKR_VAR_project=<your GCP project ID>

Finally you can build the image with:

packer build .

CI

Github Actions workflow runs only on push to main, and will automatically build and publish the new image.

Usage

This VM Machine Image will:

  • create runner user and it's home directory
  • create working directory inside the home directory: /home/runner/runner
  • inside the working directory unpack the Github Actions Runner package with available bash scripts:
    • config.sh
    • run.sh

Here is an example script that registers and runs the Github Actions Runner in ephemeral mode:

su - runner -c "cd runner && \
                  ./config.sh \
                    --url https://github.com/{{owner}}/{{repo}} \
                    --token {{token}} \
                    --labels {{labels}} \
                    --disableupdate \
                    --unattended \
                    --ephemeral"

cd ~runner/runner
./svc.sh install runner
./svc.sh start