-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_image.sh
executable file
·51 lines (40 loc) · 1.67 KB
/
build_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
#!/bin/bash
echo $#
if [ "$#" -ge 3 ]
then
DIRECTORY=$1
DOCKER_REPOSITORY=$2
DOCKER_TAG=$3
DOCKER_FILE=$4
DOCKER_FULL_NAME="$DOCKER_REPOSITORY:$DOCKER_TAG"
DOCKER_FULL_NAME_LATEST="$DOCKER_REPOSITORY:latest"
cd $DIRECTORY
echo -e "\x1B[1;32m---- Building docker image \x1B[1;33m[$DOCKER_LOCAL_TAG]\x1B[1;32m...\x1B[0m"
echo "Building RELEASE version .."
echo "Tag=$DOCKER_FULL_NAME"
echo "Tag=$DOCKER_FULL_NAME_LATEST"
docker build --force-rm=true --pull=true --tag="$DOCKER_FULL_NAME" -f $DOCKER_FILE "$(pwd)"
if [ "$?" -eq 0 ]
then
echo -e "\x1B[1;32m---- Build finished.\x1B[0m"
#echo -e "\x1B[1;32m---- Push finished.\x1B[0m"
echo -e "\x1B[1;32mAll finished locally.\x1B[0m"
# push to docker hub
if [ "$#" -ge 5 ]
then
echo -e "\x1B[1;32mPushing to Docker Hub...\x1B[0m"
docker login -u $4 -p $5
echo "docker push $DOCKER_FULL_NAME"
docker push $DOCKER_FULL_NAME
docker push $DOCKER_FULL_NAME_LATEST
else
echo -e "\x1B[1;32m[WARN] You have not provided your Docker Hub user/pass. Images are not pushed to the Hub!\x1B[0m"
fi
echo -e "\x1B[1;32mAll finished.\x1B[0m"
else
echo -e "\x1B[1;32m[ERROR] Build error!\x1B[0m"
fi
cd ..
else
echo -e "\x1B[1;32m[ERROR] Invalid parameters! Usage: build_image.sh <directory> <image_repo> <image_tag>\x1B[0m"
fi