GitLab Runner

Author: Jase Batchelor


GitLab Runner executes build pipelines on behalf of the GitLab server.

A number of executors are available, eg. Docker, Kubernetes and Bash (shell).

As we are building on our own servers we will use the shell executor.

This provides a number of benefits:

  • faster builds due to running on bare metal
  • exact copy of our development environment
  • simplicity of configuration
  • use apt-get, rustup and sdk update via a cron job for evergreen updates
  • no more outdated container images
  • add additional runners simply by cloning Radxa Zero

In a nutshell… KISS principle

Security
Generally it’s unsafe to run tests with shell executors. The jobs are run with the user’s permissions (gitlab-runner) and can “steal” code from other projects that are run on this server.  
Use it only for running builds on a server you trust and own.
 
https://docs.gitlab.com/runner/executors/shell.html#security

 


Sections

 


Installation

Ensure that the prerequisites have been addressed, specifically Git LFS

sudo apt-get install git-lfs --no-install-recommends
sudo -u gitlab-runner /usr/bin/git lfs install

Install the GitLab Runner using Debian package

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

sudo apt-get install gitlab-runner --no-install-recommends

# Open in Gitlab UI to view token
sudo gitlab-runner start
sudo gitlab-runner register --url http://192.168.105.2 --registration-token [GITLAB_TOKEN]

sudo systemctl restart gitlab-runner.service

image

 


Configuration

This configuration uses the shell executor.

sudo gitlab-runner register --url http://192.168.105.2 --token glrt-deadbeef
# Runtime platform         arch=arm64 os=linux pid=121150 revision=b72e108d version=16.1.0
# Running in system-mode.                            
#                                                    
# Enter the GitLab instance URL (for example, https://gitlab.com/):
# [http://192.168.105.2]: 
# Verifying runner... is valid                        runner=SYxssz2Ew
# Enter a name for the runner. This is stored only in the local config.toml file:
# [lima-debian-02]: 
# Enter an executor: docker, parallels, ssh, docker-autoscaler, kubernetes, custom, shell, virtualbox, docker+machine, instance, docker-windows:
shell
# Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
#  
# Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml" 

Add the gitlab-runner user to the Docker group

sudo usermod -aG docker gitlab-runner

 


Basic usage

We will cover a simple setup of GitLab for local testing and demos in a future article.

 


Templates

Clean up