gitlab可以配置本地的runner,配置之后,执行tag yeshen-pc 之后,就可以跑到我定义的机器上。
好处是:
- 如果服务器没有支持ci/cd,可以本机直接跑(就是自己电脑做基建了)
- 如果服务器不支持访问dockerhub,但是本机可以,这样也可以用到dockerhub上的镜像了
- 可以配置指定本地镜像,这样在前期开发不太稳定的时候,不需要频繁构建上dockerhub
本地 Runner 配置
Step 1 注册 Runnner
gitlab -> project(ci-test) -> settings -> CI/CD -> Runners -> Specific runners
Step 2 注册
sh
# 注册使用上面的配置信息
$ docker volume create gitlab-runner-config
$ docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest register
----------
# Enter the GitLab instance URL (for example, https://gitlab.com/):
上面截图的URL
# Enter the registration token:
上面截图的TOKEN
# Enter a description for the runner:
[cd48fa3a5a05]: yeshen-pc
# Enter tags for the runner (comma-separated):
yeshen-personal-pc
# Enter optional maintenance note for the runner:
yeshen-pc
# WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
# Registering runner... succeeded runner=GR13489414zrDvCSj
# Enter an executor: ssh, parallels, virtualbox, docker, docker-windows, docker+machine, custom, shell, instance, kubernetes, docker-autoscaler:
docker
# Enter the default Docker image (for example, ruby:2.7):
debian:10-slim
step 3 本机运行一个Runner
sh
docker run -d --name gitlab-runner --restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v gitlab-runner-config:/etc/gitlab-runner \
gitlab/gitlab-runner:latest
指定只使用本地镜像(避免从 DockerHub 拉取)
当 runner 以 Docker 方式部署时,可通过修改 config.toml 设置 pull_policy = "never"。
步骤
- 从容器中复制配置文件:
bash
docker cp gitlab-runner:/etc/gitlab-runner/config.toml /tmp/config.toml
- 在每个
[runners.docker]段落下添加:
toml
[runners.docker]
pull_policy = "never"
- 将修改后的配置复制回容器并重启 runner:
bash
docker cp /tmp/config.toml gitlab-runner:/etc/gitlab-runner/config.toml
docker restart gitlab-runner