-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·275 lines (222 loc) · 9.89 KB
/
build.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
#---------------------------------------------------------------------
#
# Author: Dirk Nachbar, Trivadis AG, Bern Switzerland
#
# Purpose: Main build script for creating WebLogic Server Image
# and WebLogic Server Domain Creation
#
# Parameters: -i <ConfigFile>
# e.g. ./build.sh -i build.ini
#
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
Usage()
#
# PURPOSE: Displays the Usage of the script
#---------------------------------------------------------------------
{
cat << EOF
Usage: build_wls_image.sh -i <ConfigFile>
Builds a Docker Image for WebLogic.
Parameters:
-i: creates WebLogic Server image according to provided values
in the configfile
LICENSE GPL 2.0
EOF
exit 0
}
#---------------------------------------------------------------------
CheckParams()
#
# PURPOSE: Checks the input Parmeter -i
#---------------------------------------------------------------------
{
if [ "${ConfigFile}" = "" ] ; then
echo "ERR: Missing parameter(s), the flags -i must be used."
Usage
fi
}
#---------------------------------------------------------------------
ReadParams()
#
# PURPOSE: Reads the Parmeters of the Configfile.
#---------------------------------------------------------------------
{
# Start Message of reading parameters from provided configuration file
echo "Starting to read parameters from configuration file ${ConfigFile}"
TheVersion="$(cat ${ConfigFile} | grep -i "^Version=" | head -n 1 | cut -d= -f2-)"
TheImageName="$(cat ${ConfigFile} | grep -i "^ImageName=" | head -n 1 | cut -d= -f2-)"
TheJdkRpm="$(cat ${ConfigFile} | grep -i "^JdkRpm=" | head -n 1 | cut -d= -f2-)"
TheWlsSource="$(cat ${ConfigFile} | grep -i "^WlsSource=" | head -n 1 | cut -d= -f2-)"
TheOracleLinux="$(cat ${ConfigFile} | grep -i "^OracleLinux=" | head -n 1 | cut -d= -f2-)"
TheAdminPassword="$(cat ${ConfigFile} | grep -i "^AdminPassword=" | head -n 1 | cut -d= -f2-)"
TheAdminPort="$(cat ${ConfigFile} | grep -i "^AdminPort=" | head -n 1 | cut -d= -f2-)"
TheNodeManagerPort="$(cat ${ConfigFile} | grep -i "^NodeManagerPort=" | head -n 1 | cut -d= -f2-)"
TheManagedServerPort="$(cat ${ConfigFile} | grep -i "^ManagedServerPort=" | head -n 1 | cut -d= -f2-)"
TheWlsImageName="$(cat ${ConfigFile} | grep -i "^WlsImageName=" | head -n 1 | cut -d= -f2-)"
TheWlsContainerName="$(cat ${ConfigFile} | grep -i "^WlsContainerName=" | head -n 1 | cut -d= -f2-)"
if [ "${TheVersion}" = "" ] ; then
echo "ERR: Missing value Version in the provided Config File."
exit 0
fi
if [ "${TheImageName}" = "" ] ; then
echo "ERR: Missing value ImageName in the provided Config File."
exit 0
fi
if [ "${TheJdkRpm}" = "" ] ; then
echo "ERR: Missing value JdkRpm in the provided Config File."
exit 0
fi
if [ "${TheWlsSource}" = "" ] ; then
echo "ERR: Missing value WlsSource in the provided Config File."
exit 0
fi
if [ "${TheOracleLinux}" = "" ] ; then
echo "ERR: Missing value OracleLinux in the provided Config File."
exit 0
fi
if [ "${TheAdminPassword}" = "" ] ; then
echo "ERR: Missing value AdminPassword in the provided Config File."
exit 0
fi
if [ "${TheAdminPort}" = "" ] ; then
echo "ERR: Missing value AdminPort in the provided Config File."
exit 0
fi
if [ "${TheNodeManagerPort}" = "" ] ; then
echo "ERR: Missing value NodeManagerPort in the provided Config File."
exit 0
fi
if [ "${TheManagedServerPort}" = "" ] ; then
echo "ERR: Missing value ManagedServerPort in the provided Config File."
exit 0
fi
if [ "${TheWlsImageName}" = "" ] ; then
echo "ERR: Missing value WlsImageName in the provided Config File."
exit 0
fi
if [ "${TheWlsContainerName}" = "" ] ; then
echo "ERR: Missing value WlsContainerName in the provided Config File."
exit 0
fi
echo "Done with reading parameters from configuration file ${ConfigFile}"
}
#---------------------------------------------------------------------
CreateBuildFiles()
#
# PURPOSE: Creates the required files for the WLS Image build
#---------------------------------------------------------------------
{
#
echo "Starting to create subdirectory ${TheImageName} and populate all required files"
# Create required files for Oracle WebLogic Server image installation
mkdir ${TheImageName}
cp Dockerfile.template ${TheImageName}/Dockerfile
cp ${TheJdkRpm} ${TheImageName}/${TheJdkRpm}
cp ${TheWlsSource} ${TheImageName}/${TheWlsSource}
cp oraInst.loc ${TheImageName}/
cp install.rsp ${TheImageName}/
sed -i "s/<TheJdkRpm>/${TheJdkRpm}/g" ${TheImageName}/Dockerfile
sed -i "s/<TheWlsSource>/${TheWlsSource}/g" ${TheImageName}/Dockerfile
sed -i "s/<TheOracleLinux>/${TheOracleLinux}/g" ${TheImageName}/Dockerfile
# Create required files for Oracle WebLogic Domain Creation
mkdir ${TheImageName}/create_domain
cp script_templates/Dockerfile.template ${TheImageName}/create_domain/Dockerfile
cp script_templates/create-wls-domain.template ${TheImageName}/create_domain/create-wls-domain.py
cp script_templates/commEnv.sh ${TheImageName}/create_domain/commEnv.sh
cp script_templates/jaxrs2-template.jar ${TheImageName}/create_domain/jaxrs2-template.jar
cp script_templates/add-machine.template ${TheImageName}/create_domain/add-machine.py
cp script_templates/createMachine.sh ${TheImageName}/create_domain/createMachine.sh
sed -i "s/<BaseImage>/${TheImageName}:${TheVersion}/g" ${TheImageName}/create_domain/Dockerfile
sed -i "s/<AdminPassword>/${TheAdminPassword}/g" ${TheImageName}/create_domain/Dockerfile
sed -i "s/<AdminPort>/${TheAdminPort}/g" ${TheImageName}/create_domain/Dockerfile
sed -i "s/<NodeManagerPort>/${TheNodeManagerPort}/g" ${TheImageName}/create_domain/Dockerfile
sed -i "s/<ManagedServerPort>/${TheManagedServerPort}/g" ${TheImageName}/create_domain/Dockerfile
sed -i "s/<AdminPort>/${TheAdminPort}/g" ${TheImageName}/create_domain/create-wls-domain.py
sed -i "s/<AdminPassword>/${TheAdminPassword}/g" ${TheImageName}/create_domain/create-wls-domain.py
sed -i "s/<NodeManagerPort>/${TheNodeManagerPort}/g" ${TheImageName}/create_domain/create-wls-domain.py
sed -i "s/<AdminPassword>/${TheAdminPort}/g" ${TheImageName}/create_domain/add-machine.py
sed -i "s/<WlsContainerName>/${TheWlsContainerName}/g" ${TheImageName}/create_domain/add-machine.py
sed -i "s/<AdminPort>/${TheAdminPort}/g" ${TheImageName}/create_domain/add-machine.py
sed -i "s/<NodeManagerPort>/${TheNodeManagerPort}/g" ${TheImageName}/create_domain/add-machine.py
echo "Done with creating subdirectory ${TheImageName} and populating all required files"
}
#---------------------------------------------------------------------
# MAIN
#---------------------------------------------------------------------
ConfigFile=""
# All required ConfigParameters are initially set to empty
TheVersion=""
TheImageName=""
TheJdkRpm=""
TheWlsSource=""
TheOracleLinux=""
TheAdminPassword=""
TheAdminPort=""
TheNodeManagerPort=""
TheManagedServerPort=""
TheWlsImageName=""
TheWlsContainerName=""
while getopts i: CurOpt; do
case ${CurOpt} in
i) ConfigFile="${OPTARG}" ;;
?) Usage
exit 1 ;;
esac
done
shift $((${OPTIND}-1))
if [ $# -ne 0 ]; then
Usage
fi
echo "Starting with preparation tasks ..."
# Check Input Params
CheckParams
# Read the Params from the Config File
ReadParams
# Create the required files for Image build and WLS Domain Creation
CreateBuildFiles
echo "Done with preparation tasks"
cd ${TheImageName}
# Build the Image
echo "Starting with Docker Image WebLogic Server build process ..."
echo "Docker Image build command"
echo "Following Command will be executed:"
echo " docker build --force-rm=true --no-cache=true --rm=true -t ${TheImageName}:${TheVersion} ."
docker build --force-rm=true --no-cache=true --rm=true -t ${TheImageName}:${TheVersion} .
echo "Done with Docker Image WebLogic Server build process"
cd create_domain
# Create the WLS Domain
echo "Starting with Docker Image WebLogic Domain build process ..."
echo "WLS Domain Creation"
echo "Following Command will be executed:"
echo " docker build -t ${TheWlsImageName}:${TheVersion} ."
docker build -t ${TheWlsImageName}:${TheVersion} .
echo "Done with Docker Image WebLogic Domain build process"
# Startup the Admin Server
echo "Startup the newly created Admin Server on port ${TheAdminPort}"
echo "Following Command will be executed:"
echo " docker run -d -p ${TheAdminPort}:${TheAdminPort} -h ${TheWlsContainerName} --name=${TheWlsContainerName} ${TheWlsImageName}:${TheVersion} startWebLogic.sh"
docker run -d -p ${TheAdminPort}:${TheAdminPort} -h ${TheWlsContainerName} --name=${TheWlsContainerName} ${TheWlsImageName}:${TheVersion} startWebLogic.sh
# set a sleep of 60 seconds in order to allow the Admin Server to be up and running
echo "Wait for 60 seconds in order to allow the Admin Server to be up and running"
echo "..."
sleep 60
# retrieve the IP Address for above created WLS Admin Server
TheContainerIP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${TheWlsContainerName})
echo "Admin server can be reached either via"
echo "Docker internal IP: http://${TheContainerIP}:${TheAdminPort}/console"
echo "Docker server IP: http://<Dockerhost>:${TheAdminPort}/console"
# Node Manager creation and startup
echo "Starting with Node Manager Creation"
echo "Following Command will be executed:"
echo " docker exec -it ${TheWlsContainerName} createMachine.sh"
docker exec -it ${TheWlsContainerName} createMachine.sh
echo "Done with Node Manager Creation"
echo "Done with Weblogic Server Installation and configuration on Docker"
echo "****************************************************************************"
echo "Following Docker Images are available:"
docker images
echo "Admin Server URL: http://${TheContainerIP}:${TheAdminPort}/console"
echo "NodeManager Port: ${TheNodeManagerPort}"