安装runner
我们这里直接复用官方的镜像即可。将配置文件目录挂载到宿主机,方便以后快速修改配置并应用,将docker sock文件挂载到runner中,因为gitlab-runner需要调用docker daemon启动docker执行CI的job环境。
# 镜像复用的官方镜像:gitlab/gitlab-runner:v10.0.0
docker run -d --name gitlab-runner-v10.0.0 --restart always \
-v /data/apps/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:v10.0.0
注册runner
按照git.xxxx.com/admin/runner页面Setup a shared Runner manually步骤注册即可,我们主要关心URL地址和registration token即可。如下图:
gitlab-runner.png
[root@ip-10-255-1-169]#docker exec -it 1a197e3371d1 gitlab-runner register #gitlab-runner register注册一个runner
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): #https://git.xxxxxx.com/admin/runners中对应的URL
https://git.xxxxx.com
Please enter the gitlab-ci token for this runner: #https://git.xxxx.com/admin/runners中对应的token
1SpVgbdCVv7xmM_XWGGv
Please enter the gitlab-ci description for this runner: #此runner的描述,会记录在gitlab runner页面中
[1a197e3371d1]: kubernetes-qa
Please enter the gitlab-ci tags for this runner (comma separated): #为此runner打一些tag标签
kubernetes-qa
Whether to run untagged builds [true/false]: #允许此runner 为任何新提交代码跑build
[false]: true
Whether to lock the Runner to current project [true/false]: #not lock
[true]: false
Please enter the executor: kubernetes, parallels, shell, ssh, virtualbox, docker, docker-ssh, docker+machine, docker-ssh+machine: ##选择一个executor用来跑job
docker #我们通过docker运行runner,所以这里选择docker executor
Please enter the default Docker image (e.g. ruby:2.1): #选择一个默认的镜像仓库作为每个job的base image,每个job默认将基于此镜像运行
hub.xxxxx.com/devops/alpine:3.7
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
注册完成之后我们可以看到runner生成的配置文件,其中的token是单独生成的,可以备份下来方便以后runner升级我们无需重复注册。:
# more /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[[runners]]
name = "kubernetes-qa"
url = "https://git.xxxxxx.com"
token = "f7cb691ad136a10ad0cab0b319925b"
executor = "docker"
[runners.docker]
tls_verify = false
image = "hub.xxxx.com/devops/alpine:3.7"
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
注册完,回到git.xxxx.com/admin/runner页面,我们可以看到新建的share runner。
gitlab-runner2.jpg
runner同时并发支持多个job同时运行:
- 修改/srv/gitlab-runner/config/config.toml文件中concurrent=20来作为并发运行多个job,这里根据需求而定
docker方式runner安装成功,可以开始描述gitlab-ci.yml做一些CI和CD的事情.
网友评论