Skip to content

Commit 4f2d5c6

Browse files
Qi ZhengZhongbaoShi
Qi Zheng
authored andcommitted
Unify the tags way
For version format x.y.z, three tags as below tag: x.y.z tag1: x.y tag2: x They all point to the latest image. Once app got updated (minor updates, z to z1), the tag x.y.z will be replaced by x.y.z1, but the tag x or x.y may still keep. Signed-off-by: Qi Zheng <[email protected]>
1 parent 0de0d45 commit 4f2d5c6

File tree

21 files changed

+68
-152
lines changed

21 files changed

+68
-152
lines changed

docker-hooks.sh

+27-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CLR_URL="https://cdn.download.clearlinux.org/releases"
44

55
# Return tag value or NULL if not found
66
function get_tag {
7-
pkg=$1
7+
local pkg=$1
88

99
clr_ver=`docker run --rm clearlinux/os-core cat /usr/lib/os-release | grep VERSION_ID`
1010
clr_ver=${clr_ver##*=}
@@ -29,20 +29,42 @@ function get_tag {
2929
}
3030

3131
function get_tags_in_docker {
32-
img=$1
32+
local img=$1
3333

3434
tag_url="https://registry.hub.docker.com/v2/repositories/$img/tags/"
3535
tags=$(curl $tag_url 2>/dev/null | docker run -i stedolan/jq '."results"[]["name"]')
3636
echo $tags
3737
}
3838

39+
# For version format x.y.z, three tags as below
40+
# x.y.z, x.y and x
3941
function tag_and_push {
42+
# For version format x.y.z, three tags as below
43+
# tag: x.y.z
44+
# tag1: x.y
45+
# tag2: x
4046
local tag=$1
41-
local major_tag=$2
47+
local tag1=${tag%.*}
48+
local tag2=${tag%%.*}
49+
local image=$2
4250

4351
set -e
4452
docker tag $image:latest $image:$tag
4553
docker push $image:$tag
46-
docker tag $image:latest $image:$major_tag
47-
docker push $image:$major_tag
54+
docker tag $image:latest $image:$tag1
55+
docker push $image:$tag1
56+
docker tag $image:latest $image:$tag2
57+
docker push $image:$tag2
58+
}
59+
60+
function do_tag {
61+
local image=$1
62+
local pkg=$2
63+
64+
echo "=> Tagging the $image"
65+
local tag=$(get_tag $pkg)
66+
67+
if [ $? -eq 0 ] && [ -n "$tag" ]; then
68+
tag_and_push $tag $image
69+
fi
4870
}

golang/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/golang"
7-
tag=$(get_tag go)
5+
package=go
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format x.y, such as 1.12, 1.13
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

haproxy/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/haproxy"
7-
tag=$(get_tag haproxy)
5+
package=haproxy
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format 1.6 or 2.0
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

httpd/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/httpd"
7-
tag=$(get_tag httpd)
5+
package=httpd
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

iperf/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/iperf"
7-
tag=$(get_tag iperf)
5+
package=iperf
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

mariadb/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/mariadb"
7-
tag=$(get_tag mariadb)
5+
package=mariadb
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

memcached/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/memcached"
7-
tag=$(get_tag memcached)
5+
package=memcached
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format like 1.4 or 1.5
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

nginx/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/nginx"
7-
tag=$(get_tag nginx-mainline)
5+
package=nginx-mainline
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format 1.16 or 1.17
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

node/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/node"
7-
tag=$(get_tag nodejs)
5+
package=nodejs
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

openjdk/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/openjdk"
7-
tag=$(get_tag openjdk13)
5+
package=openjdk13
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

openvino/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/openvino"
7-
tag=$(get_tag dldt)
5+
package=dldt
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

perl/hooks/post_push

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/perl"
7-
tag=$(get_tag perl)
5+
package=perl
6+
7+
do_tag $image $package
88

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi

php-fpm/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/php-fpm"
7-
tag=$(get_tag php)
5+
package=php
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

php/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/php"
7-
tag=$(get_tag php)
5+
package=php
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

postgres/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/postgres"
7-
tag=$(get_tag postgresql11)
5+
package=postgresql11
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

python/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/python"
7-
tag=$(get_tag python3)
5+
package=python3
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format x.y, such as 3.6 , 3.7
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

rabbitmq/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/rabbitmq"
7-
tag=$(get_tag rabbitmq-server)
5+
package=rabbitmq-server
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

redis/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/redis"
7-
tag=$(get_tag redis-native)
5+
package=redis-native
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

ruby/hooks/post_push

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/ruby"
7-
tag=$(get_tag ruby)
5+
package=ruby
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
major_tag=${tag%%.*}
11-
tag_and_push $tag $major_tag
12-
fi
7+
do_tag $image $package

tensorflow-serving/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/tensorflow-serving"
7-
tag=$(get_tag tensorflow-serving)
5+
package=tensorflow-serving
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format x.y, such as 1.14
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

tensorflow/hooks/post_push

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#!/bin/bash
2-
echo "=> Tagging the image"
3-
42
. ../docker-hooks.sh
53

64
image="clearlinux/tensorflow"
7-
tag=$(get_tag tensorflow)
5+
package=tensorflow
86

9-
if [ $? -eq 0 ] && [ -n "$tag" ]; then
10-
# major tag format x.y, such as 1.16
11-
major_tag=${tag%.*}
12-
tag_and_push $tag $major_tag
13-
fi
7+
do_tag $image $package

0 commit comments

Comments
 (0)