Commit 22c415c6 authored by Kevin Daudt's avatar Kevin Daudt 💻
Browse files

register-runners: adjust to be more flexible

Instead of hardcoding 2 runners to be registered, you can add profiles
to a directory to specify what runners should be registered.
parent 134da444
Pipeline #5134 passed with stages
in 6 minutes and 27 seconds
......@@ -5,9 +5,8 @@ ENV SSL_CERT_FILE /etc/ssl/cert.pem
RUN apk add -U --no-cache gitlab-runner
COPY register-runner entrypoint /usr/local/bin/
COPY register-runners entrypoint /usr/local/bin/
VOLUME ["/etc/gitlab-runner", "/home/gitlab-runner"]
VOLUME ["/etc/gitlab-runner"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
CMD ["run", "--user=gitlab-runner", "--working-directory=/var/lib/gitlab-runner"]
# gitlab-runner docker image
[![pipeline status](](
This will create a docker image for running a gitlab runner on Alpine Linux on
all the architectures that Alpine Linux supports.
## Starting the runner
## Profiles
At startup, it will look for profiles in /data/profiles. These are files with
variables that define how that specific runner is registered. Look at the help
output of `gitlab-runner register --help` to see what variables are supported.
Note that variables are automatically exported (so no need to use `export`).
The following variables are required:
* `REGISTRATION_TOKEN` - The gitlab to use to register the runner. This can be
found in the project and group CI/CD settings, or in the admin section for
shared runners.
* `RUNNER_NAME` - The name of the runner in order to identify it.
There is a `docker-compose.yml` file included that starts up the runner. The
registration of the runner will be done automatically, but you need to provide a
`.env` file with some parameters. There is an `example.env` file that you can use
as a template.
The following variables have a default set, but can be overridden:
* `GITLAB_REGISTRATION_TOKEN_SHARED` - The gitlab registration token (you can
find it in the admin pannel under runners)
* `GITLAB_REGISTRATION_TOKEN_DOCKER` - The gitlab registration token for the
dedicated docker image runner. This token should come from a project or group.
* `ARCH` - The architecture for this runner (used as a description and tag).
| Variable | Default Value |
| `DOCKER_IMAGE` | `alpine:latest` |
| `RUNNER_LIMIT` | 1 |
Then run `docker-compose up -d` and the runner should be running.
if [ ! -f /etc/gitlab-runner/config.toml ]; then
echo "Runner is not configured. Please provide 'GITLAB_REGISTRATION_TOKEN'"
exit 1
register-runner || exit $?
set -eu
exec gitlab-runner "$@"
echo "-> Registering runner $ARCH"
gitlab-runner register \
--non-interactive \
--url "" \
--registration-token "$GITLAB_REGISTRATION_TOKEN_SHARED" \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner ($ARCH)" \
--tag-list "docker-alpine,$ARCH,ci-build" \
--run-untagged="false" \
--locked="false" \
--access-level="not_protected" \
--limit=2 \
--output-limit=102400 \
--docker-helper-image alpinelinux/gitlab-runner-helper:latest || success=0;
gitlab-runner register \
--non-interactive \
--url "" \
--registration-token "$GITLAB_REGISTRATION_TOKEN_DOCKER" \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner-docker ($ARCH)" \
--tag-list "docker-alpine,$ARCH,ci-docker-image" \
--run-untagged="false" \
--locked="true" \
--access-level="not_protected" \
--limit=1 \
--docker-helper-image alpinelinux/gitlab-runner-helper:latest \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock || success=0;
if [ $success -eq 1 ]; then
echo "-> Registration success"
echo "-> Something went wrong"
exit $status
set -eu
for profile_path in /data/profiles/*; do
if ! [ -e "$profile_path" ]; then
echo "No profiles found in /data/profiles, exiting"
exit 1
profile=$(basename "$profile_path")
if [ -e "$registered_runners" ] && grep -xq "$profile" "$registered_runners"; then
echo "-> Runner '$profile' already registered, skipping"
# subshell to isolate variables
set -a # automatically export variables
# shellcheck disable=SC1090
. "$profile_path"
set +a
if [ -z "$REGISTRATION_TOKEN" ]; then
echo "Required environment variable \$REGISTRATION_TOKEN is not set."
if [ -z "$RUNNER_NAME" ]; then
echo "Required environment variable \$RUNNER_NAME is not set."
export DOCKER_IMAGE=${DOCKER_IMAGE:-alpine:latest}
gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-helper-image alpinelinux/gitlab-runner-helper:latest
echo "-> Registration of '$profile' successful"
echo "$profile" >>/etc/gitlab-runner/registered-runners
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment