如何确定特定标签是否可用于图像 [英] How can I determine if a specific tag is available for an image

查看:82
本文介绍了如何确定特定标签是否可用于图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用它来检查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发行版相比,支持indicesjq版本是相当新的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