-
Notifications
You must be signed in to change notification settings - Fork 2
/
dockerhub-tag.sh
executable file
·58 lines (50 loc) · 1.44 KB
/
dockerhub-tag.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
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Docker Tag Container (DockerHub)
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni
# License : Apache v2
# -----------------------------------------------------------------------------
set -e
# export CI_PROJECT_PATH="devopscorner"
# export CI_PROJECT_NAME="k8s-context"
# export IMAGE="$CI_PROJECT_PATH/$CI_PROJECT_NAME"
export IMAGE=$1
set_tag() {
export BASE_IMAGE=$2
export TAGS_ID=$3
export CUSTOM_TAGS=$4
export COMMIT_HASH=$(git log -1 --format=format:"%H")
if [ "$CUSTOM_TAGS" = "" ]; then
export TAGS="$TAGS_ID \
$BASE_IMAGE-$TAGS_ID \
$TAGS_ID-$COMMIT_HASH \
$BASE_IMAGE-$COMMIT_HASH "
else
export TAGS="$TAGS_ID \
$BASE_IMAGE-$TAGS_ID \
$TAGS_ID-$COMMIT_HASH \
$BASE_IMAGE-$COMMIT_HASH \
$TAGS_ID-$CUSTOM_TAGS"
fi
}
docker_tag() {
for TAG in $TAGS; do
echo "Docker Tags => $IMAGE:$TAG"
echo ">> docker tag $IMAGE:$BASE_IMAGE $IMAGE:$TAG"
docker tag $IMAGE:$BASE_IMAGE $IMAGE:$TAG
echo '- DONE -'
echo ''
done
}
main() {
# set_tag devopscorner/k8s-context alpine [version|latest|tags] [custom-tags]
set_tag $1 $2 $3 $4
docker_tag
echo ''
echo '-- ALL DONE --'
}
### START HERE ###
main $1 $2 $3 $4
### How to Execute ###
# ./dockerhub-tag.sh [DOCKERHUB_IMAGE_PATH] [alpine] [version|latest|tags] [custom-tags]