Using Self-Hosted Github Actions Runner

Gao

When creating a rust project, my ci system has encountered a CI problem. The Github Actions can not finisht build, the process had taken too much resources.

To Fix this, I had to use a Self-Hosted Actions Runner. Here is How to do this.

1. Create VM

Create an VM at host machine with 24-cores, 64GiB memory and 200GiB disk space.

Select OS with Ubuntu 22.04.

2. Prepare ENV

Prepare

ansible-playbook playbooks/ubuntu/update-apt.yml --extra-vars=host=github-runner

Install

apt install curl apt install build-essential apt install git

Create User

useradd -d /opt/actions-runner -M -N actions-runner

3. Install Action Runner

Go to page https://github.com/organizations/gsmlg-dev/settings/actions/runners and click New Runner Button, select new Self-Hosted Runner.

Go in to /opt folder and follow the download steps.

Wrap the config command with su

su actions-runner -c './config.sh --url https://github.com/gsmlg-dev --token <TOKEN>'

Full config options

Commands:
 ./config.sh         Configures the runner
 ./config.sh remove  Unconfigures the runner
 ./run.sh            Runs the runner interactively. Does not require any options.

Options:
 --help     Prints the help for each command
 --version  Prints the runner version
 --commit   Prints the runner commit
 --check    Check the runner's network connectivity with GitHub server

Config Options:
 --unattended           Disable interactive prompts for missing arguments. Defaults will be used for missing options
 --url string           Repository to add the runner to. Required if unattended
 --token string         Registration token. Required if unattended
 --name string          Name of the runner to configure (default github-runner)
 --runnergroup string   Name of the runner group to add this runner to (defaults to the default runner group)
 --labels string        Extra labels in addition to the default: 'self-hosted,Linux,X64'
 --local                Removes the runner config files from your local machine. Used as an option to the remove command
 --work string          Relative runner work directory (default _work)
 --replace              Replace any existing runner with the same name (default false)
 --pat                  GitHub personal access token with repo scope. Used for checking network connectivity when executing `./run.sh --check`
 --disableupdate        Disable self-hosted runner automatic update to the latest released version`
 --ephemeral            Configure the runner to only take one job and then let the service un-configure the runner after the job finishes (default false)

Examples:
 Check GitHub server network connectivity:
  ./run.sh --check --url <url> --pat <pat>
 Configure a runner non-interactively:
  ./config.sh --unattended --url <url> --token <token>
 Configure a runner non-interactively, replacing any existing runner with the same name:
  ./config.sh --unattended --url <url> --token <token> --replace [--name <name>]
 Configure a runner non-interactively with three extra labels:
  ./config.sh --unattended --url <url> --token <token> --labels L1,L2,L3

Test actions-runner is configured success.

su actions-runner -c ./run.sh

4. Create Service

# Install ./svc.sh install actions-runner # start ./svc.sh start # check status ./svc.sh status

5. Use Runner in Actions

Config in yaml

runs-on: [self-hosted, linux, x64, hpc]

6. Add Envirionment to Runner

Edit file /etc/systemd/system/multi-user.target.wants/actions.runner.<group>.<name>.service, Add

Environment=http_proxy=http://proxy-server:8080 Environment=https_proxy=http://proxy-server:8080 Environment=no_proxy=localhost,localnet