【问题标题】:How to check if a version of a GitHub docker image already exists?如何检查一个版本的 GitHub docker 镜像是否已经存在?
【发布时间】:2020-07-08 13:36:53
【问题描述】:

当 GitHub 包注册表成为解决方案时,这个问题得到了解答。现在已弃用,我最近移至新的GitHub Packages Container registry,想知道现在应该如何完成?

我的 docker 镜像现在看起来像这样:

env:
  IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }}

我正在使用 GitHub 操作在 GitHub 上创建“DevOps”工作流。

有时集成测试会失败,因此我的工作流程也会失败。这些故障通常是由集成测试中的故障引起的,在修改测试时不需要修改额外的代码。

当我重新启动我的工作流程时,我的代码会在它作为 docker 图像上传到 GitHub(再次)之前重新构建(和测试)。

我的问题:如何检查我的 docker 镜像是否已经创建并上传到我的 GitHub 包,这样我就不需要重建相同的镜像了?

我的工作流程 yaml 文件包含我的 docker 映像的此配置:

env:
  IMAGE: docker.pkg.github.com/${{ github.repository }}/awesome-module:${{ github.sha }}

我也在尝试使用 GitHub 社区寻找解决方案,但到目前为止还没有运气。见线程https://github.community/t5/GitHub-Actions/How-to-check-if-a-docker-image-is-already-built-on-GitHub/m-p/56364/highlight/false#M9845

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    来自 GitHub 社区:

    on: push
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
        - name: Check package version 
          run: |
            manifest=$(curl -X GET https://docker.pkg.github.com/v2/{org}/{repo}/{image name}/manifests/$GITHUB_SHA -u $GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }} | jq '.')
            echo $manifest
    

    【讨论】:

      【解决方案2】:

      你可以使用docker manifest inspect docker.pkg.github.com/<repo>/<image>@sha256:<sha>然后检查输出

      图片存在:

      > docker manifest inspect hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
      {
              "schemaVersion": 2,
              "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
              "config": {
                      "mediaType": "application/vnd.docker.container.image.v1+json",
                      "size": 1520,
                      "digest": "sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57"
              },
              "layers": [
                      {
                              "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
                              "size": 972,
                              "digest": "sha256:b04784fba78d739b526e27edc02a5a8cd07b1052e9283f5fc155828f4b614c28"
                      }
              ]
      }
      

      图片不存在:

      > docker manifest inspect hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74e
      no such manifest: docker.io/library/hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74e
      

      【讨论】:

      • docker manifest inspect is only supported on a Docker cli with experimental cli features enabled
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 2015-08-13
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      相关资源
      最近更新 更多