使用JQ从Docker Hub获取最新有效的MySQL标签

发布于 2025-02-03 14:24:43 字数 729 浏览 4 评论 0原文

我正在使用以下命令从Docker Hub上的MySQL获取所有发行标签:

wget -q https://registry.hub.docker.com/v1/repositories/mysql/tags -O - | jq -r .[].name

输出是:

5.7.38
5.7.38-debian
5.7.38-oracle
5.7.4
5.7.4-m14
5.7.5
5.7.5-m15
5.7.6
5.7.6-m16
5.7.7
5.7.7-rc
5.7.8
5.7.8-rc
5.7.9
8
8-debian
8-oracle
8.0
8.0-debian
8.0-oracle
8.0.0
8.0.1
8.0.11
8.0.12
8.0.13
8.0.14
8.0.15
8.0.16
8.0.17
8.0.18
8.0.19
8.0.2
8.0.20
8.0.21
8.0.22
8.0.23
8.0.24
8.0.25
8.0.26
8.0.27
8.0.28
8.0.28-debian
8.0.28-oracle
8.0.29
8.0.29-debian
8.0.29-oracle
8.0.3
8.0.4
8.0.4-rc
debian
oracle

有没有一种方法可以获取最新的稳定版本?例如,我想获取8.0.29,因为它是8倍版本的最新稳定版本。下次,当8.0.30到来时,我从同一命令中获得输出?

任何人都可以帮我或指向正确的方向吗?我尝试使用Xidel,但找不到解决方案

I am using following command to fetch all release tags from mysql on docker hub :

wget -q https://registry.hub.docker.com/v1/repositories/mysql/tags -O - | jq -r .[].name

Output is:

5.7.38
5.7.38-debian
5.7.38-oracle
5.7.4
5.7.4-m14
5.7.5
5.7.5-m15
5.7.6
5.7.6-m16
5.7.7
5.7.7-rc
5.7.8
5.7.8-rc
5.7.9
8
8-debian
8-oracle
8.0
8.0-debian
8.0-oracle
8.0.0
8.0.1
8.0.11
8.0.12
8.0.13
8.0.14
8.0.15
8.0.16
8.0.17
8.0.18
8.0.19
8.0.2
8.0.20
8.0.21
8.0.22
8.0.23
8.0.24
8.0.25
8.0.26
8.0.27
8.0.28
8.0.28-debian
8.0.28-oracle
8.0.29
8.0.29-debian
8.0.29-oracle
8.0.3
8.0.4
8.0.4-rc
debian
oracle

Is there a way i can fetch the latest stable version only? For example , i want to fetch 8.0.29 as it is the latest stable version for 8x version . And next time when 8.0.30 comes i get the output from the same command?

Can anybody please help or point me to right direction? I tried using xidel but could not find solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十级心震 2025-02-10 14:24:43

使用扫描提取任何数字序列(“ \\ d+”),使用tonumber将字符串转换为数字,并将其用作sort_by 在初始数组上,您可以从中使用索引-1从中输出最后一个项目。

jq -r 'map(.name) | sort_by(scan("\\d+") | tonumber)[-1]'
8.0.29-oracle

demo


如果对于输出,您只需要纯版本号/code>而不是8.0.29-Oracle),在之后和包括仪表板之后放弃所有内容:

jq -r 'map(.name | .[:index("-")]) | sort_by(scan("\\d+") | tonumber)[-1]'
8.0.29

演示

Extract any sequence of digits using scan("\\d+"), convert the strings to numbers using tonumber, and use that as argument for sort_by on the initial array, from which you can then output the last item using index -1.

jq -r 'map(.name) | sort_by(scan("\\d+") | tonumber)[-1]'
8.0.29-oracle

Demo


If for the output you only want the pure version number (8.0.29 instead of 8.0.29-oracle), ditch everything after and including the dash sign:

jq -r 'map(.name | .[:index("-")]) | sort_by(scan("\\d+") | tonumber)[-1]'
8.0.29

Demo

梦一生花开无言 2025-02-10 14:24:43

我尝试使用Xidel,但找不到解决方案

如果您仍然有兴趣,这并不难:

$ xidel -s "https://registry.hub.docker.com/v1/repositories/mysql/tags" -e '
  (
    for $x in $json()/name[matches(.,"^\d+\.\d+\.\d+$")]
    order by $x
    return $x
  )[last()]
'
8.0.29
  • [artees(。 )]仅返回这些名称仅使用数字。
  • 按$ x进行排序订单。
  • ... )[last()]返回序列的最后一项(在这种情况下为最新版本)。

或者,您可以使用max()

$ xidel -s "https://registry.hub.docker.com/v1/repositories/mysql/tags" -e '
  max($json()/name[matches(.,"^\d+\.\d+\.\d+$")])
'
8.0.29

I tried using xidel but could not find solution

If you're still interested, it's not that hard:

$ xidel -s "https://registry.hub.docker.com/v1/repositories/mysql/tags" -e '
  (
    for $x in $json()/name[matches(.,"^\d+\.\d+\.\d+
quot;)]
    order by $x
    return $x
  )[last()]
'
8.0.29
  • [matches(.,"^\d+\.\d+\.\d+$")] returns only those names with just digits.
  • order by $x for sorting.
  • (...)[last()] to return the last item of the sequence (in this case the latest version).

Alternatively and even shorter, you can use max():

$ xidel -s "https://registry.hub.docker.com/v1/repositories/mysql/tags" -e '
  max($json()/name[matches(.,"^\d+\.\d+\.\d+
quot;)])
'
8.0.29
平生欢 2025-02-10 14:24:43

最新版本具有最新标签。 “稳定”是在情人眼中,而不是通过给定信息来计算的。

The latest version has the latest tag. "stable" is in the eye of the beholder and not computable with the given information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文