How can I determine if a specific tag is available for an image

余生颓废 提交于 2019-12-12 03:28:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!