gitlab ci Runner 配置

gitlab可以配置本地的runner,配置之后,执行tag yeshen-pc 之后,就可以跑到我定义的机器上。

好处是:

  1. 如果服务器没有支持ci/cd,可以本机直接跑(就是自己电脑做基建了)
  2. 如果服务器不支持访问dockerhub,但是本机可以,这样也可以用到dockerhub上的镜像了
  3. 可以配置指定本地镜像,这样在前期开发不太稳定的时候,不需要频繁构建上dockerhub

本地 Runner 配置

Step 1 注册 Runnner

gitlab -> project(ci-test) -> settings -> CI/CD -> Runners -> Specific runners

https://yeshen.org/ys/ci_test/-/settings/ci_cd

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"。

步骤

  1. 从容器中复制配置文件:
bash 复制代码
docker cp gitlab-runner:/etc/gitlab-runner/config.toml /tmp/config.toml
  1. 在每个 [runners.docker] 段落下添加:
toml 复制代码
[runners.docker]
  pull_policy = "never"
  1. 将修改后的配置复制回容器并重启 runner:
bash 复制代码
docker cp /tmp/config.toml gitlab-runner:/etc/gitlab-runner/config.toml
docker restart gitlab-runner
相关推荐
极小狐2 天前
极狐GitLab万人并发架构实践,大规模组织的扩容路线图
架构·gitlab·极狐gitlab
Lvan的前端笔记3 天前
GitLab CI 环境变量整理
ci/cd·gitlab
李迟4 天前
CICD实例:解决GitLab Runner无法执行CICD问题
gitlab
hanjq_code6 天前
gitlab本地文件 跨分支 忽略改动 不提交
gitlab
极小狐6 天前
极狐GitLab集群高可用方案,多节点架构与故障自愈实践
架构·gitlab·高可用·极狐gitlab
极小狐7 天前
极狐GitLab主备同步延迟治理,复制滞后监控与优化方法
gitlab·极狐gitlab·geo容灾
极小狐7 天前
跨项目流水线报 404 Not Found?CI_JOB_TOKEN 允许名单 9 步排查
ci/cd·gitlab·devops·权限管理·流水线·极狐gitlab·作业令牌
极小狐8 天前
极狐GitLab双机热备搭建指南,主机备机部署与切换实操
gitlab·高可用·极狐gitlab
有同事要进步14 天前
如何在github或者是gitlab上创建空文件
gitlab·github
GoodStudyAndDayDayUp16 天前
gitlab私有化跑CICD
gitlab·gitlab私有化跑cicd