forked from oracle/weblogic-kubernetes-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-domain.sh
executable file
·329 lines (274 loc) · 11.6 KB
/
create-domain.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/env bash
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
# Description
# This sample script creates a WebLogic domain home in docker image, and generates the domain resource
# yaml file, which can be used to restart the Kubernetes artifacts of the corresponding domain.
#
# The domain creation inputs can be customized by editing create-domain-inputs.yaml
#
# The following pre-requisites must be handled prior to running this script:
# * The WDT sample requires that JAVA_HOME is set to a java JDK version 1.8 or greater
# * The kubernetes namespace must already be created
# * The kubernetes secrets 'username' and 'password' of the admin account have been created in the namespace
#
# Initialize
script="${BASH_SOURCE[0]}"
scriptDir="$( cd "$( dirname "${script}" )" && pwd )"
source ${scriptDir}/../../common/utility.sh
source ${scriptDir}/../../common/validate.sh
function usage {
echo usage: ${script} -o dir -i file -u username -p password [-k] [-e] [-h]
echo " -i Parameter inputs file, must be specified."
echo " -o Output directory for the generated properties and YAML files, must be specified."
echo " -u Username used in building the Docker image for WebLogic domain in image."
echo " -p Password used in building the Docker image for WebLogic domain in image."
echo " -e Also create the resources in the generated YAML files, optional."
echo " -k Keep what has been previously from cloned https://github.com/oracle/docker-images.git, optional. "
echo " If not specified, this script will always remove existing project directory and clone again."
echo " -h Help"
exit $1
}
#
# Parse the command line options
#
executeIt=false
cloneIt=true
while getopts "evhki:o:u:p:" opt; do
case $opt in
i) valuesInputFile="${OPTARG}"
;;
o) outputDir="${OPTARG}"
;;
e) executeIt=true
;;
u) username="${OPTARG}"
;;
p) password="${OPTARG}"
;;
k) cloneIt=false;
;;
h) usage 0
;;
*) usage 1
;;
esac
done
if [ -z ${valuesInputFile} ]; then
echo "${script}: -i must be specified."
missingRequiredOption="true"
fi
if [ -z ${username} ]; then
echo "${script}: -u must be specified."
missingRequiredOption="true"
fi
if [ -z ${password} ]; then
echo "${script}: -p must be specified."
missingRequiredOption="true"
fi
if [ -z ${outputDir} ]; then
echo "${script}: -o must be specified."
missingRequiredOption="true"
fi
if [ "${missingRequiredOption}" == "true" ]; then
usage 1
fi
#
# Function to initialize and validate the output directory
# for the generated properties and yaml files for this domain.
#
function initOutputDir {
domainOutputDir="${outputDir}/weblogic-domains/${domainUID}"
# Create a directory for this domain's output files
mkdir -p ${domainOutputDir}
removeFileIfExists ${domainOutputDir}/${valuesInputFile}
removeFileIfExists ${domainOutputDir}/create-domain-inputs.yaml
removeFileIfExists ${domainOutputDir}/domain.properties
removeFileIfExists ${domainOutputDir}/domain.yaml
}
# try to execute docker to see whether docker is available
function validateDockerAvailable {
if ! [ -x "$(command -v docker)" ]; then
validationError "docker is not installed"
fi
}
#
# Function to setup the environment to create domain
#
function initialize {
# Validate the required files exist
validateErrors=false
validateDockerAvailable
validateKubectlAvailable
if [ -z "${valuesInputFile}" ]; then
validationError "You must use the -i option to specify the name of the inputs parameter file (a modified copy of kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain-inputs.yaml)."
else
if [ ! -f ${valuesInputFile} ]; then
validationError "Unable to locate the input parameters file ${valuesInputFile}"
fi
fi
if [ -z "${outputDir}" ]; then
validationError "You must use the -o option to specify the name of an existing directory to store the generated properties and yaml files in."
fi
domainPropertiesInput="${scriptDir}/properties-template.properties"
if [ ! -f ${domainPropertiesInput} ]; then
validationError "The template file ${domainPropertiesInput} for creating a WebLogic domain was not found"
fi
dcrInput="${scriptDir}/domain-template.yaml"
if [ ! -f ${dcrInput} ]; then
validationError "The template file ${dcrInput} for creating the domain resource was not found"
fi
failIfValidationErrors
validateCommonInputs
initOutputDir
if [ "${cloneIt}" = true ]; then
getDockerSample
fi
}
#
# Function to get the dependency docker sample
#
function getDockerSample {
rm -rf ${scriptDir}/docker-images
git clone https://github.com/oracle/docker-images.git ${scriptDir}/docker-images
}
#
# Function to generate the properties and yaml files for creating a domain
#
function createFiles {
# Make sure the output directory has a copy of the inputs file.
# The user can either pre-create the output directory, put the inputs
# file there, and create the domain from it, or the user can put the
# inputs file some place else and let this script create the output directory
# (if needed) and copy the inputs file there.
copyInputsFileToOutputDirectory ${valuesInputFile} "${domainOutputDir}/create-domain-inputs.yaml"
domainPropertiesOutput="${domainOutputDir}/domain.properties"
dcrOutput="${domainOutputDir}/domain.yaml"
enabledPrefix="" # uncomment the feature
disabledPrefix="# " # comment out the feature
if [ -z "${domainHomeImageBase}" ]; then
fail "Please specify domainHomeImageBase in your input YAML"
fi
domainName=${domainUID}
# Generate the properties file that will be used when creating the weblogic domain
echo Generating ${domainPropertiesOutput}
cp ${domainPropertiesInput} ${domainPropertiesOutput}
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${domainPropertiesOutput}
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${domainPropertiesOutput}
sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${domainPropertiesOutput}
sed -i -e "s:%MANAGED_SERVER_PORT%:${managedServerPort}:g" ${domainPropertiesOutput}
sed -i -e "s:%MANAGED_SERVER_NAME_BASE%:${managedServerNameBase}:g" ${domainPropertiesOutput}
sed -i -e "s:%CONFIGURED_MANAGED_SERVER_COUNT%:${configuredManagedServerCount}:g" ${domainPropertiesOutput}
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${domainPropertiesOutput}
sed -i -e "s:%PRODUCTION_MODE_ENABLED%:${productionModeEnabled}:g" ${domainPropertiesOutput}
sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${domainPropertiesOutput}
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${domainPropertiesOutput}
sed -i -e "s:%T3_CHANNEL_PORT%:${t3ChannelPort}:g" ${domainPropertiesOutput}
sed -i -e "s:%T3_PUBLIC_ADDRESS%:${t3PublicAddress}:g" ${domainPropertiesOutput}
# Generate the yaml to create the domain resource
echo Generating ${dcrOutput}
if [ "${exposeAdminT3Channel}" = true ]; then
exposeAdminT3ChannelPrefix="${enabledPrefix}"
else
exposeAdminT3ChannelPrefix="${disabledPrefix}"
fi
if [ "${exposeAdminNodePort}" = true ]; then
exposeAdminNodePortPrefix="${enabledPrefix}"
else
exposeAdminNodePortPrefix="${disabledPrefix}"
fi
domainHome="/u01/oracle/user_projects/domains/${domainName}"
if [ -z "${weblogicCredentialsSecretName}" ]; then
weblogicCredentialsSecretName="${domainUID}-weblogic-credentials"
fi
cp ${dcrInput} ${dcrOutput}
sed -i -e "s:%NAMESPACE%:$namespace:g" ${dcrOutput}
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${dcrOutput}
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput}
sed -i -e "s:%DOMAIN_HOME%:${domainHome}:g" ${dcrOutput}
sed -i -e "s:%WEBLOGIC_CREDENTIALS_SECRET_NAME%:${weblogicCredentialsSecretName}:g" ${dcrOutput}
sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${dcrOutput}
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${dcrOutput}
sed -i -e "s:%INCLUDE_SERVER_OUT_IN_POD_LOG%:${includeServerOutInPodLog}:g" ${dcrOutput}
sed -i -e "s:%SERVER_START_POLICY%:${serverStartPolicy}:g" ${dcrOutput}
sed -i -e "s:%EXPOSE_ADMIN_PORT_PREFIX%:${exposeAdminNodePortPrefix}:g" ${dcrOutput}
sed -i -e "s:%ADMIN_NODE_PORT%:${adminNodePort}:g" ${dcrOutput}
sed -i -e "s:%EXPOSE_T3_CHANNEL_PREFIX%:${exposeAdminT3ChannelPrefix}:g" ${dcrOutput}
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${dcrOutput}
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${dcrOutput}
sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput}
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_POLICY%:${imagePullPolicy}:g" ${dcrOutput}
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${imagePullSecretName}:g" ${dcrOutput}
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${dcrOutput}
domainHomeImageBuildPathDefault="./docker-images/OracleWebLogic/samples/12213-domain-home-in-image-wdt"
if [ -z $domainHomeImageBuildPath ]; then
domainHomeImageBuildPath=${domainHomeImageBuildPathDefault}
fi
imageName="`basename ${domainHomeImageBuildPath} | sed 's/^[0-9]*-//'`"
# now we know which image to use, update the domain yaml file
if [ -z $image ]; then
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
else
sed -i -e "s|%IMAGE_NAME%|${image}|g" ${dcrOutput}
fi
# Remove any "...yaml-e" files left over from running sed
rm -f ${domainOutputDir}/*.yaml-e
}
#
# Function to build docker image and create WebLogic domain home
#
function createDomainHome {
dockerDir=${scriptDir}/${domainHomeImageBuildPath}
dockerPropsDir=${dockerDir}/properties
cp ${domainPropertiesOutput} ${dockerPropsDir}/docker-build
# 12213-domain-home-in-image use one properties file for the credentials
usernameFile="${dockerPropsDir}/docker-build/domain_security.properties"
passwordFile="${dockerPropsDir}/docker-build/domain_security.properties"
# 12213-domain-home-in-image-wdt uses two properties files for the credentials
if [ ! -f $usernameFile ]; then
usernameFile="${dockerPropsDir}/docker-build/adminuser.properties"
passwordFile="${dockerPropsDir}/docker-build/adminpass.properties"
fi
sed -i -e "s|myuser|${username}|g" $usernameFile
sed -i -e "s|mypassword1|${password}|g" $passwordFile
if [ ! -z $domainHomeImageBase ]; then
sed -i -e "s|\(FROM \).*|\1 ${domainHomeImageBase}|g" ${dockerDir}/Dockerfile
fi
sh ${dockerDir}/build.sh
imageNameOrigin="`basename ${domainHomeImageBuildPath}`"
# if use the default images, we tag it to a more generic name (without the release version numbers)
if [ -z $image ]; then
docker tag $imageNameOrigin:latest $imageName:latest
fi
if [ "$?" != "0" ]; then
fail "Create domain ${domainName} failed."
fi
echo ""
echo "Create domain ${domainName} successfully."
}
#
# Function to output to the console a summary of the work completed
#
function printSummary {
# Get the IP address of the kubernetes cluster (into K8S_IP)
getKubernetesClusterIP
echo ""
echo "Domain ${domainName} was created and will be started by the WebLogic Kubernetes Operator"
echo ""
if [ "${exposeAdminNodePort}" = true ]; then
echo "Administration console access is available at http:${K8S_IP}:${adminNodePort}/console"
fi
if [ "${exposeAdminT3Channel}" = true ]; then
echo "T3 access is available at t3:${K8S_IP}:${t3ChannelPort}"
fi
echo "The following files were generated:"
echo " ${domainOutputDir}/create-domain-inputs.yaml"
echo " ${domainPropertiesOutput}"
echo " ${dcrOutput}"
echo ""
echo "Completed"
}
# Perform the sequence of steps to create a domain
createDomain