How to check if a docker image is already built on GitHub packages #26999
-
This question have no answers on stackoverflow and I would appreciate a solution if exists. Summory of the question: How can I check if my github workflow allready has build a docker image for this commit? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hi @jactor-rises , You could use Docker Registry API v2 to list image tags . Then you could compare the tags with the current commit sha. The API url for GitHub Package Registry is like: https://docker.pkg.github.com/v2/{org}/{repo}/{image_name}/tags/list |
Beta Was this translation helpful? Give feedback.
-
Hi, you can use the Github Packages preview GraphQL API with connection with bash invocation of jq. This is example of how I am doing it.
And then something like:
|
Beta Was this translation helpful? Give feedback.
-
The suggested solutions seems to include lots of coding and such code is hard to maintain. From https://docs.docker.com/registry/spec/api/: Existing Manifests The image manifest can be checked for existence with the following url:
The name and reference parameter identify the image and are required. The reference may include a tag or digest. A 404 Not Found response will be returned if the image is unknown to the registry. If the image exists and the response is successful the response will be as follows:
Would it not be easier to try and get the manifest for a docker image and see if it exists or not? Examples? |
Beta Was this translation helpful? Give feedback.
-
Hi @jactor-rises , You could use docker registry api to get image manifest for Github Package Registry.
|
Beta Was this translation helpful? Give feedback.
-
@yanjingzhu : do you need some special permissions to do this? From output from use of action https://github.com/navikt/bidrag-docker/tree/master/exists (see exists.sh): 1s 1 Run navikt/bidrag-docker/exists@v1 2 with: 3 image_name: bidrag-dokument 4 GITHUB_TOKEN: *** 5 env: 6 IMAGE: docker.pkg.github.com/navikt/bidrag-dokument/bidrag-dokument:d4cc1bcd2ff78387b19db6f15261ba5207beab1c 7/bin/bash /home/runner/work/_actions/navikt/bidrag-docker/v1/exists/dist/…/exists.sh bidrag-dokument 8 % Total % Received % Xferd Average Speed Time Time Time Current 9 Dload Upload Total Spent Left Speed 11 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0 12 0 205 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0 14Headere i respons fra https://docker.pkg.github.com/v2/navikt/bidrag-dokument/bidrag-dokument/manifests/d4cc1bcd2ff78387b19db6f15261ba5207beab1c: 15---- 16HTTP/1.1 401 Unauthorized 17Content-Security-Policy: default-src ‘none’; 18Docker-Distribution-Api-Version: registry/2.0 19Server: GitHub Registry 20Strict-Transport-Security: max-age=31536000; 21X-Content-Type-Options: nosniff 22X-Frame-Options: DENY 23X-Xss-Protection: 1; mode=block 24Date: Sat, 09 May 2020 08:06:57 GMT 25Content-Length: 205 26Content-Type: text/plain; charset=utf-8 27X-GitHub-Request-Id: 0400:2CD7:6D029:ECA4F:5EB664A1 30Found 0 mentions of HTTP/1.1\ 404 31unauthorized, assuming not found |
Beta Was this translation helpful? Give feedback.
-
When execute curl request, -u parameter is used to pass user and password. Please make sure the GITHUB_TOKEN is passed to scripts in exists.sh. |
Beta Was this translation helpful? Give feedback.
Hi @jactor-rises ,
You could use docker registry api to get image manifest for Github Package Registry.