APNIC 56 Network Automation tutorial
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Gitlab runner setup

Setup Gitlab Runner on your server

Step 1 - Setup docker image of the runner

  1. Create directory for runner config
a01@server:~$ mkdir runner
a01@server:~$ cd runner/

  1. Setup docker container for runner
docker run -d --name gitlab-runner --restart always \
  -v /home/a01/runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

  1. Ensure the runner is up
a01@server:~/runner$ docker container list | grep runner
4f55bead3675   gitlab/gitlab-runner:latest            "/usr/bin/dumb-init …"   About a minute ago   Up About a minute                                                                                              gitlab-runner
a01@server:~/runner$


Step 2 - Register runner with the Gitlab Project

Visit Gitlab project > Settings > CI/CD > Runner and findout registration token

Run a one-time container to register

docker run --rm -it -v /home/a01/runner/config:/etc/gitlab-runner gitlab/gitlab-runner register

Sample output and config options:

a01@server:~$ docker run --rm -it -v /home/a01/runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=6 revision=76984217 version=15.1.0
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com/

Enter the registration token:
GR1348941N3Grwefwfwfwewefch

Enter a description for the runner:
[25031f80bc82]: a01

Enter tags for the runner (comma-separated):
<leave empty>

Enter optional maintenance note for the runner:

Registering runner... succeeded                     runner=GR1348941N3GrsSrd

Enter an executor: docker-ssh, docker+machine, docker-ssh+machine, docker, parallels, shell, ssh, virtualbox, kubernetes, custom:
docker

Enter the default Docker image (for example, ruby:2.7):
alpine:latest

Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
a01@server:~$

Edit the runner in Gitlab project > Settings > CI/CD > Runner and check “Indicates whether this runner can pick jobs without tags” and save.



Step 3 - (Optional) Allow docker’s privilaged mode in the config

This is an optional step and is needed if buidling container images using the runner. This does comes at a cost o reducing security. More details about it are here.

Detailed instructions here on Gitlab website.

  1. Edit /home/a01/runner/config/config.toml (Note sudo would be needed to edit it due to permissions issue).

Change privileged = false to privileged = true under the section [runners.docker]

  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = true

Save & edit.

  1. Restart docker container to apply new config
a01@server:~$ docker container restart gitlab-runner
gitlab-runner
a01@server:~$