aboutsummaryrefslogtreecommitdiff
path: root/autotag.sh
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-12-04 22:42:27 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-12-04 22:42:27 +0100
commit0766a2b86d5a1703fe1d13a54012565e38efae71 (patch)
treed9350ffa66c91967c2ad4312783bac37a9050dab /autotag.sh
First commitHEADmaster
Diffstat (limited to 'autotag.sh')
-rwxr-xr-xautotag.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/autotag.sh b/autotag.sh
new file mode 100755
index 0000000..d3de206
--- /dev/null
+++ b/autotag.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+#Clyhtsuriva
+
+PURPLE='\033[1;35m'
+RED='\033[0;31m'
+NC='\033[0m'
+
+#just for aesthetic when printing on stdout
+[ -z "$1" ] && printf "${RED}Image name required${NC}\n" && exit 1 #the user should give us the image name
+
+image="$1"
+host="localhost"
+port=5000
+
+request="curl -s "$host":"$port"/v2/"$image"/tags/list"
+json=$($request) #actually do the request
+printf "${PURPLE}request: $request\n"
+printf "json response: $json${NC}\n"
+
+[ -n "$(grep "error" <<< $json)" ] && printf "${RED}Image not found${NC}\n" && exit 1
+
+parsed=$(cut -d: -f3 <<< $json) #only takes what's after "tags"
+i=1
+max_found=0
+buffer=0
+
+while [ $max_found -eq 0 ]; do
+
+ if [ ! -z $(grep "v" <<< $(cut -d'"' -f$i <<< $parsed)) ]; then
+ #if there is a v when cutting with the delimiter "
+ latest=$(cut -d'"' -f$i <<< $parsed) #since it's ok, we're saving it
+ [ $(sed 's/v//g' <<< $latest) -gt $buffer ] && buffer=$(sed 's/v//g' <<< $latest)
+ #save in buffer in greater than anything else
+ fi
+
+ ((i++)) # incrementing
+ if [ -z $(cut -d'"' -f$i <<< $parsed) ]; then
+ max_found=1 #if it's empty, it means we are out of tags
+ fi
+done
+
+
+latest=$buffer
+version=$latest
+((version++))
+printf "${PURPLE}latest version: v$latest\n"
+printf "new tag: v$version\n"
+
+printf "Tagging ...${NC}\n"
+docker tag $image localhost/$image:v$version
+printf "${PURPLE}Pushing ...${NC}\n"
+docker push localhost/$image:v$version
+
+printf "${PURPLE}Looking at the registry ...${NC}\n"
+$request