镜像拉取并启动
1
2
3
4
5
|
$ sudo 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 \
-v /etc/docker/:/etc/docker/ \
gitlab/gitlab-runner:v12.10.0
|
runner注册
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$ docker exec -it gitlab-runner gitlab-ci-multi-runner register
Runtime platform arch=amd64 os=linux pid=19 revision=c553af1a version=12.10.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://172.16.77.40:10024/ #gitlab地址
Please enter the gitlab-ci token for this runner:
b3ybNpuJBVBLus3xfXoU #token 在gitlab的Admin Area>Runners里可以查到
Please enter the gitlab-ci description for this runner:
[b5838a22d63f]: ci-runner #runner的描述
Please enter the gitlab-ci tags for this runner (comma separated):
ci-tag #与runner关联的标签
Registering runner... succeeded runner=b3ybNpuJ
Please enter the executor: ssh, virtualbox, docker-ssh+machine, parallels, docker, docker-ssh, shell, docker+machine, kubernetes, custom:
docker #执行者
Please enter the default Docker image (e.g. ruby:2.6):
docker:stable #指定的镜像
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
|
通过以上操作后在gitlab的Admin Area>Runners里就可以看到你刚注册的runner了
添加maven缓存等
docker image每次构建都是在独立的container里, maven的 .m2文件并不会被多次构建公用,这里我们可以通过修改gitlab-runner的配置,将maven .m2目录加到volumes中,并增加镜像拉取规则(默认是从远程拉取镜像,这里修改为优先获取本地镜像)
1
2
3
4
5
6
7
8
9
|
# 修改runner的配置文件
$ vim /srv/gitlab-runner/config/config.toml
......
volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock","/home/docker/data/.m2/:/.m2/"]
pull_policy = "if-not-present"
......
# 重启runner
$ docker restart gitlab-runner
|
Author
dylan
LastMod
2020-05-09
License
如需转载请注明文章作者和出处。谢谢!