Gitlab CI 进程中未能拉取Gitlab注册表图像。

huangapple go评论65阅读模式
英文:

Gitlab registry images not getting pulled in Gitlab CI progcess

问题

我使用/kaniko/executor构建镜像并推送到gitlab容器注册表(参考下面的脚本)。镜像已创建并复制到容器注册表。

现在我在不同项目的gitlab-ci流程中使用此基础镜像,但遇到以下错误。

警告/错误日志片段:

警告:无法拉取策略为""的镜像:拉取镜像失败:rpc错误:代码=未知描述=无法拉取和解压缩镜像"registry.gitlab.com/:v1.0.0":无法解析引用"registry.gitlab.com/:v1.0.0":拉取访问被拒绝,仓库不存在或可能需要授权:服务器消息:权限不足:授权失败

错误:作业失败:准备环境:等待容器运行中:拉取镜像"registry.gitlab.com/:v1.0.0"失败:rpc错误:代码=未知描述=无法拉取和解压缩镜像"registry.gitlab.com/:v1.0.0":无法解析引用"registry.gitlab.com/:v1.0.0":拉取访问被拒绝,仓库不存在或可能需要授权:服务器消息:权限不足:授权失败。请查看https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading了解更多信息

.gitlab-ci.yaml文件代码用于创建镜像并推送到容器注册表:

变量:
  GIT_STRATEGY: clone
  IMAGE_VERSION: v1.0.0

默认:
  标签:
    - 应用程序

阶段:
  - 构建

构建gitlab容器:
  阶段:构建
  镜像:
    名称:gcr.io/kaniko-project/executor:debug
    入口点:[""]
  脚本:
    - echo "{"auths":{"$CI_REGISTRY":{"username":"$CI_REGISTRY_USER","password":"$CI_REGISTRY_PASSWORD"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$IMAGE_VERSION
英文:

I am using /kaniko/executor to build the image and push to gitlab container registry (refer below script ). Image getting created and copied to container registry.

Now I am using this base image into gitlab-ci process of different project with image tag but getting below error.

**Warning/Error log snippet : **

WARNING: Failed to pull image with policy "": image pull failed: rpc error: code = Unknown desc = failed to pull and unpack image "registry.gitlab.com/<project-path>:v1.0.0": failed to resolve reference "registry.gitlab.com/<project-path>:v1.0.0": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

ERROR: Job failed: prepare environment: waiting for pod running: pulling image "registry.gitlab.com/<project-path>:v1.0.0": image pull failed: rpc error: code = Unknown desc = failed to pull and unpack image "registry.gitlab.com/<project-path>:v1.0.0": failed to resolve reference "registry.gitlab.com/<project-path>:v1.0.0": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

.gitlab-ci.yaml file code to create image and push to container registry:

variables:
  GIT_STRATEGY: clone
  IMAGE_VERSION: v1.0.0

default:
  tags:
    - applications

stages:
  - build

build_gitlab_container:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [&quot;&quot;]
  script:
    - echo &quot;{\&quot;auths\&quot;:{\&quot;$CI_REGISTRY\&quot;:{\&quot;username\&quot;:\&quot;$CI_REGISTRY_USER\&quot;,\&quot;password\&quot;:\&quot;$CI_REGISTRY_PASSWORD\&quot;}}}&quot; &gt; /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$IMAGE_VERSION


So far I have validated below options

  1. Incorrect repository URL : My repository is correct
  2. Authorization details
  3. Insufficient scope - I am owner of this gitlab subgroup and project.

答案1

得分: 1

我遇到了一个新项目的同样问题。

转到设置 > CI/CD > 令牌访问以获取基础图像项目,并添加到您的目标项目中。

记得从路径中删除/

Gitlab CI 进程中未能拉取Gitlab注册表图像。

英文:

I was facing same problem for a new project.

Go to Settings &gt; CI/CD &gt; Token Access for the base image project, and add your target project.

Gitlab CI 进程中未能拉取Gitlab注册表图像。

Do remember to trim / from path.

huangapple
  • 本文由 发表于 2023年4月20日 09:45:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定