-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerHubUpdate.sh
executable file
·60 lines (49 loc) · 966 Bytes
/
dockerHubUpdate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/env bash
function fail {
printf 'FAIL [%s]\n' "$1" >&2
exit "${2-1}"
}
export IMAGE="mrnetops/fastly-exporter"
echo "
#
# Remove all current tags for ${IMAGE}
#
"
docker images --no-trunc \
| grep -P "^${IMAGE}\s+" \
| awk '{print $3;}' \
| sort -u \
| xargs -r docker rmi -f
echo "
#
# Initial docker build
#
"
docker build . -t ${IMAGE}:latest \
|| fail "docker build"
echo "
#
# Major, minor and patch tags from the application version string
#
"
output=`docker run ${IMAGE}:latest -version` \
|| fail "docker run"
version=`echo $output | grep -oP '(?!=v)\d+\.\d+\.\d+'` \
|| fail "version"
tag_patch=${version%-*%-*} \
|| fail "tag_patch"
tag_minor=${tag_patch%.*} \
|| fail "tag_minor"
tag_major=${tag_minor%.*} \
|| fail "tag_major"
docker build . \
-t ${IMAGE}:latest \
-t ${IMAGE}:${tag_major} \
-t ${IMAGE}:${tag_minor} \
-t ${IMAGE}:${tag_patch} \
echo "
#
# Push to dockerhub
#
"
docker push --all-tags ${IMAGE}