I’ve had self hosted Gitlab instance running for a long time along the gitlab.com service. After an upgrade I noticed Gitlab had CI enabled on repositories by default. This got me pondering on enabling the CI features on my own instance. I’m using Ubuntu 18.04, but on the Official instructions there are other distributions like CentOS, Fedora and Debian, mentioned. So here is a brief guide to my future self.
Add the repository for Gitlab runner
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
Install the runner
sudo apt-get install gitlab-runner
I know beforehand that I want to use Docker as my executor, so I install it before registering the runner.
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Check the key fingerprint
sudo apt-key fingerprint 0EBFCD88
Add the stable repository. It is also possible to use test or nightly repository.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install Docker Engine - Community and containerd
sudo apt-get install docker-ce docker-ce-cli containerd.io
Test Docker by running the hello-world container
sudo docker run hello-world
Register the runner. If you want to install a shared runner, you have to have admin access to .Gitlab instance. While installing shared instance, you can find the URL and token from the Gitlab UI by going to admin/runners. The rest of the options are told here.
I selected Docker as my executor, so I have to give the default Docker image, in case projects do not define one in .gitlab-ci.yml. I choose Alpine Linux as it is popular distribution with small footprint.
When the runner has been installed and registered, it is visible in Gitlab. Now all you need to do is add .gitlab-ci.yml to the root of your repository and start wondering what to do with it.