如何确定特定标签是否可用于图像 [英] How can I determine if a specific tag is available for an image
问题描述
我目前正在使用它来检查gcr.io上是否有可用的图像.
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")"
tags_json=$(curl "https://gcr.io/v2/${repo}/${image}/tags/list" 2>/dev/null)
tags_found="$(echo "${tags_json}" | jq ".tags | indices([\"${version}\"]) | any")"
这很不幸,因为与某些LTS发行版相比,支持indices
的jq
版本是相当新的.
This is unfortunate because the version of jq
that supports indices
is rather new compared to some LTS distros out there...
我可以在docker.io上解决这个问题,它可以与jq
的旧版本一起使用:
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?")"
tags_json=$(curl "https://registry.hub.docker.com/v2/repositories/${repo}/${image}/tags/${version}/" 2>/dev/null)
tags_found="$(echo "${tags_json}" | jq ".v2?")"
是否有更好的方法可以做到这一点?我看到有人提到GCR在典型的docker Registry协议的基础上支持一些扩展.我在这里可以使用的任何东西.
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.
推荐答案
您可以使用python json解析工具.
You can use python json parse tool.
下面是一个示例: curl https://gcr.io/v2/ $ {repo}/$ {image}/tags/list 2>/dev/null | python -c'导入sys,json;在json.load(sys.stdin)["tags"]'$ {version}
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}
希望这会有所帮助!
这篇关于如何确定特定标签是否可用于图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!