GitLab Runner is an agent that runs GitLab CI/CD (Continues Integration/Continuous Deployment) jobs in a pipeline. It’s heavily utilized in the world of DevOps to provision and configure infrastructure. The GitLab Runner can be installed as a binary on Linux, MacOS or Windows. It can also be installed as a container.
On this tutorial, I will walk through installing and configuring GitLab Runner as a container using a Docker image on a RPI-4..yaay. I will make it very swift to get you started and won’t feel a thing. I will not bore you with details, but if there are useful links for further study, I will definitely throw it in. The goal is to get you started with GitLab Runners and the rest is on you.
As a bonus, we will run our first job of building docker images and push them to Docker hub. Enough reading, let’s get our hands dirty, I mean our keyboards 😉
To lean more about GitLab Runners, refer to GitLab official documentation.
Sensitive information will be pixilated or erased. This should not alter the quality of the tutorial.
If you don’t have Docker installed on your RPI-4, you may refer to my Docker on Ubuntu 20.04 Raspberry Pi 4 tutorial.
docker volume create gitlab-runner-volume
Note: you can change the volume name gitlab-runner-volume to any name of your chosen, but you should be consistent as we will use the volume name to bind the container to the RPI-4 local host.
docker run -d --name gitlab-runner --restart always --env TZ=US \
-v gitlab-runner-volume:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:alpine
The only parameters you have the options to change are:
For more information about the installation process, here is the link GitLab’s official documentation.
We do need to head to our GitLab account and grab the runner’s token. If you don’t have a GitLab account, you can create one for free. Here is the link.
Now, we need to create a repository to host our project. From GitLab, let’s click on create New project. On the Create new project, select create blank project. Then, give the project a name and click Create project. In my case, I named my repo, GitLab-Runner-RPI-4.
From the repository, let’s click on settings, CI/CD and then Expand on the Runners section as shown below.
Replace the token place holder after registration-token with the one from our note pad, and then run the following commands on your RPI-4 terminal:
docker run --rm -it -v gitlab-runner-volume:/etc/gitlab-runner gitlab/gitlab-runner:alpine register -n \
--url https://gitlab.com/ \
--registration-token GR1348941EDhyNWqfxPttukrGVKJd \
--executor docker \
--description "My Docker Runner" \
--docker-image "docker:20.10.12-dind-alpine3.15" \
--docker-privileged \
--docker-volumes "/certs/client"
If everything went smooth, you should not exhibit no errors as shown below.
To confirm that the GitLab Runner container is running, run the below Docker command:
docker ps -a
Alright, this is a great indication that we have successfully configured GitLab Runner on RPI-4. Now, we are ready to make some actions 💥
git clone `your-Clone-with-HTTPS-link`
Note: the git clone command will prompt you to enter your GitLab credentials for authentication.
image: docker:19.03.12
variables:
IMAGE_NAME: "test:1.0.0"
DOCKER_TLS_CERTDIR: "/certs"
services:
- docker:19.03.12-dind
before_script:
- docker info
build image:
stage: build
script:
- docker build -t $REGISTRY_USER/$IMAGE_NAME .
- docker login -u $REGISTRY_USER -p $DOCKER_HUB_TOKEN
- docker push $REGISTRY_USER/$IMAGE_NAME
FROM alpine
RUN echo "Hello World"
Note: In the local repo, we should have two files, Dockerfile and .gitlab-ci.yml. A README file might be there as well.
Key: REGISTRY_USER Value: your Docker hub username NOT the email
Key: DOCKER_HUB_TOKEN Value: the token which we generated from Docker hub
Note: the flags should be unchecked for simplicity for the two variables.
git add -A
git commit -am "first test"
git push
If you head back to our GitLab repo and click on CI/CD under Pipelines, you would notice that the pipeline is running.
Moreover, if you click on the running status and you would be directed to the current stage, which is Build.
Here, click on build image, you shall see more details about the current build status. The goal is to see Job succeeded.
Once you see Job succeeded and passed status in green, you can start doing your victory dance 👯♀️ 👯♀️
If we head back to Docker hub account, we should see that our Docker image test:1.0.0 has been successfully pushed to the repo.
Docker hub allows Personal (free account), one private repository and unlimited number of public repositories. Therefore, if you get denied message to access the resource on the pushing images to Docker hub step, ensure your repository is public.
By the end of this tutorial, we have successfully configured a GitLab Runner on a RPI-4, created a GitLab repo and registered GitLab Runner to it. Finally, we created a Hello World Docker image from a Dockerfile and had the runner building the Docker image and pushing it to our Docker hub account. Now, off you go and the sky is the limit.