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
CodePudding user response:
The latest version has the latest
tag. "stable" is in the eye of the beholder and not computable with the given information.
CodePudding user response:
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
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
CodePudding user response:
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 $")]
order by $x
return $x
)[last()]
'
8.0.29
[matches(.,"^\d \.\d \.\d $")]
returns only thosename
s 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 $")])
'
8.0.29