Skip to content

Commit 0908504

Browse files
changes to align with newest docker-images and also corrections
1 parent 54106ca commit 0908504

File tree

1 file changed

+126
-63
lines changed
  • kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image

1 file changed

+126
-63
lines changed

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/create-domain.sh

Lines changed: 126 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ source ${scriptDir}/../../common/utility.sh
2020
source ${scriptDir}/../../common/validate.sh
2121

2222
function usage {
23-
echo usage: ${script} -o dir -i file -u username -p password [-k] [-e] [-h]
23+
echo usage: ${script} -o dir -i file -u username -p password [-e] [-h]
2424
echo " -i Parameter inputs file, must be specified."
2525
echo " -o Ouput directory for the generated properties and YAML files, must be specified."
2626
echo " -u Username used in building the Docker image for WebLogic domain in image."
2727
echo " -p Password used in building the Docker image for WebLogic domain in image."
2828
echo " -e Also create the resources in the generated YAML files, optional."
29-
echo " -k Keep what has been previously from cloned https://github.com/oracle/docker-images.git, optional. "
30-
echo " If not specified, this script will always remove existing project directory and clone again."
3129
echo " -h Help"
3230
exit $1
3331
}
@@ -36,8 +34,7 @@ function usage {
3634
# Parse the command line options
3735
#
3836
executeIt=false
39-
cloneIt=true
40-
while getopts "evhki:o:u:p:" opt; do
37+
while getopts "evhi:o:u:p:" opt; do
4138
case $opt in
4239
i) valuesInputFile="${OPTARG}"
4340
;;
@@ -49,8 +46,6 @@ while getopts "evhki:o:u:p:" opt; do
4946
;;
5047
p) password="${OPTARG}"
5148
;;
52-
k) cloneIt=false;
53-
;;
5449
h) usage 0
5550
;;
5651
*) usage 1
@@ -86,15 +81,51 @@ fi
8681
# Function to initialize and validate the output directory
8782
# for the generated properties and yaml files for this domain.
8883
#
89-
function initOutputDir {
84+
function initAndValidateOutputDir {
9085
domainOutputDir="${outputDir}/weblogic-domains/${domainUID}"
9186
# Create a directory for this domain's output files
9287
mkdir -p ${domainOutputDir}
9388

94-
removeFileIfExists ${domainOutputDir}/${valuesInputFile}
95-
removeFileIfExists ${domainOutputDir}/create-domain-inputs.yaml
96-
removeFileIfExists ${domainOutputDir}/domain.properties
97-
removeFileIfExists ${domainOutputDir}/domain.yaml
89+
validateOutputDir \
90+
${domainOutputDir} \
91+
${valuesInputFile} \
92+
create-domain-inputs.yaml \
93+
domain.properties \
94+
domain.yaml
95+
}
96+
97+
#
98+
# Function to validate the domain secret
99+
#
100+
function validateDomainSecret {
101+
# Verify the secret exists
102+
validateSecretExists ${weblogicCredentialsSecretName} ${namespace}
103+
failIfValidationErrors
104+
105+
# Verify the secret contains a username
106+
SECRET=`kubectl get secret ${weblogicCredentialsSecretName} -n ${namespace} -o jsonpath='{.data}'| grep username: | wc | awk ' { print $1; }'`
107+
if [ "${SECRET}" != "1" ]; then
108+
validationError "The domain secret ${weblogicCredentialsSecretName} in namespace ${namespace} does contain a username"
109+
fi
110+
111+
# Verify the secret contains a password
112+
SECRET=`kubectl get secret ${weblogicCredentialsSecretName} -n ${namespace} -o jsonpath='{.data}'| grep password: | wc | awk ' { print $1; }'`
113+
if [ "${SECRET}" != "1" ]; then
114+
validationError "The domain secret ${weblogicCredentialsSecretName} in namespace ${namespace} does contain a password"
115+
fi
116+
failIfValidationErrors
117+
}
118+
119+
#
120+
# Function to validate a kubernetes secret exists
121+
# $1 - the name of the secret
122+
# $2 - namespace
123+
function validateSecretExists {
124+
echo "Checking to see if the secret ${1} exists in namespace ${2}"
125+
local SECRET=`kubectl get secret ${1} -n ${2} | grep ${1} | wc | awk ' { print $1; }'`
126+
if [ "${SECRET}" != "1" ]; then
127+
validationError "The secret ${1} was not found in namespace ${2}"
128+
fi
98129
}
99130

100131
# try to execute docker to see whether docker is available
@@ -139,20 +170,54 @@ function initialize {
139170

140171
failIfValidationErrors
141172

142-
validateCommonInputs
143-
144-
initOutputDir
173+
# Parse the commonn inputs file
174+
parseCommonInputs
175+
176+
validateInputParamsSpecified \
177+
adminServerName \
178+
domainUID \
179+
clusterName \
180+
managedServerNameBase \
181+
namespace \
182+
t3PublicAddress \
183+
version
184+
185+
validateIntegerInputParamsSpecified \
186+
adminPort \
187+
configuredManagedServerCount \
188+
initialManagedServerReplicas \
189+
managedServerPort \
190+
t3ChannelPort \
191+
adminNodePort
192+
193+
validateBooleanInputParamsSpecified \
194+
productionModeEnabled \
195+
exposeAdminT3Channel \
196+
exposeAdminNodePort \
197+
includeServerOutInPodLog
198+
199+
export requiredInputsVersion="create-weblogic-sample-domain-inputs-v1"
200+
validateVersion
201+
202+
validateDomainUid
203+
validateNamespace
204+
validateAdminServerName
205+
validateManagedServerNameBase
206+
validateClusterName
207+
validateWeblogicCredentialsSecretName
208+
initAndValidateOutputDir
209+
validateServerStartPolicy
210+
validateClusterType
211+
failIfValidationErrors
145212

146-
if [ "${cloneIt}" = true ]; then
147-
getDockerSample
148-
fi
213+
getDockerSample
149214
}
150215

151216
#
152217
# Function to get the dependency docker sample
153218
#
154219
function getDockerSample {
155-
rm -rf ${scriptDir}/docker-images
220+
rm -rf {scriptDir}/docker-images
156221
git clone https://github.com/oracle/docker-images.git
157222
}
158223

@@ -239,49 +304,14 @@ function createFiles {
239304
# Function to build docker image and create WebLogic domain home
240305
#
241306
function createDomainHome {
242-
if [ -z $imagePath ]; then
243-
imagePath="12213-domain-home-in-image-wdt"
244-
fi
245-
246-
cp ${domainPropertiesOutput} ./docker-images/OracleWebLogic/samples/${imagePath}/properties/docker_build
307+
cp ${domainPropertiesOutput} ./docker-images/OracleWebLogic/samples/12213-domain-home-in-image/properties/docker_build
247308

248-
imageName="12213-domain-home-in-image:latest"
249-
# use the existence of build-archive.sh file to determine if we need to download WDT
250-
if [ -f "./docker-images/OracleWebLogic/samples/${imagePath}/build-archive.sh" ]; then
251-
imageName="12213-domain-wdt:latest"
252-
fi
309+
cd docker-images/OracleWebLogic/samples/12213-domain-home-in-image
253310

254-
# now we know which image to use, update the domain yaml file
255-
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
311+
sed -i -e "s|myuser|${username}|g" properties/docker_build/domain_security.properties
312+
sed -i -e "s|mypassword1|${password}|g" properties/docker_build/domain_security.properties
256313

257-
cd docker-images/OracleWebLogic/samples/${imagePath}
258-
259-
# 12213-domain-home-in-image use one properties file for the credentials
260-
usernameFile="properties/docker_build/domain_security.properties"
261-
passwordFile="properties/docker_build/domain_security.properties"
262-
263-
# 12213-domain-home-in-image-wdt uses two properties files for the credentials
264-
if [ ! -f $usernameFile ]; then
265-
usernameFile="properties/docker-build/adminuser.properties"
266-
passwordFile="properties/docker-build/adminpass.properties"
267-
sed -i -e "s|weblogic|${username}|g" $usernameFile
268-
sed -i -e "s|welcome1|${password}|g" $passwordFile
269-
else
270-
sed -i -e "s|myuser|${username}|g" $usernameFile
271-
sed -i -e "s|mypassword1|${password}|g" $passwordFile
272-
fi
273-
274-
# use the existence of build-archive.sh file to determine if we need to download WDT
275-
if [ -f "build-archive.sh" ]; then
276-
sh ./build-archive.sh
277-
wget https://github.com/oracle/weblogic-deploy-tooling/releases/download/weblogic-deploy-tooling-0.14/weblogic-deploy.zip
278-
fi
279-
280-
if [ ! -z $baseImage ]; then
281-
sed -i -e "s|\(FROM \).*|\1 ${baseImage}|g" Dockerfile
282-
fi
283-
284-
sh ./build.sh
314+
./build.sh
285315

286316
if [ "$?" != "0" ]; then
287317
fail "Create domain ${domainName} failed."
@@ -313,10 +343,43 @@ function printSummary {
313343
echo " ${domainOutputDir}/create-domain-inputs.yaml"
314344
echo " ${domainPropertiesOutput}"
315345
echo " ${dcrOutput}"
316-
echo ""
317-
echo "Completed"
318346
}
319347

320-
# Perform the sequence of steps to create a domain
321-
createDomain
348+
#
349+
# Function to create the domain resource
350+
#
351+
function createDomainResource {
352+
pwd
353+
kubectl apply -f ${dcrOutput}
354+
DCR_AVAIL=`kubectl get domain -n ${namespace} | grep ${domainUID} | wc | awk ' { print $1; } '`
355+
if [ "${DCR_AVAIL}" != "1" ]; then
356+
fail "The domain resource ${domainUID} was not found"
357+
fi
358+
}
359+
360+
#
361+
# Perform the following sequence of steps to create a domain
362+
#
363+
364+
# Setup the environment for running this script and perform initial validation checks
365+
initialize
366+
367+
# Generate the properties and yaml files for creating the domain
368+
createFiles
369+
370+
# Check that the domain secret exists and contains the required elements
371+
validateDomainSecret
372+
373+
# Create the WebLogic domain
374+
createDomainHome
375+
376+
if [ "${executeIt}" = true ]; then
377+
createDomainResource
378+
fi
379+
380+
# Print a summary
381+
printSummary
382+
383+
echo
384+
echo Completed
322385

0 commit comments

Comments
 (0)