极狐GitLab 正式推出面向 GitLab 老旧版本(12.x、13.x、14.x、15.x 等)免费用户的专业升级服务,点击查看详情

返回列表 发布新帖

GitLab Runner

857 0
发表于 2024-4-11 15:57:05 | 显示全部楼层 阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×

本帖最后由 胡睿智 于 2024-4-11 15:59 编辑

官方原文:

1. GitLab Runner简介

详细内容请参考:GitLab Runner

1.1 Runner简介

  • GitLab Runner用于执行.gitlab-ci.yml中定义的代码;
  • GitLab Runner的版本应该与GitLab一致;
  • Runner安装好后应进行注册,以建立与GitLab主机的通讯;
  • 注册Runner时,必须选择执行器(executor),以确定每个作业运行的环境;
  • 注册Runner时,可以为它添加标签(tag)
  • 根据访问权限的不同,Runner分为三种:共享级、组级、项目级;
  • 可使用Prometheus 监控 Runner;

1.2 Runner执行流程

Runner执行流程

Gitlab Runner là gì? Tổng quan về Gitlab Runner - Phần 1

2. 安装Runner

详细内容请参考: Install GitLab Runner

Runner的安装方式有以下几种

2.1 系统软件仓库

详细内容请参考:Install GitLab Runner using the official GitLab repositories

2.1.1 安装GitLab Runner

Installing GitLab Runner

2.1.2 更新GitLab Runner

Updating GitLab Runner

2.1.3 手动下载安装包

Manually download packages

2.1.4 禁用skel

有时候linux的skel目录会导致GitLab Runner出错,安装Runner时可将环境变量GITLAB_RUNNER_DISABLE_SKEL的值设置为true。例如:

# For Debian/Ubuntu/Mint
export GITLAB_RUNNER_DISABLE_SKEL=true; sudo -E apt-get install gitlab-runner

# For RHEL/CentOS/Fedora
export GITLAB_RUNNER_DISABLE_SKEL=true; sudo -E yum install gitlab-runner

2.2 二进制文件

2.3 容器

2.4 自动伸缩

3. 配置Runner

详细内容请参考: Configuring GitLab Runner

3.1 高级配置项

通过config.toml文件修改GitLab Runner的配置,详细内容请参考:Advanced configuration

  • 修改大多数选项时,不需要重启Runner;
  • config.toml 文件通常位于:
    • *nix系统的/etc/gitlab-runner/ 或者 ~/.gitlab-runner/
    • 其它系统的./

config.toml示例:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "test-runner"
  url = "https://gitlab.com"
  token = "__REDACTED__"
  executor = "kubernetes"
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.kubernetes]
    host = "http://localhost:9876/"
    bearer_token_overwrite_allowed = false
    image = ""
    namespace = ""
    namespace_overwrite_allowed = ""
    privileged = false
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    [runners.kubernetes.volumes]

3.1.1 全局配置

主要有以下几个配置:

  • concurrent
  • log_level
  • log_format
  • check_interval
  • sentry_dsn
  • listen_address

详细内容请参考:The global section

3.1.2 [session_server]

主要有三个配置:

  • listen_address
  • advertise_address
  • session_timeout

用Helm Chart部署的Runner不支持[session_server]。详细内容请参考:The [session_server] section

3.1.3 [[runners]]

每个[[runners]]定义一个Runner,详细内容请参考:The [[runners]] section

3.1.4 [runners.docker]

定义Docker容器参数,详细内容请参考:The [runners.docker] section

3.1.5 [runners.parallels]

定义虚拟机并发参数,详细内容请参考:The [runners.parallels] section

3.1.6 [runners.virtualbox]

定义VirtualBox参数,详细内容请参考:The [runners.virtualbox] section

3.1.7 [runners.ssh]

定义SSH连接参数,详细内容请参考:The [runners.ssh] section

3.1.8 [runners.machine]

