How to get a new tag for an image?

Given the following list of images, how can I get the latest tags? (0.0.268) I assume this is possible with a combination of bash and the Go template, but I cannot 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- IBM Bluemix CLI):

tagsList=$(bx cr images --format "{{if (eq .Repository \"myregistry/mynamespace/myimage\")}} {{.Tag}}{{end}}")

Echo $tagsList:

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

From this list I need a new tag, which 0.0.15.

+6
source share
2 answers

To get the latest 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 .: .
-k n,n: n th ( 1)
-nr: ( )
-k1,1 -k2,2 -k3,3: 1, 2, 3, , , .

:

10.0.10
+5

() :

golang

0

All Articles