Gitlab & Docker

1. Installing Gitlab CI based on a docker image

Pull the latest version:

1
docker pull gitlab/gitlab-runner:latest

You need to mount a config volume into the gitlab-runner container to be used for configs and other resources:

1
2
3
4
docker run -d --name table-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest

Only registered runners can connect to Gitlab CI Server, so a registration process is required:

1
docker exec -it gitlab-runner gitlab-runner register

Then it will ask for some necessary authentication information, as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://your_gitlab_ip/
Please enter the gitlab-ci token for this runner:
xxxxxxxxxxxxxxx
Please enter the gitlab-ci description for this runner:
[xxxxxxxx]: docker-runner
Please enter the gitlab-ci tags for this runner (comma separated):
table
Whether to run untagged builds [true/false]:
[false]:
Whether to lock the Runner to current project [true/false]:
[true]: false
Registering runner... succeeded runner=xxxxxx
Please enter the executor: docker, shell, virtualbox, kubernetes, docker-ssh, parallels, ssh, docker+machine, docker-ssh+machine:
docker
Please enter the default Docker image (e.g. ruby:2.1):
maven:3.5.3-jdk-8
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

One-line registration command:

1
2
3
4
5
6
7
8
9
10
docker exec -it table-runner gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image docker \
--url "https://your_gitlab_ip/" \
--registration-token "xxxxxxxxxxxxxx" \
--description "docker-runner" \
--tag-list "master" \
--run-untagged false \
--locked="true"

You can find them in your project page, Settings -> Pipeline -> Specific Runners

If successful, you can see the Runner just configured.

2. Let gitlab-runner use the proxy

Centos 7 & 6

You need to edit /srv/gitlab-runner/config/config.toml and add the following to the [[runners]] section:

1
environment = ["HTTPS_PROXY=http://your_proxy_ip:port", "HTTP_PROXY=http://your_proxy_ip:port", "NO_PROXY=localhost,127.0.0.0"]

Centos 7 (Not recommended)

Create a systemd drop-in directory for the gitlab-runner service:

1
mkdir /etc/systemd/system/gitlab-runner.service.d

Create a file called /etc/systemd/system/gitlab-runner.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable(s):

1
2
3
[Service]
Environment="HTTP_PROXY=http://your_proxy_ip:port"
Environment="HTTPS_PROXY=http://your_proxy_ip:port"

Save the file and flush changes:

1
systemctl daemon-reload

Restart GitLab Runner:

1
sudo systemctl restart gitlab-runner
咕咕咕