基于自动伸缩特性定义Docker Machine,详细内容请参考:The [runners.machine] section

3.1.9 [runners.custom]

自定义执行器配置,详细内容请参考:The [runners.custom] section

3.1.10 [runners.cache]

定义分布式缓存,详细内容请参考:The [runners.cache] section

3.1.11 [runners.kubernetes]

定义k8s参数,详细内容请参考:The [runners.kubernetes] section

3.1.12 [runners.custom_build_dir]

定义是否允许自定义构建目录,详细内容请参考:The [runners.custom_build_dir] section

3.1.13 [runners.referees]

定义作业监控,详细内容请参考:The [runners.referees] section

3.2 自签证书或自定义证书颁发机构

详细内容请参考:Self-signed certificates or custom Certification Authorities

3.2.1 用自签证书连接GitLab服务器

使用自签证书连接GitLab服务器,详细内容请参考:Supported options for self-signed certificates targeting the GitLab server

3.2.2 自定义证书颁发机构(CA)

这是一种更通用的方式,详细内容请参考:Trusting TLS certificates for Docker and Kubernetes executors

3.3 Runners自动伸缩配置

使用docker machine按需创建云上的主机、在这些主机上执行作业。详细内容请参考:Runners autoscale configuration

在AWS ECW上自动伸缩GitLab Runner

在AWS Fargate上自动伸缩GitLab CI

3.4 Runner系统服务

可覆盖默认的系统服务配置,如systemd、upstart。详细内容请参考:The system services of GitLab Runner

3.5 Runner 命令行

详细内容请参考:GitLab Runner commands

查看命令行帮助:

  • gitlab-runner --help
  • gitlab-runner <command> --help

3.5.1 与注册相关的命令

详细内容请参考:Registration-related commands

  • gitlab-runner register
    • Interactive registration
    • Non-interactive registration
  • gitlab-runner list
  • gitlab-runner verify
  • gitlab-runner unregister

3.5.2 与服务相关的命令

详细内容请参考:Service-related commands

  • gitlab-runner install
  • gitlab-runner uninstall
  • gitlab-runner start
  • gitlab-runner stop
  • gitlab-runner restart
  • gitlab-runner status
  • Multiple services

3.5.3 与执行相关的命令

详细内容请参考:Run-related commands

  • gitlab-runner run
  • gitlab-runner run-single
  • gitlab-runner exec

3.5.4 内部命令

详细内容请参考:Internal commands

  • gitlab-runner artifacts-downloader
  • gitlab-runner artifacts-uploader
  • gitlab-runner cache-archiver
  • gitlab-runner cache-extractor

3.6 功能标志

使用指定的环境变量启用或禁用特定功能,详细内容请参考:Feature flags

4. 注册Runner

详细内容请参考:Registering runners

  • 交互式注册
  • 单行命令注册
  • 使用--template-config 模板文件注册

模板文件示例:

[[runners.kubernetes.volumes.empty_dir]]
  name = "empty_dir"
  mount_path = "/path/to/empty_dir"
  medium = "Memory"

5. 执行器

执行器用于在不同的场景下执行作业,详细内容请参考:Executors

  • Shell
  • Docker
  • Docker Machine (auto-scaling)
  • Kubernetes
  • Parallels
  • VirtualBox
  • SSH
  • Custom

6. Runner监控

GitLab Runner通过内嵌HTTP服务器(默认端口是9252)的/metrics发布Prometheus指标,可被Prometheus或其它客户端抓取。详细内容请参考:GitLab Runner monitoring

回复

使用道具 举报

意见建议

Email:forum@gitlab.cn
  • 关注公众号
  • 添加专业顾问
Copyright © 2001-2024 极狐GitLab论坛 版权所有 All Rights Reserved. 鄂ICP备2021008419号-1|鄂公网安备42018502006137号
关灯 快速发帖
扫一扫添加专业顾问
返回顶部
快速回复 返回顶部 返回列表