- Create a Docker network for all containers:
docker network create gitlab-runner-net
- Create a Docker volume to store runner config:
docker volume create gitlab-runner-vol
- Register runner with
docker
executor:
docker run --rm -it -v gitlab-runner-vol:/etc/gitlab-runner gitlab/gitlab-runner:v13.12.0 register
- default image for docker executor:
maven:3.8.1-jdk-11
- Register runner with
shell
executor:
docker run --rm -it -v gitlab-runner-vol:/etc/gitlab-runner gitlab/gitlab-runner:v13.12.0 register
- Tweak runner config:
docker run --rm -it -v gitlab-runner-vol:/etc/gitlab-runner debian:buster-slim
apt update
apt install nano
nano /etc/gitlab-runner/config.toml
- add
pull_policy = "if-not-present"
andnetwork_mode = "gitlab-runner-net"
to runner config, i.e.:
[[runners]]
...
executor = "docker"
...
[runners.docker]
...
pull_policy = "if-not-present" # pull docker images on demand and not always
network_mode = "gitlab-runner-net" # run containers in custom network
- Create and run container (using a WSL2 Linux shell):
docker run -d --name gitlab-runner --restart always --network gitlab-runner-net \
-v gitlab-runner-vol:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
-v /usr/bin/com.docker.cli:/usr/bin/com.docker.cli \
gitlab/gitlab-runner:v13.12.0
/var/run/docker.sock
must be read-/writeable for all, sosudo chmod 666 /var/run/docker.sock
on the host if necessary- only works this way, if Docker uses WSL2 back-end
- otherwise, GitLab Runner should be installed locally and not in a container
- If the runner is not needed anymore, stop and remove the container and volume:
docker stop gitlab-runner
docker rm gitlab-runner
docker volume rm gitlab-runner-vol
docker network rm gitlab-runner-net
- Create and run a container for hosting the servlet using Tomcat:
docker run -d --name github-runner --network gitlab-runner-net -p 8081:8080 tomcat:9.0.46-jdk11
- Open a shell in the container:
docker exec -it github-runner /bin/bash
- Install Maven in the container:
apt update
apt install maven
- Change permissions on
/usr/local/tomcat/webapps
to world read-/writeable:
chmod 777 /usr/local/tomcat/webapps
- Create a new user for running the GitHub self-hosted runner and switch to that user:
adduser github-runner
su -l github-runner
-
Install and run self-hosted runner for Linux X64 as explained in the settings of your repository (Settings → Actions → Runners)
-
To stop the runner, press
Ctrl + C
. -
If the runner is not needed anymore,
exit
the container shell and then stop and remove the container:
docker stop github-runner
docker rm github-runner
- Create and run a SonarQube container:
docker run -d --name sonarqube --restart always \
--network gitlab-runner-net -p 9000:9000 \
-e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true \
sonarqube:8.9.1-community
- Log into SonarQube, create a new project and adapt CI/CD config accordingly