-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecr-tag.sh
executable file
·59 lines (51 loc) · 1.64 KB
/
ecr-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
59
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Docker Tag Container (Elastic Container Registry - ECR)
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni
# License : Apache v2
# -----------------------------------------------------------------------------
set -e
export AWS_ACCOUNT_ID=$1
export CI_REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.ap-southeast-1.amazonaws.com"
export CI_ECR_PATH=$2
export IMAGE="$CI_REGISTRY/$CI_ECR_PATH"
set_tag() {
export BASE_IMAGE=$3
export TAGS_ID=$4
export CUSTOM_TAGS=$5
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 [AWS_ACCOUNT] devopscorner/nifi [alpine|ubuntu] [version|latest|tags] [custom-tags]
# set_tag [AWS_ACCOUNT] devopscorner/nifi-registry [alpine|ubuntu] [version|latest|tags] [custom-tags]
set_tag $1 $2 $3 $4 $5
docker_tag
echo ''
echo '-- ALL DONE --'
}
### START HERE ###
main $1 $2 $3 $4 $5
### How to Execute ###
# ./ecr-tag.sh [AWS_ACCOUNT] [ECR_PATH] [alpine|ubuntu] [version|latest|tags] [custom-tags]