Given the following list of images, how would I retrieve the newest of the tags? (0.0.268) I guess it's possible with a combination of bash and Go template, but I can't figure it out...
my-image 0.0.1 fd704b8d675e
my-image 0.0.2 9294a62d2c38
my-image 0.0.9 325326e8f7a2
my-image 0.0.10 b97c64b198d9
my-image 0.0.268 8a89b5fac348
For example:
By running the following command (bx cr
is an IBM Bluemix CLI):
tagsList=$(bx cr images --format "{{if (eq .Repository \"myregistry/mynamespace/myimage\")}} {{.Tag}}{{end}}")
The echo of $tagsList
is:
0.0.10 0.0.12 0.0.13 0.0.14 0.0.15 0.0.3 0.0.4 0.0.5 0.0.7
Out of this list I need the newest tag, which is 0.0.15
.
You have several alternatives to validate the existence of the tag in the registry: Pull the whole image with the tag by using docker pull <image>:<tag> Leverage the Container Registry API. Use the GitHub Package REST API.
Simply head over to Docker Hub, choose a tag, and each time you pull the image, you'll get the latest version pushed by the authors. The downside of this is that each time a Docker tag is pulled, the latest version is used, and this is often not what you want if you value build reproducibility, and you really should!
To get the last tag <major_version>.<medium_version>.<minor_version>
:
file.txt:
my-image 0.10.1 fd704b8d675e
my-image 2.0.2 9294a62d2c38
my-image 0.0.9 325326e8f7a2
my-image 10.0.3 b97c64b198d9
my-image 10.0.10 b97c64b198d9
my-image 0.0.268 8a89b5fac348
my-image 10.0.6 b97c64b198d9
last_tag.sh:
#!/usr/bin/env bash
cut -d' ' -f2 file.txt \
| sort -t . -k1,1 -k2,2 -k3,3 -nr \
| head -1
-t .
: precise the delimiter .
-k n,n
: sort for the column n th (1-based)-nr
: sort number (no string) in decreasing order-k1,1 -k2,2 -k3,3
: sort in order column 1, column 2, column 3,
that is to say major version, medium version then minor version.
Output:
10.0.10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With