解决gitlab runner在docker模式下报 503 Service Unavailable 错误

1年前 (2022) 程序员胖胖胖虎阿
158 0 0

gitlab runner安装并注册好后,在第一次启动时报无法拉取gitlab-runner-helper错误:

Running with gitlab-runner 15.3.0 (bbcb5aba)
  on debian-docker CHvjghoP
  feature flags: FF_USE_FASTZIP:true
Preparing the "docker" executor
00:02
Using Docker executor with image ruby:3.0 ...
Pulling docker image registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-bbcb5aba ...
WARNING: Failed to pull image with policy "always": Error response from daemon: Head "https://registry.gitlab.com/v2/gitlab-org/gitlab-runner/gitlab-runner-helper/manifests/x86_64-bbcb5aba": received unexpected HTTP status: 503 Service Unavailable (manager.go:235:1s)
ERROR: Job failed: failed to pull image "registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-bbcb5aba" with specified policies [always]: Error response from daemon: Head "https://registry.gitlab.com/v2/gitlab-org/gitlab-runner/gitlab-runner-helper/manifests/x86_64-bbcb5aba": received unexpected HTTP status: 503 Service Unavailable (manager.go:235:1s)

分析错误信息发现runner首先想拉取一个registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-bbcb5aba镜像,该镜像的作用应该是加速下载速度、安全链接、设置环境变量以及添加附件的软件等,由于默认的helper镜像位于gitlab的官方docker仓库中,而在接取此仓库时发生了503错误。

解决方案

gitlab runner需要一个helper,这是必须的。而当前的问题是:这个registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-bbcb5aba发生了503(可能是由于认证引起的)。

所以我们要做的是:重新为gitlab runner指定一个不需要权限认证的gitlab-runner-helper,幸运的是docker官方提供了这个image.

重新设置helper

我们打来gitlab runner所在服务器,登录后先查看自己的gitlab runner版本:

root@debian-docker:/etc/gitlab-runner# gitlab-runner -v
Version:      15.3.0
Git revision: bbcb5aba
Git branch:   15-3-stable
GO version:   go1.17.9
Built:        2022-08-19T22:41:11+0000
OS/Arch:      linux/amd64

然后找到配置文件config.toml

  1. 当以root用户在*nix系统上运行Gitlab Runner时,路径在 /etc/gitlab-runner/
  2. 当以及非root用户在*nix系统上运行Gitlab Runner时,路径在 ~/.gitlab-runner/
  3. 其它的系统,在./

然后添加以下信息:

  [runners.docker]
    ...
    helper_image="gitlab/gitlab-runner-helper:x86_64-${CI_RUNNER_VERSION}"

GitLab Runner 版本小于13.2的,加入以下信息:

  [runners.docker]
    ...
    helper_image="gitlab/gitlab-runner-helper:x86_64-${CI_RUNNER_REVISION}"

配置变更后,重新跑Job,再次查看日志,发现以下错误:

ERROR: Job failed: failed to pull image "gitlab/gitlab-runner-helper:x86_64-15.3.0" with specified policies [always]: Error response from daemon: manifest for gitlab/gitlab-runner-helper:x86_64-15.3.0 not found: manifest unknown: manifest unknown (manager.go:235:3s)

此时已经不再是504错误了,而且请求的image地址也变成了我们配置的itlab/gitlab-runner-helper:x86_64-15.3.0,说明刚刚的配置生效了。但是很遗憾docker hub上并不存在x86_64-15.3.0版本:

解决gitlab runner在docker模式下报 503 Service Unavailable 错误

即然这样,那我想用下最新的版本应该问题不大吧,当前最新的版本是x86_64-v14.10.2

所以我再次修改配置文件config.toml,把helper的版本改成x86_64-v14.10.2

  [runners.docker]
    ...
    helper_image="gitlab/gitlab-runner-helper:x86_64-v14.10.2"

重新运行job,拉取成功的画面来了:

解决gitlab runner在docker模式下报 503 Service Unavailable 错误

总结

此错误在google上搜索并没有找到傻瓜式的答案,所以解决问题的方向还是要由报错信息及原理上猜想。由官方文档或许到helper是必须要安装的image,然后由报错的地址发现其无法正常拉取image。于是最终把解决的关键点放到了:手动指定image的地址上来。

相关文章

暂无评论

暂无评论...