-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildDockerImage.sh
executable file
·110 lines (86 loc) · 2.15 KB
/
buildDockerImage.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
usage() {
cat << EOF
Usage: buildDockerImage.sh -v [version] [Docker build option]
Builds a Docker Image for Oraclejdk
Parameters:
-v: version to build
Choose one of: $(for i in $(ls -d */); do echo -n "${i%%/} "; done)
-o: passes on Docker build option
Copyright (c) 2018 Goodrain and/or its affiliates. All rights reserved.
EOF
exit 0
}
##############
#### MAIN ####
##############
if [ "$#" -eq 0 ]; then
usage;
fi
# Parameters
VERSION="7u80"
DOCKEROPS=""
while getopts "hesxiv:o:" optname; do
case "$optname" in
"h")
usage
;;
"v")
VERSION="$OPTARG"
;;
"o")
DOCKEROPS="$OPTARG"
;;
"?")
usage;
exit 1;
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
;;
esac
done
# prepare image
PRO_PATH=$PWD
cd $PRO_PATH/base
make all
cd ..
# Oracle JDK Image Name
IMAGE_NAME="goodrain-apps/oraclejdk:$VERSION"
# Go into version folder
cd $VERSION
echo "=========================="
echo "DOCKER info:"
docker info
echo "=========================="
# Proxy settings
PROXY_SETTINGS=""
if [ "${http_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg http_proxy=${http_proxy}"
fi
if [ "${https_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg https_proxy=${https_proxy}"
fi
if [ "${ftp_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg ftp_proxy=${ftp_proxy}"
fi
if [ "${no_proxy}" != "" ]; then
PROXY_SETTINGS="$PROXY_SETTINGS --build-arg no_proxy=${no_proxy}"
fi
if [ "$PROXY_SETTINGS" != "" ]; then
echo "Proxy settings were found and will be used during the build."
fi
# ################## #
# BUILDING THE IMAGE #
# ################## #
echo "Building image '$IMAGE_NAME' ..."
# BUILD THE IMAGE (replace all environment variables)
BUILD_START=$(date '+%s')
docker build --force-rm=true --no-cache=true $DOCKEROPS $PROXY_SETTINGS -t $IMAGE_NAME -f Dockerfile . || {
echo ""
echo "ERROR: Docker Image was NOT successfully created."
echo "ERROR: Check the output and correct any reported problems with the docker build operation."
exit 1
}
echo ""