专栏系列Gitlab 指南
Gitlab Runner说明
1. 安装
Linux amd64为例
PLAINTEXT
# 下载二进制文件
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# 赋权
sudo chmod +x /usr/local/bin/gitlab-runner
# 创建gitlab-runner用户
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
# 安装成一个服务
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner startgitlab runner的配置文件在/etc/gitlab-runner/config.toml下
TOML
concurrent = 10 # 并发运行的数量,这里修改为10,0不代表无限制,必须为数值
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "centos8.3 runner" # runner名字
url = "https://gitlab.xxx.com/" # gitlab服务器地址
token = "gJNJCpRp_-Zobf19BDA5" # token
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:20.10.5" # 不指定时默认的docker镜像
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"] # 配置使用的宿主机的docker以让容器内部可以直接使用docker命令
shm_size = 02. Gitlab Runner使用详解
Runner的执行时序图
sequenceDiagram
participant GitLab
participant GitLabRunner
participant Executor
opt registration
GitLabRunner->>GitLab: POST /api/v4/runners with registration_token
activate GitLab
GitLab-->>GitLabRunner: Registered with runner_token
deactivate GitLab
end
loop job requesting and handling
GitLabRunner->>GitLab: POST /api/v4/jobs/request with runner_token
GitLab-->>GitLabRunner: job payload with job_token
activate GitLabRunner
GitLabRunner->>Executor: Job payload
activate Executor
Executor->>GitLab: clone sources with job token
Executor->>GitLab: download artifacts with job token
Executor-->>GitLabRunner: return job output and status
deactivate Executor
GitLabRunner-->>GitLab: updating job output and status with job_token
deactivate GitLabRunner
end
2.1 Executor
executor类型大概有下面几种
| Executor | SSH | Shell | VirtualBox | Parallels | Docker | Kubernetes | Custom |
|---|---|---|---|---|---|---|---|
| 每次构建清理构建环境 | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | conditional(4) |
| 重复使用之前的clone | ✓ | ✓ | ✗ | ✗ | ✓ | ✗ | conditional(4) |
| Runner的文件系统访问受保护 | ✓ | ✗ | ✓ | ✓ | ✓ | ✓ | conditional |
| 转移Runner的机器 | ✗ | ✗ | 部分 | 部分 | ✓ | ✓ | ✓ |
| 零配置支持并发构建 | ✗ | ✗(1) | ✓ | ✓ | ✓ | ✓ | conditional(4) |
| 复杂构建环境 | ✗ | ✗(2) | ✗(3) | ✗(3) | ✓ | ✓ | ✓ |
| 调试构建问题 | easy | easy | hard | hard | medium | medium | medium |
- It’s possible, but in most cases it is problematic if the build uses services installed on the build machine
- It requires to install all dependencies by hand
- For example using Vagrant
- Dependent on what kind of environment you are provisioning. It can be completely isolated or shared between each build.
- When a runner’s file system access is not protected, jobs can access the entire system including the runner’s token, and the cache and code of other jobs. Executors marked ✓ don’t allow the runner to access the file system by default. However, security flaws or certain configurations could allow jobs to break out of their container and access the file system hosting runner.
3. FAQ
-
sudo gitlab-runner install提示command not found由于gitlab安装在
/usr/local/bin下面,而sudo环境变量下不存在改地址,所以这个需要把改路径加到环境变量中
打开/etc/sudoers,修改如下内容PLAINTEXTDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin增加
PLAINTEXTDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
4. 更新gitlab-runner
-
停止服务
BASHsudo gitlab-runner stop -
下载最新脚本替换当前的
BASHsudo curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64" -
给脚本赋权
BASHsudo chmod +x /usr/local/bin/gitlab-runner -
启动服务
BASHsudo gitlab-runner start
推荐阅读
PVE 安装 (基于最新PVE8)及相关基础配置(换 Debian 源和 PVE 企业源)本文介绍 PVE 8 的安装及 Debian 源的更换和 PVE 源的更换
Fake Location 1.3.2.2 全功能解锁模块FakeLocation 1.3.2.2 全功能破解,来自52PoJie论坛
Fake Location 1.3.2.2专业版破解(虚拟定位软件)在 52Pojie 上看到的 Fake Location 的破解案例,虽然 APP 已经不能用了,但是破解参考价值还是很好的
OpenWRT 配置 AP 模式OpenWRT 配置 AP 模式
OpenWrt 进阶教程之无线中继配置指南OpenWrt进阶教程之无线中继配置指南
Android逆向 | 某麦网APP抢票接口加密参数分析及抢票工具编写Android逆向 | 某麦网APP抢票接口加密参数分析及抢票工具编写
OpenWRT 主路由模式和旁路由模式配置OpenWRT 主路由模式和旁路由模式配置
PVE 安装 OpenWRT (基于PVE 8)PVE 安装 OpenWRT(基于PVE 8.0
评论交流
暂无评论,欢迎分享您的见解
