-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-docker-image.sh
53 lines (44 loc) · 1.37 KB
/
build-docker-image.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
#!/bin/bash
name=
while [ -z $name ]; do
printf "\e[1;46mEnter the image name:\e[0m ";
read -r name;
done
version=
while [ -z $version ]; do
printf "\e[1;46mEnter the tag of your image:\e[0m ";
read -r version;
done
branch=$(git branch | grep '*')
echo -e "you are building an image from the following branch of your project : \e[1;41m${branch:2}\e[0m"
echo -e "your image will be \e[1;41m$name:$version\e[0m"
echo -e "do you want to continue? [Y/n]"
read accept
if [ "$accept" != "Y" ]; then
echo -e "\e[0;41mprocess aborted by user!\e[0m";
exit 1;
fi
echo -e "\e[1;30;43m-- Starting to build docker image --\e[0m"
docker build -t $name:$version .
if [ $? -ne 0 ];
then
echo -e "\e[0;41mTask build docker image failed and return an non 0 code. Abort!\e[0m";
exit 4;
else
echo -e "\e[0;42mTask build docker image successfully executed\e[0m"
fi
echo -e "Do you want to push the new image to the repository? [Y/n]"
read push
if [ "$push" != "Y" ]; then
echo -e "\e[0;42mDocker image will not be push. Use can use it localy! Process over.\e[0m";
exit 5;
fi
echo -e "\e[1;30;43m-- Starting to push image to docker hub --\e[0m"
docker push $name:$version
if [ $? -ne 0 ];
then
echo -e "\e[0;41mTask push docker image failed and return an non 0 code. Abort!\e[0m";
exit 6;
else
echo -e "\e[0;42mTask psuh docker image successfully executed\e[0m"
fi