Based on the official Docker image of Github's action runner, this Docker image provides an easy way spin up a self-hosted GitHub Action Runner.
Upon shutdown the runner will automatically be disconnected from the GitHub repository, per default.
services:
github-runner:
image: ghcr.io/stonemaster/github-actions-runner:main
container_name: githubrunner
restart: always
environment:
- GITHUB_REPO_URL=https://github.com/stonemaster/github-actions-runner
- RUNNER_TOKEN=Example: https://github.com/stonemaster/github-actions-runner
The https URL of the GitHub repository or that of a GitHub organization.
- If
RUNNER_TOKENis set, it will be used as the registration token. Those tokens expire and are best suited for short-lived runners. The runner token can be fetched in GitHub settings on the new self-hosted runner configuration page. - If
GITHUB_REGISTRATION_TOKENis set, it will to fetch a new registration token for this runner. A fine-grained personal access token (PAT) with the Self-hosted runnerswritepermission is required to use this option. See the official documentation.
![NOTE]
RUNNER_TOKENhas precedence overGITHUB_REGISTRATION_TOKENif both are set.
These environment variables contain Base64 encoded scripts. If set they will be
run before starts and after a job has completed. As per the offical
documentation
these scripts should be written in bash or sh. The container makes sure the
scripts are executable after decoding them.
Scripts can easily be converted into Base64 on the command-line and then used as an environment variable:
$ cat script.sh
#!/bin/bash
echo "Hello World!"
$ base64 script.sh
IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gV29ybGQhIgo=Add the Base64 string as an environment variable:
[...]
environment:
- RUNNER_TOKEN=123
- PRE_JOB_SCRIPT=IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gV29ybGQhIgo=
[...]Similar to the PRE_JOB_SCRIPT and POST_JOB_SCRIPT environment variables
this allows to specify a Base64-encoded script to be run at shutdown of the
runner. The script is run after disconnecting the runner from GitHub.