Skip to main content

Gitlab Runner

在 Docker 下, 用于对私有项目进行构建部署。

部署 runner

Specific runners 注册信息

在 gitlab 上,项目中 找到 CI/CD Settings -> Runners -> Specific runners -> Set up a specific runner manually 记下 url 和 token

启动 runner

在 docker 上运行:

docker run -d --name gitlab-runner --restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v gitlab-runner-config:/etc/gitlab-runner \
--network host \
gitlab/gitlab-runner:latest

注意:这里因为网络问题,network使用了host模式。

注册到 Gitlab

1. 进入 runner container

docker exec -it gitlab-runner /bin/bash

2. 配置 Runner

gitlab-runner register

Runtime platform arch=amd64 os=linux pid=29 revision=b37d3da9 version=14.3.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
# 找到上面的 Specific runners 注册信息 的 url
Enter the registration token:
# 找到上面的 Specific runners 注册信息 的 token
# 构建节点名称 随意命名
Enter a description for the runner:
[localhost.runner.com]: runner-35
# 标签名称 在同一组runner可以命一个名
Enter tags for the runner (comma-separated):
docker-runner
Registering runner... succeeded                     runner=71SuA9WG
# 这里是用docker来部署的 输入docker
Enter an executor: parallels, virtualbox, docker+machine, docker-ssh+machine, kubernetes, custom, docker, docker-ssh, shell, ssh:
docker
# 基础镜像 根据你的实际需求来找。
Enter the default Docker image (for example, ruby:2.6):
alpine:latest
# 安装成功后会显示这个信息
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

配置 Gitlab Runner

在 gitlab 上,项目中 找到 CI/CD Settings -> Runners -> Available specific runners

点进刚才注册到 runner 实例,勾选 Run untagged jobs (Indicates whether this runner can pick jobs without tags)

无外部网络(optional)

镜像除了 gitlab/gitlab-runner,在运行的时候还会产生一些其他的依赖。

需要预先从一个有外部网络的主机构建一次 找到其他依赖的镜像,再上传到各个runner节点

例如:

  • registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-b37d3da9

参考资料: