forked from PhilippSalvisberg/docker-odb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildDockerImage.sh
executable file
·146 lines (118 loc) · 3.41 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
usage() {
cat << EOF
Usage: buildDockerImage.sh [-o] [-d] [-t target] [Docker build option]
Builds a Docker Image for Oracle Database.
Parameters:
-d: debug mode, do not remove dangling images (intermitten images with tag <none>)
-t: target a specific intermitten images (base, builder, database)
-o: passes on Docker build option
-h: usage
EOF
}
# Check Docker version
checkDockerVersion() {
# Get Docker Server version
DOCKER_VERSION=$(docker version --format '{{.Server.Version | printf "%.5s" }}')
# Remove dot in Docker version
DOCKER_VERSION=${DOCKER_VERSION//./}
if [ "$DOCKER_VERSION" -lt "${MIN_DOCKER_VERSION//./}" ]; then
echo "Docker version is below the minimum required version $MIN_DOCKER_VERSION"
echo "Please upgrade your Docker installation to proceed."
exit 1;
fi;
}
##############
#### MAIN ####
##############
# Parameters
DEBUG=0
STANDARD=1
VERSION="11.2.0.4"
DOCKEROPS="--force-rm=true --no-cache=true"
MIN_DOCKER_VERSION="17.09"
DOCKERFILE="Dockerfile"
EDITION="se"
TARGET=""
while getopts "h:dto:" optname; do
case "$optname" in
"h")
usage
exit 0;
;;
"t")
TARGET=${TARGET}
;;
"d")
DEBUG=1
DOCKEROPS=""
;;
"o")
DOCKEROPS="${DOCKEROPS} ${OPTARG}"
;;
"?")
usage;
exit 1;
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
;;
esac
done
checkDockerVersion
#Image Name
IMAGE_NAME="juxta/oracle:$VERSION-$EDITION"
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 \
$DOCKEROPS $PROXY_SETTINGS $TARGET --build-arg DB_EDITION=$EDITION \
-t $IMAGE_NAME -f $DOCKERFILE . || {
echo ""
echo "ERROR: Oracle Database Docker Image was NOT successfully created."
echo "ERROR: Check the output and correct any reported problems with the docker build operation."
exit 1
}
if [ ! "$DEBUG" -eq 1 ]; then
echo "Keep dangling images (intermitten images with tag <none>)."
else
echo "Remove dangling images (intermitten images with tag <none>)"
yes | docker image prune > /dev/null
fi
echo "Push image to regisry (jxt-dev-pgsql.juxta.fr:5000/oracle:$VERSION-$EDITION)"
docker tag $IMAGE_NAME jxt-dev-pgsql.juxta.fr:5000/oracle:$VERSION-$EDITION
docker push jxt-dev-pgsql.juxta.fr:5000/oracle:$VERSION-$EDITION
BUILD_END=$(date '+%s')
BUILD_ELAPSED=`expr $BUILD_END - $BUILD_START`
echo ""
echo ""
cat << EOF
Oracle Database Docker Image for '$EDITION' version $VERSION is ready to be extended:
--> $IMAGE_NAME
Build completed in $BUILD_ELAPSED seconds.
EOF