问题
I'm currently using this to check if an image is available on gcr.io.
tags_json=$(curl "https://gcr.io/v2/${repo}/${image}/tags/list" 2>/dev/null)
tags_found="$(echo "${tags_json}" | jq ".tags | indices([\"${version}\"]) | any")"
This is unfortunate because the version of jq
that supports indices
is rather new compared to some LTS distros out there...
I can get away with this for docker.io, which works with older versions of jq
:
tags_json=$(curl "https://registry.hub.docker.com/v2/repositories/${repo}/${image}/tags/${version}/" 2>/dev/null)
tags_found="$(echo "${tags_json}" | jq ".v2?")"
Is there a better way to do this? I've seen mentions that GCR supports some extensions on top of the typical docker registry protocol. Anything that I can use here.
回答1:
You can use python json parse tool.
Below is an example: curl https://gcr.io/v2/${repo}/${image}/tags/list 2>/dev/null | python -c 'import sys, json; print sys.argv[1] in json.load(sys.stdin)["tags"]' ${version}
Hope this helps!
来源:https://stackoverflow.com/questions/36437885/how-can-i-determine-if-a-specific-tag-is-available-for-an-image