Run your CI/CD runner with Gitlab Runner in 2 minutes
I really like Gitlab for their CI/CD services. And specially their generous free usage offering. These month I've been running out of CI/CD minutes. So I decided to run my own runner inside a VM which I don't use that much.
- Docker installed
Registering our runner to Gitlab. You'll need to get the
Runner registration token from the
Project Setting > CI/CD page.
It'll look something like below
Let's register our runner.
docker run --rm -it --name gitlab-runner -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest register
We're doing a few things here.
- First we are running gitlab-runner container and asking it to register itself to Gitlab.
- We're also mounting
docker.sockto the runner container so that it can spin a new docker container for our CI/CD pipeline
- We're mount a config directory so our configuration is persisted across the container restart.
Once you run above it will ask you two thing, Gitlab instance URL and your registration token. Just fill in what you obtained from above step.
Once that's done. We need to run the
Let's run it
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
Remember we are mounting the same config directory, and it is important otherwise
gitlab-runner won't run.
And that's all. Now if you refresh the CI/CD settings page you will see your runner listed there.