Self-hosted GitLab runners are an essential part of GitLab CI/CD pipelines. They allow you to run your tests, builds, and deployments on your own infrastructure, giving you more control over your continuous integration and delivery processes. In this comprehensive guide, we'll walk you through the key concepts and steps to configure self-hosted GitLab runners.
What are Self-Hosted GitLab Runners?
Self-hosted GitLab runners are instances of the GitLab runner application that you run on your own servers or virtual machines. They communicate with GitLab to receive jobs from your GitLab projects and execute them on your infrastructure. This approach gives you more control over your infrastructure, security, and compliance.
Prerequisites
Before you start configuring self-hosted GitLab runners, make sure you have the following prerequisites:
- A GitLab account and a project with a
.gitlab-ci.ymlfile. - A server or virtual machine with the necessary resources to run the GitLab runner.
- Git installed on the server or virtual machine.
Installing the GitLab Runner
To install the GitLab runner, follow these steps:
- Download the GitLab runner package for your operating system from the GitLab website:
- Extract the package:
- Move the GitLab runner binary to a system directory:
- Register the GitLab runner with GitLab:
$ wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/packages/gitlab-runner-...tgz
$ tar xzf gitlab-runner-...tgz
$ sudo mv gitlab-runner /usr/local/bin
$ sudo gitlab-runner register --url "https://gitlab.example.com" --registration-token "your_registration_token"
Configuring the GitLab Runner
After installing the GitLab runner, you need to configure it to run your jobs. This involves creating a configuration file for the runner and configuring it to connect to your GitLab instance:
- Create a configuration file for the runner:
- Edit the configuration file:
- Save and close the file.
- Start the GitLab runner:
$ sudo mkdir -p /etc/gitlab-runner/
$ sudo touch /etc/gitlab-runner/config.toml
$ sudo nano /etc/gitlab-runner/config.toml
Add the following configuration:
concurrent = 10 check_interval = 30s[[runners]] name = "my_runner" limit = 3 [[runners.cache]] Paths = ["/var/cache/gitlab-runner"]
[[runners.cache_shares]] Name = "my_runner" Shares = "1gb"
$ sudo gitlab-runner start
Configuring the GitLab Project
Finally, you need to configure your GitLab project to use the self-hosted runner:
- Edit the
.gitlab-ci.ymlfile: - Push the changes to your GitLab project:
$ git checkout
$ git config user.email "[email protected]"
$ git config user.name "Your Name"
$ echo "services:" >> .gitlab-ci.yml
$ echo " - docker:" >> .gitlab-ci.yml
$ echo " access_level: private" >> .gitlab-ci.yml
$ echo " image: docker:latest" >> .gitlab-ci.yml
$ echo " tags: [" >> .gitlab-ci.yml
$ echo " my_runner," >> .gitlab-ci.yml
$ echo " ]" >> .gitlab-ci.yml
$ git add .gitlab-ci.yml
$ git commit -m "Add self-hosted runner configuration"
$ git push origin
In this comprehensive guide, we walked you through the key concepts and steps to configure self-hosted GitLab runners. We covered installing the GitLab runner, configuring it, and configuring your GitLab project to use it. With self-hosted runners, you have more control over your infrastructure, security, and compliance in your GitLab CI/CD pipelines.