Eric Guo's blog.cloud-mes.com

in HTML5, JavaScript, Ruby & Rails, Python, and Cloud MES!

Setup a Gitlab Runner Server on Ubuntu 20.04

Permalink

According to the official documentation, I having a free lighthouse server from tencent and install Ubuntu 20.04 to running gitlab runner.

Install docker.

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
docker run hello-world

Install gitlab runner

sudo su -
docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner --help
docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner verify
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
docker logs gitlab-runner
docker restart gitlab-runner

Upgrade gitlab runner

sudo su -
docker stop gitlab-runner && docker rm gitlab-runner
docker pull gitlab/gitlab-runner
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
docker logs gitlab-runner
docker restart gitlab-runner

Fix the docker address pools conflict with internal network IP

docker network inspect bridge
vi /etc/docker/daemon.json
systemctl restart docker.service
docker network inspect bridge
{
"registry-mirrors": ["https://mirror.ccs.tencentyun.com", "http://hub-mirror.c.163.com"],
"default-address-pools":
[
{"base":"10.200.100.0/16","size":24}
]
}

Clean docker cache

wget https://gitlab.com/gitlab-org/gitlab-runner/-/raw/main/packaging/root/usr/share/gitlab-runner/clear-docker-cache
chmod +x clear-docker-cache
./clear-docker-cache

Further info

Comments