This tutorial is adapted from the Web Age course https://www.webagesolutions.com/courses/WA3243-advanced-gitlab-administration.
Part 1 – Gather Necessary Info
We will need the URL of GitLab server and a runner registration token.
1. Log into GitLab as root.
2. In the browser, click the hamburger icon to expose the menu and then click Admin.
3. Click Runners from the navigation menu.
4. Click Register an instance runner.
5. Copy the registration token and save it somewhere. We will need it soon.
6. Open a new Terminal.
7. We will now get the internal IP address of the GitLab server. Run this command:
docker inspect gitlab | grep IPAddress
8. You should get the IP, save the IP address somewhere. We will need it soon.
Part 2 – Register the Runner
1. Run this command:
docker run --rm -it \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
gitlab/gitlab-runner register
2. Enter the following values:
Parameter | Value | Remarks |
GitLab instance URL | http://IP address | This is the URL that the runner will connect to GitLab with. If GitLab and the runner are running inside Docker containers or K8s cluster, then you need to make sure that this URL is reachable. Use the IP address you obtained earlier. |
Registration token | Enter the value you had copied earlier | |
Description | My Runner | This is a name for the runner |
Tags for the runner | Leave this empty | |
Maintenance note | Leave empty | |
Executor | docker | An executor is a platform such as Docker container, Kubernetes and remote SSH session that runs a CI/CD job. |
docker image | ruby:2.7 |
Make sure you see the Runner registered successfully message:
__
3. Back in the GitHub web site, refresh the Runners page. You should see the runner.
4. Since our GitLab server does not have a proper host name registered in DNS, the runner will have difficulty finding it. We will do a workaround to fix that. Edit the configuration files as follows:
sudo gedit /srv/gitlab-runner/config/config.toml
[Enter wasadmin as password]
5. Make these two changes shown in bold face below.
- Add “/var/run/docker.sock:/var/run/docker.sock”
- At the end of the file, add the extra_hosts variable, make sure to replace with your IP address from previous steps.
[runners.docker]
tls_verify = false
image = "ruby:2.7"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
shm_size = 0
extra_hosts=["gitlab.example.com:"]
For example:
- Save and close the file.
- Restart GitLab Runner:
docker stop gitlab-runner
docker start gitlab-runner
Part 3 – Review
In this tutorial, we registered a runner with our GitLab instance. We are now ready to start
defining the CI/CD pipeline.