Monday 11 October 2021
Gitlab CI/CD is a DevOps tool integrated into Gitlab to be able to make continuous integration, continuous delivery and continuous deployment. In order to use this tool you must use the Gitlab Runners, which are applications that are responsible for running the Gitlab CI/CD pipeline jobs.
Although Gitlab servers may have shared runners that any user can use, we may be interested in having one or more Runners in our machine. In this article we will explain how you can do it quickly and easily.
Installation using Docker containers
There are multiple ways to install a Runner on a machine, but the most flexible way and the one we will explain in this article is using Docker containers
The requirements to be able to install and use a Runner with Docker are as follows:
- Have a machine with Docker installed and understand its basic operation
- Have a Runners registration token in a Gitlab group or project
To obtain the registration token you only have to go to the group or project where we want to register the Runner and access "Settings -> CI/CD -> Runners".
It is important that you keep the token secret, since using this token anyone can register a Runner in your project and potentially gain access to the files. If you leak it, press the "Reset registration token" button to get a new one.
Un cop obtingut el token de registre cal crear el contenidor que s’encarregarà d’executar els Runners. Per fer-ho cal executar les següents comandes amb permisos d’administrador:
Once the registration token is obtained, you must create the container that will be in charge of running the Runners. To do this, you must execute the following orders with
docker volume create gitlab-runner-config docker run -d --name gitlab-runner --restart always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v gitlab-runner-config:/etc/gitlab-runner \ gitlab/gitlab-runner:latest
The next step is to register a Runner to run our pipelines. This can be done by running the following order and supplying the data it requests:
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner
Finally, you have to go to Settings, CI/CD, Runners and see if the Runner appears in the "Available specific runners" section.
If it appears it is that everything has gone well and we can already use it to run our pipelines. In case it is necessary to have more Runners, just repeat the order used to register a new one.