Reputation: 3089
The question was answered when GitHub package registry was the solution. This is now deprecated and I have recently moved to the new GitHub Packages Container registry and am wondering how this should be accomplished now?
My docker image is now looking like this:
env:
IMAGE: ghcr.io/${{ github.repository }}:${{ github.sha }}
I am creating "DevOps" workflows on GitHub using GitHub actions.
Sometimes integration tests fails and therefore my workflow also fails. Often these failures is caused by failures in the integration tests and no extra code is needed to be modified when the tests are modified.
When I restart my workflow, then my code is rebuild (and tested) before it is uploaded to GitHub (again) as a docker image.
My question: How can I inspect if my docker image is already created and uploaded to my GitHub package so I do not need to rebuild an identical image?
My workflow yaml file contains this configuration for my docker image:
env:
IMAGE: docker.pkg.github.com/${{ github.repository }}/awesome-module:${{ github.sha }}
I am also trying to find a solution using The GitHub community, but no luck so far. See thread https://github.community/t5/GitHub-Actions/How-to-check-if-a-docker-image-is-already-built-on-GitHub/m-p/56364/highlight/false#M9845
Upvotes: 3
Views: 3585
Reputation: 3089
From The GitHub community:
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
Upvotes: 3
Reputation: 8400
You can use docker manifest inspect docker.pkg.github.com/<repo>/<image>@sha256:<sha>
then check the output
Image exists:
> 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"
}
]
}
Image does not exist:
> docker manifest inspect hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74e
no such manifest: docker.io/library/hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74e
Upvotes: 0