搭建GitLab Runner(基于Docker)
搭建GitLab Runner(基于Docker)
前面的文章中已经介绍了搭建GitLab(基于Docker),直接在Ubuntu 20.04系统中搭建GitLab Runner
名称 | 服务器 | 搭载服务 |
---|---|---|
A | 192.168.1.72 | GitLab(已搭建完成) |
B | 192.168.1.73 | GitLab Runner(未搭建完成) |
修改hosts
在B主机中修改hosts,增加一条192.168.1.72 gitlab.com
。
$ cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.1.72 gitlab.com
安装GitLab Runner镜像&启动GitLab Runner容器
由于我这里的gitlab是自定义域名,所有需要使用--add-host
来向容器增加一条的hosts。
$ sudo docker run -d --name gitlab-runner \
--add-host gitlab.com:192.168.1.72 \
--restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
注册Runner
在GitLab中,进入一个项目,点击Settings
的CI/CD
。
看到图中Specific runners
下面有步骤,其中有Register the runner with this URL
和And this registration token
是注册中Runner的时候要输入的URL和Token。
注册命令如下:
$ sudo docker run --add-host gitlab.com:192.168.1.72 --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
输入参数
http://gitlab.com/
btrbkwsSwHbFZs54PJWd
cicd
cicd
docker
node:alpine
注册成功
$ sudo docker run --add-host gitlab.com:192.168.1.72 --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
Runtime platform arch=amd64 os=linux pid=9 revision=58ba2b95 version=14.2.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://gitlab.com/
Enter the registration token:
btrbkwsSwHbFZs54PJWd
Enter a description for the runner:
[7c296633a3d5]: cicd
Enter tags for the runner (comma-separated):
cicd
Registering runner... succeeded runner=btrbkwsS
Enter an executor: custom, docker, shell, docker+machine, kubernetes, docker-ssh, parallels, ssh, virtualbox, docker-ssh+machine:
docker
Enter the default Docker image (for example, ruby:2.6):
node:alpine
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
还没有评论,来说两句吧...