-
Notifications
You must be signed in to change notification settings - Fork 6
/
ecr-build.sh
executable file
·79 lines (66 loc) · 2.77 KB
/
ecr-build.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env sh
# -----------------------------------------------------------------------------
# Docker Build Container (Elastic Container Registry - ECR)
# -----------------------------------------------------------------------------
# Author : Dwi Fahni Denni
# License : Apache v2
# -----------------------------------------------------------------------------
set -e
export AWS_ACCOUNT_ID=$1
export AWS_DEFAULT_REGION="ap-southeast-1"
export CI_REGISTRY="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"
export CI_ECR_PATH=$3
export IMAGE="$CI_REGISTRY/$CI_ECR_PATH"
docker_build() {
export FILE=$2
export BASE_IMAGE=$4
export TAGS_ID=$5
export CUSTOM_TAGS=$6
if [ "$CUSTOM_TAGS" = "" ]; then
echo "Build Image => $IMAGE:$BASE_IMAGE"
echo ">> docker build -t $IMAGE:$BASE_IMAGE -f $FILE ."
docker build -t $IMAGE:$BASE_IMAGE -f $FILE .
echo '---'
echo "Build Image => $IMAGE:$TAGS_ID"
echo ">> docker build -t $IMAGE:$TAGS_ID -f $FILE ."
docker build -t $IMAGE:$TAGS_ID -f $FILE .
echo '---'
echo "Build Image => $IMAGE:$BASE_IMAGE-$TAGS_ID"
echo ">> docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID -f $FILE ."
docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID -f $FILE .
echo '---'
else
echo "Build Image => $IMAGE:$BASE_IMAGE"
echo ">> docker build -t $IMAGE:$BASE_IMAGE -f $FILE ."
docker build -t $IMAGE:$BASE_IMAGE -f $FILE .
echo '---'
echo "Build Image => $IMAGE:$TAGS_ID"
echo "docker build -t $IMAGE:$TAGS_ID -f $FILE ."
docker build -t $IMAGE:$TAGS_ID -f $FILE .
echo '---'
echo "Build Image => $IMAGE:$BASE_IMAGE-$TAGS_ID"
echo ">> docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID -f $FILE ."
docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID -f $FILE .
echo '---'
echo "Build Image => $IMAGE:$TAGS_ID-${CUSTOM_TAGS}"
docker build -t $IMAGE:$TAGS_ID-${CUSTOM_TAGS} -f $FILE .
echo ">> docker build -t $IMAGE:$TAGS_ID-${CUSTOM_TAGS} -f $FILE ."
echo '---'
echo "Build Image => $IMAGE:$BASE_IMAGE-$TAGS_ID-${CUSTOM_TAGS}"
echo ">> docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID-${CUSTOM_TAGS} -f $FILE ."
docker build -t $IMAGE:$BASE_IMAGE-$TAGS_ID-${CUSTOM_TAGS} -f $FILE .
echo '---'
fi
}
main() {
# docker_build 0987654321 Dockerfile devopscorner/bookstore alpine [version|latest|tags] [custom-tags]
# docker_build 0987654321 Dockerfile.alpine-3.15 devopscorner/bookstore alpine [version|latest|tags] [custom-tags]
# docker_build 0987654321 Dockerfile.alpine-3.16 devopscorner/bookstore alpine [version|latest|tags] [custom-tags]
docker_build $1 $2 $3 $4 $5 $6
echo ''
echo '-- ALL DONE --'
}
### START HERE ###
main $1 $2 $3 $4 $5 $6
### How to Execute ###
# ./ecr-build.sh [AWS_ACCOUNT] Dockerfile [ECR_PATH] [alpine] [version|latest|tags] [custom-tags]