Docker 映像摘要与推送到 Github 容器注册表后生成的摘要不同

Docker image digest is different to the resulting digest once pushed to the Github Container Registry

我在 Github 操作上有一个 CI 管道,用于构建和推送 docker 图像,然后,我有一个单独的存储库,其中有一个我从命令触发的操作行,将 docker 图像作为参数,然后将其应用于 Kustomize 模板

这是一个例子CI

docker build . -t ghcr.io/myOrg/myApp:${{ commitSha }}
docker push ghcr.io/myOrg/myRepo:${{ commitSha }}

gh workflow run update_image.yml -R myOrg/myInfraRepo -f image=ghcr.io/myOrg/myRepo@$(docker images --no-trunc --quiet ghcr.io/myOrg/myApp:${{ commitSha }})

测试时,整个流程正常,并使用图像和摘要触发工作流程,但是,摘要似乎不正确

当我通过 github 包检查容器时,我可以看到以下清单

{
  "digest": "sha256:9e32f9292cbe63d27374fd467ad5e530112cbfddf17c250ca90e087bdfcd436e",
  "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
  "size": 1998,
  "config": {
    "digest": "sha256:6f7e582643c22f4e41021be851bb0394c0e326e8fe06c7d3e890316d1a0234e9",
    "mediaType": "application/vnd.docker.container.image.v1+json",
    "size": 8755
  },
  "layers": [
...

两个摘要不同,docker images --no-trunc --quiet输出的是config.digest下的摘要,不是顶层摘要。我不明白为什么它们不同,这是注册表摘要吗? 如果是这样,我如何通过命令行获取该摘要?

好吧,我设法解决了这个问题。我使用了错误的命令来获取摘要。

docker images --no-trunc --quiet ghcr.io/myOrg/myApp:${{ commitSha }}

有效,但这只是本地摘要。我用

中的这个替换了它
docker inspect --format='{{index .RepoDigests 0}}' $IMAGE

其中 returns 全名和远程摘要。所以现在我的最终命令是这样的:

gh workflow run update_image.yml -R myOrg/myInfraRepo -f image=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/myOrg/myApp:${{ commitSha }})