Install GitLab runner on Raspberry Pi.

I will use previous LXD setup on Raspberry Pi 4 with DietPi operating system.

Get the registration token

Determine the registration token.

Create LXD instance

I am using Raspberry Pi 4 with DietPi operating system, aarch64 architecture.

$ uname -a
Linux DietPi 5.10.63-v8+ #1459 SMP PREEMPT Wed Oct 6 16:42:49 BST 2021 aarch64 GNU/Linux

Search for Ubuntu 20.04.3 LTS (Focal Fossa) image.

$ sudo -i lxc image list images: architecture=arm64 os=Ubuntu release=focal
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|            ALIAS            | FINGERPRINT  | PUBLIC |             DESCRIPTION             | ARCHITECTURE |      TYPE       |   SIZE   |          UPLOAD DATE          |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
| ubuntu/focal (7 more)       | 4d05260235b7 | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | CONTAINER       | 97.76MB  | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
| ubuntu/focal (7 more)       | 7664234ba371 | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | VIRTUAL-MACHINE | 239.38MB | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
| ubuntu/focal/cloud (3 more) | b34bd4e8a06c | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | VIRTUAL-MACHINE | 262.69MB | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
| ubuntu/focal/cloud (3 more) | fbea3bbeffa9 | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | CONTAINER       | 112.38MB | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 0e6724185d46 | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | CONTAINER       | 101.32MB | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 1ef2f2f42455 | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | VIRTUAL-MACHINE | 239.31MB | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 01e2c1616e4a | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | VIRTUAL-MACHINE | 239.31MB | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 4cc95e7aecd7 | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | CONTAINER       | 112.38MB | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 8b17689d7ff1 | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | VIRTUAL-MACHINE | 262.38MB | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 9bbf2a08a5fb | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | CONTAINER       | 97.76MB  | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 44df16720440 | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | CONTAINER       | 88.65MB  | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 47c2afda0b28 | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | CONTAINER       | 88.73MB  | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 48ce6843b5c4 | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | CONTAINER       | 100.71MB | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 04288b617a5b | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | VIRTUAL-MACHINE | 262.56MB | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 7141a7f194ce | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | CONTAINER       | 101.64MB | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | 12151b6307fb | yes    | Ubuntu focal arm64 (20211113_07:42) | aarch64      | CONTAINER       | 112.37MB | Nov 13, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | c5a43ce69ea8 | yes    | Ubuntu focal arm64 (20211114_08:44) | aarch64      | CONTAINER       | 89.29MB  | Nov 14, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+
|                             | d5473410cfe5 | yes    | Ubuntu focal arm64 (20211112_07:42) | aarch64      | CONTAINER       | 97.76MB  | Nov 12, 2021 at 12:00am (UTC) |
+-----------------------------+--------------+--------+-------------------------------------+--------------+-----------------+----------+-------------------------------+

Inspect image.

$ sudo -i lxc image info images:ubuntu/focal
Fingerprint: 4d05260235b770941e1b4eb59cf039810d3cd651a4425a5451cb5b45328bd2ae
Size: 97.76MB
Architecture: aarch64
Type: container
Public: yes
Timestamps:
    Created: 2021/11/14 00:00 UTC
    Uploaded: 2021/11/14 00:00 UTC
    Expires: never
    Last used: never
Properties:
    os: Ubuntu
    release: focal
    architecture: arm64
    description: Ubuntu focal arm64 (20211114_08:44)
    variant: default
    serial: 20211114_08:44
    type: squashfs
Aliases:
    - ubuntu/focal/default
    - ubuntu/focal/default/arm64
    - ubuntu/20.04/default
    - ubuntu/20.04/default/arm64
    - ubuntu/focal
    - ubuntu/focal/arm64
    - ubuntu/20.04
    - ubuntu/20.04/arm64
Cached: no
Auto update: disabled
Profiles: []

Copy this image.

$ sudo -i lxc image copy images:ubuntu/focal/arm64 local:
Image copied successfully!      

Create an alias.

$ sudo -i lxc image alias create local:ubuntu/focal 4d05260235b7

Display local images.

$ sudo -i lxc image list
+--------------+--------------+--------+--------------------------------------+--------------+-----------+---------+------------------------------+
|    ALIAS     | FINGERPRINT  | PUBLIC |             DESCRIPTION              | ARCHITECTURE |   TYPE    |  SIZE   |         UPLOAD DATE          |
+--------------+--------------+--------+--------------------------------------+--------------+-----------+---------+------------------------------+
| ubuntu/focal | 4d05260235b7 | no     | Ubuntu focal arm64 (20211114_08:44)  | aarch64      | CONTAINER | 97.76MB | Nov 14, 2021 at 4:26pm (UTC) |
+--------------+--------------+--------+--------------------------------------+--------------+-----------+---------+------------------------------+

