forked from oracle/docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildDockerImage.sh
executable file
·161 lines (130 loc) · 3.87 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#
# Since: February, 2017
# Author: [email protected]
# Description: Build script for building Oracle Rest Data Services Docker images.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
#
usage() {
cat << EOF
Usage: buildDockerImage.sh [-i] [-o] [Docker build option]
Builds a Docker Image for Oracle Rest Data Services
Parameters:
-i: ignores the MD5 checksums
-o: passes on Docker build option
LICENSE UPL 1.0
Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.
EOF
exit 0
}
# Validate packages
checksumPackages() {
echo "Checking if required packages are present and valid..."
md5sum -c Checksum.$VERSION
if [ "$?" -ne 0 ]; then
echo "MD5 for required packages to build this image did not match!"
echo "Make sure to download missing files in folder '$VERSION'."
exit $?
fi
}
# Parameters
VERSION=""
SKIPMD5=0
DOCKEROPS=""
while getopts "hio:" optname; do
case "$optname" in
"h")
usage
;;
"i")
SKIPMD5=1
;;
"o")
DOCKEROPS="$OPTARG"
;;
"?")
usage;
exit 1;
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
;;
esac
done
# Determine latest version
# Do this after the options so that users can still do a "-h"
if [ `ls -al ords*zip 2>/dev/null | wc -l` -gt 1 ]; then
echo "ERROR: Found multiple versions of ORDS zip files.";
echo "ERROR: Please only put one ORDS zip file into this directory!";
exit 1;
else
# #644: using awk as below does not work in macOS bash as it's really gawk (3 params) - see ticket for more info
# VERSION=$(ls ords*zip 2>/dev/null | awk 'match ($0, /(ords\.)(.{1,2}\..{1,2}\..{1,2})\.(.+.zip)/, result) { print result[2] }')
ORDS_FILENAME=$(ls ords*zip 2>/dev/null)
ORDS_FILENAME_REGEXP="(ords(\.|-))(.{1,2}\..{1,2}\..{1,2})(\..*)(zip)"
if [[ $ORDS_FILENAME =~ $ORDS_FILENAME_REGEXP ]]; then
VERSION="${BASH_REMATCH[3]}"
else
VERSION=""
fi;
fi;
if [ -z "$VERSION" ]; then
echo "ERROR: No install file is in this directory!"
echo "ERROR: Please copy the install file into this directory or refer to the ReadMe!"
exit 1;
fi;
# Oracle Database Image Name
IMAGE_NAME="oracle/restdataservices:$VERSION"
if [ ! "$SKIPMD5" -eq 1 ]; then
checksumPackages
else
echo "Ignored MD5 checksum."
fi
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 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 "There was an error building the image."
exit 1
}
BUILD_END=$(date '+%s')
BUILD_ELAPSED=`expr $BUILD_END - $BUILD_START`
echo ""
if [ $? -eq 0 ]; then
cat << EOF
Oracle Rest Data Services version $VERSION is ready to be extended:
--> $IMAGE_NAME
Build completed in $BUILD_ELAPSED seconds.
EOF
else
echo "Oracle Rest Data Services Docker Image was NOT successfully created. Check the output and correct any reported problems with the docker build operation."
fi