GitLab is an emerging tool that empowers one of the pillars of DevOps called the CICD Pipeline. Just like we have executors in Jenkins, GitLab has Runners that will act as an application on demand and executes the commands and instructions defined in the GitLab Pipeline scripts (.gitLab-ci.yaml) at the root of the project. Since GitLab is a very popular VCS tool, it is contained to implement CI on Commit to any branch or in the event of Merge Request. So, GitLab Runners can be configured to execute any sort of Project Repository CI Pipeline. In this article, we will discuss How to Configure GitLab CI runner on your own.
Table of Contents
How GitLab Runners works?
GitLab Runner is open-source software that can run as binary on your operating system. Gitlab Runner is written in Go language and whichever Operating System that companies Go Language can able to be installed with GitLab Runner. But Most of the Operating System supports GitLab.
Once you install the Runner, you will need to Register it into the GitLab. This will enable communication between GitLab and the Runner. You can install GitLab Runner on Docker Container.
After the Registration, you will need to choose the Executor. Executors are basically giving you an environment to run the Jobs in CICD Pipeline. You can install GitLab runner on any Linux operating system and choose Docker Executor. This will create a Docker Container as Executor.
GitLab Runner Permissions are determined by who is going to access it. That will give us three different GitLab Runners
We must consider when we are registering the GitLab runner on the GitLab Instance.
Tagging is another useful future where you name the runner with tags and once the GitLab Pipeline script (.gitlab-ci.yml) file got the mentions of the particular tag, the job will use the mentioned executor.
We can configure the GitLab runner in terms of logging and cache settings, memory CPU settings, and more. These settings can be done in the file called config.toml. This will be available after the installation of GitLab Runner. GitLab runners can be monitored using Prometheus.
How to Install GitLab Runner
Just like any other application GitLab Runner can be installed using following ways.
Let’s see how to install GitLab CI Runner one by one.
Installing from GitLab Official Repository Manager
From the official GitLab Repo, it is very easy to install and configure the GitLab Runner, For the same, follow the instaruction.
STEP 1: Run the GitLab Shell Script using CURL to add the Repository.
For Debian/Ubuntu/Mint
$ curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
For RHEL/CentOS/Fedora
$ curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
STEP 2: Install from the repository Manager.
For Debian/Ubuntu/Mint
$ sudo -E apt-get install gitlab-runner
For RHEL/CentOS/Fedora
$ sudo -E yum install gitlab-runner
Installing the GitLab from Binaries
Installing from Binary is little tricky as it involves little permission works. But, just follow the steps to install GitLab Runner using Binary
STEP 1: Download the Binary
# Linux x86-64
$ sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
# Linux arm
$ sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm
# Linux x86
$ sudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386"
STEP 2: Assign the permission to the binary
$ sudo chmod +x /usr/local/bin/gitlab-runner
STEP 3: Create User to run GitLab Runner
$ sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
STEP 4: Run the Binary as a service using the above user
$ sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
$ sudo gitlab-runner start
Install GitLab Runner on Docker Container
Running the GitLab Runner is easy and yet suggested best way. To do so, Run the following command
$ docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
How to Configure GitLab Instance for the Runner.
To get GitLab Runner Configured on the GitLab Instance, you need to get the configuration details that can be added to the runner for authentication. To do so,
Then just copy the URL and Registration token and keep it with you for the next process.
How to Configure GitLab Runner
You just need to run register command from the binary or the executor you just installed on your operating system.
Example, if you are running the GitLab Runner on linux, just run
$ sudo gitlab-runner register
Or if it is Docker Container, Jun this command on the host
$ docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
This will prompt you some questions and just give the answers to register yourself.
Or, to register as one line, use the following command or parameters.
$ sudo gitlab-runner register \
--non-interactive \
--url "https://gitlab.com/" \
--registration-token "<Give you token from GitLab>" \
--executor "docker" \
--docker-image alpine:latest \
--description "docker-runner" \
--tag-list "docker, CICD" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
In the above Just use the Copied URL and Registration token we saw in the Setting page of GitLab Instance.
That’s all, this will Register your GitLab Runner to the GitLab Instance.
Conclusion.
Nowadays, making the process simpler and yet powerful is the ultimate goal of matured automation. In that, we the Automating the CICD Pipeline in GitLab is very easy with GitLab Runners. In this article, we discussed How to Configure the GitLab Runner on your own. So, our next article will discuss how to create a CICD pipeline in GitLab. Stay tuned and subscribe DigitalVarys for more articles and study materials on DevOps, Agile, DevSecOps and App Development.
Experienced DevSecOps Practitioner, Tech Blogger, Expertise in Designing Solutions in Public and Private Cloud. Opensource Community Contributor.