Create gitlab-runner instance.

$ sudo -i lxc launch local:ubuntu/focal gitlab-runner
Creating gitlab-runner
Starting gitlab-runner

Define memory limit.

$ sudo -i lxc config set gitlab-runner-ssh limits.memory 1024MB

Set cpu limit.

$ sudo -i lxc config set gitlab-runner-ssh limits.cpu 1

Install GitLab runner application

Do not use official repository as it provides outdated GitLab runner.

Enter gitlab-runner instance.

$ sudo -i lxc exec gitlab-runner bash
root@gitlab-runner:~#

Install packages required to download an application.

root@gitlab-runner:~# apt install curl

Downlad an application.

root@gitlab-runner:~# curl -L --output /usr/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm64

Inspect downladed file.

root@gitlab-runner:~# ls -l /usr/bin/gitlab-runner
-rw-r--r-- 1 root root 53884871 Nov 21 22:36 /usr/bin/gitlab-runner

Ensure that executable bit is set.

root@gitlab-runner:~# chmod +x /usr/bin/gitlab-runner

Add gitlab-runner group.

root@gitlab-runner:~# groupadd --gid 2000 gitlab-runner

Add gitlab-runner user.

root@gitlab-runner:~# useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash --uid 2000 --gid 2000

Inspect created user.

root@gitlab-runner:~# id gitlab-runner
uid=2000(gitlab-runner) gid=2000(gitlab-runner) groups=2000(gitlab-runner)

Setup runner service.

root@gitlab-runner:~# gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

Start service.

root@gitlab-runner:~# gitlab-runner start

I am using a self signed certificate, so create a dedicated directory to store it.

root@gitlab-runner:~# mkdir /etc/gitlab-runner/certificates

Store server certificate.

root@gitlab-runner:~# echo | openssl s_client -servername git.octocat.lab -connect git.octocat.lab:443 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | tee /etc/gitlab-runner/certificates/git.octocat.lab.pem

Configure runner using shell provider

Register a GitLab runner.

root@gitlab-runner-ssh:~# gitlab-runner register --name "Local SSH runner" --tls-ca-file /etc/gitlab-runner/certificates/git.octocat.lab.pem --executor shell --shell bash --url https://git.octocat.lab/ --registration-token aSRFKnhdLhgARLjo1MAC --tag-list "ssh,local" --non-interactive

Configure runner using docker provider

Install Docker.

root@gitlab-runner-docker:~# apt-get install docker.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apparmor bridge-utils containerd dns-root-data dnsmasq-base git git-man iptables libcurl3-gnutls liberror-perl libgdbm-compat4 libgdbm6 libidn11 libip6tc2 libnetfilter-conntrack3 libnfnetlink0
  libnftnl11 libperl5.30 patch perl perl-modules-5.30 pigz runc ubuntu-fan
Suggested packages:
  apparmor-profiles-extra apparmor-utils ifupdown aufs-tools btrfs-progs cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse zfs-fuse | zfsutils gettext-base git-daemon-run
  | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn firewalld nftables gdbm-l10n ed diffutils-doc perl-doc libterm-readline-gnu-perl
  | libterm-readline-perl-perl make libb-debug-perl liblocale-codes-perl
The following NEW packages will be installed:
  apparmor bridge-utils containerd dns-root-data dnsmasq-base docker.io git git-man iptables libcurl3-gnutls liberror-perl libgdbm-compat4 libgdbm6 libidn11 libip6tc2 libnetfilter-conntrack3
  libnfnetlink0 libnftnl11 libperl5.30 patch perl perl-modules-5.30 pigz runc ubuntu-fan
0 upgraded, 25 newly installed, 0 to remove and 10 not upgraded.
Need to get 69.5 MB of archives.
After this operation, 396 MB of additional disk space will be used.
[...]

Verify Docker installation.

root@gitlab-runner-docker:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
93288797bd35: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Register a GitLab runner.

root@gitlab-runner-ssh:~# gitlab-runner register --name "Local Docker runner" --tls-ca-file /etc/gitlab-runner/certificates/git.octocat.lab.pem --executor docker --docker-image debian:bullseye --url https://git.octocat.lab/ --registration-token aSRFKnhdLhgARLjo1MAC --tag-list "docker,local" --run-untagged --non-interactive

Verify registered runners

Use GitLab admin area to verify configured runners.

That is all!