docker - 无法使用 kaniko 从 GitLab CI 构建 Docker 镜像并将其推送到(私有(private))Artifactory

标签 docker gitlab gitlab-ci artifactory kaniko

我正在设计一个 GitLab CI 管道来为给定服务构建 Docker 镜像。

这就是 Gitlab CI list 到目前为止的样子(相关摘录):

...

publish-docker-image:
  stage: publish
  dependencies:
    - assemble
  image:
    name: docker.tld.com/namespace/kaniko:latest # At work they offer a custom kaniko image
    entrypoint: [""]
  script:
    - mkdir --parents /kaniko/.docker/
    - mv $kaniko_config /kaniko/.docker/config.json # $kaniko_config is a file variable from GitLab CI
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0

$kaniko_config 文件转换为以下 JSON:

{
  "auths": {
    "https://artifactory.tld.com/": {
      "username": "the_real_username",
      "password": "the_real_password"
    }
  }
}

现在每次运行管道时我都会得到以下输出:

$ mkdir --parents /kaniko/.docker/
$ mv $kaniko_config /kaniko/.docker/config.json
$ cat /kaniko/.docker/config.json
{
  "auths": {
    "https://artifactory.tld.com/": {
      "username": "the_real_username",
      "password": "the_real_password"
    }
  }
}
$ /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0
error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: checking push permission for "artifactory.tld.com/artifactory/docker-snapshot/organization/project/kaniko-test:0.1.0": creating push check transport for artifactory.tld.com failed: GET https://artifactory.tld.com/v2/: : Not Found
Cleaning up file based variables

我在这里做错了什么?此外,我不知道为什么错误消息上有 https://artifactory.tld.com/v2/ (/v2),因为我不是使用类似的东西。

最佳答案

对于将来遇到此问题的任何人 - kaniko-config.json 文件应具有以下结构:

{
  "auths": {
    "<artifactory-docker-registry>": {
      ...
    }
  }
}

可以使用 Set Me Up 检索“artifactory-docker-registry” JFrog 平台 UI 中的按钮。

关于docker - 无法使用 kaniko 从 GitLab CI 构建 Docker 镜像并将其推送到(私有(private))Artifactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67713978/

相关文章:

docker - Gitlab 中的软件包和注册表中缺少容器注册表

mongodb - 如何连接到我的Docker的远程服务器中的Mongo DB?

Git 推送失败

variables - 为仅针对一个管道运行的作业动态保存 GitLab 变量

gitlab - 部署作业后如何在作业中获取环境 URL?

windows - Windows docker 容器的图形输出

typescript - XSym : not found while executing binary in Docker on Windows

gitlab - 如何在 gitlab-ci 中定义数组类型变量

android - java.lang.IllegalStateException : Dex archives: setting . DEX 扩展仅适用于 .CLASS 文件

bash - Gitlab:使用 grep 的管道命令不起作用?