/
buildDockerImage.sh
executable file
·123 lines (103 loc) · 2.79 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
#!/bin/bash
#
# Since: October, 2014
# Author: bruno.borges@oracle.com
# Description: script to build a Docker image for WebLogic
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
#
usage() {
cat << EOF
Usage: buildDockerImage.sh -v [version] [-d | -g] [-s]
Builds a Docker Image for Oracle WebLogic.
Parameters:
-v: version to build. Required.
Choose one of: $(for i in $(ls -d */); do echo -n "${i%%/} "; done)
-d: creates image based on 'developer' distribution
-g: creates image based on 'generic' distribution
-s: skips the MD5 check of packages
* use either -d or -g, obligatory.
LICENSE CDDL 1.0 + GPL 2.0
Copyright (c) 2014-2015 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.$DISTRIBUTION
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. See *.download files for more information"
exit $?
fi
}
if [ "$#" -eq 0 ]; then usage; fi
# Parameters
DEVELOPER=0
GENERIC=0
VERSION="12.1.3"
SKIPMD5=0
while getopts "hsdgv:" optname; do
case "$optname" in
"h")
usage
;;
"s")
SKIPMD5=1
;;
"d")
DEVELOPER=1
;;
"g")
GENERIC=1
;;
"v")
VERSION="$OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
;;
esac
done
# WebLogic Image Name
DEFAULT_IMAGE_NAME="oracle/weblogic:$VERSION"
DEFAULT_DEV_IMAGE_NAME="$DEFAULT_IMAGE_NAME-dev"
# Developer or Generic?
if [ "$DEVELOPER" -eq "$GENERIC" ]; then
usage
elif [ $DEVELOPER -eq 1 ]; then
DISTRIBUTION="developer"
IMAGE_NAME="$DEFAULT_DEV_IMAGE_NAME"
else
DISTRIBUTION="generic"
IMAGE_NAME="$DEFAULT_IMAGE_NAME"
fi
# Go into version folder
cd $VERSION
if [ ! "$SKIPMD5" -eq 1 ]; then
checksumPackages
else
echo "Skipped MD5 checksum."
fi
echo "====================="
# ################## #
# BUILDING THE IMAGE #
# ################## #
echo "Building image '$IMAGE_NAME' based on '$DISTRIBUTION' distribution..."
# BUILD THE IMAGE (replace all environment variables)
rm -f Dockerfile && ln -s Dockerfile.$DISTRIBUTION Dockerfile
docker build --force-rm=true --no-cache=true -t $IMAGE_NAME . || {
echo "There was an error building the image."
exit 1
}
rm -f Dockerfile
echo ""
if [ $? -eq 0 ]; then
echo "WebLogic Docker Image for '$DISTRIBUTION' $VERSION is ready to be extended: $IMAGE_NAME"
else
echo "WebLogic Docker Image was NOT successfully created. Check the output and correct any reported problems with the docker build operation."
fi