Skip to content

Commit d4cf5dc

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

File tree

2 files changed

+61
-129
lines changed

2 files changed

+61
-129
lines changed

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

Lines changed: 60 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ 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 [-e] [-h]
23+
echo usage: ${script} -o dir -i file -u username -p password [-k] [-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."
2931
echo " -h Help"
3032
exit $1
3133
}
@@ -34,7 +36,8 @@ function usage {
3436
# Parse the command line options
3537
#
3638
executeIt=false
37-
while getopts "evhi:o:u:p:" opt; do
39+
cloneIt=true
40+
while getopts "evhki:o:u:p:" opt; do
3841
case $opt in
3942
i) valuesInputFile="${OPTARG}"
4043
;;
@@ -46,6 +49,8 @@ while getopts "evhi:o:u:p:" opt; do
4649
;;
4750
p) password="${OPTARG}"
4851
;;
52+
k) cloneIt=false;
53+
;;
4954
h) usage 0
5055
;;
5156
*) usage 1
@@ -81,51 +86,15 @@ fi
8186
# Function to initialize and validate the output directory
8287
# for the generated properties and yaml files for this domain.
8388
#
84-
function initAndValidateOutputDir {
89+
function initOutputDir {
8590
domainOutputDir="${outputDir}/weblogic-domains/${domainUID}"
8691
# Create a directory for this domain's output files
8792
mkdir -p ${domainOutputDir}
8893

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
94+
removeFileIfExists ${domainOutputDir}/${valuesInputFile}
95+
removeFileIfExists ${domainOutputDir}/create-domain-inputs.yaml
96+
removeFileIfExists ${domainOutputDir}/domain.properties
97+
removeFileIfExists ${domainOutputDir}/domain.yaml
12998
}
13099

131100
# try to execute docker to see whether docker is available
@@ -170,54 +139,19 @@ function initialize {
170139

171140
failIfValidationErrors
172141

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
142+
validateCommonInputs
143+
144+
initOutputDir
212145

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

216151
#
217152
# Function to get the dependency docker sample
218153
#
219154
function getDockerSample {
220-
rm -rf {scriptDir}/docker-images
221155
git clone https://github.com/oracle/docker-images.git
222156
}
223157

@@ -239,11 +173,17 @@ function createFiles {
239173
enabledPrefix="" # uncomment the feature
240174
disabledPrefix="# " # comment out the feature
241175

242-
domainName=${domainUID}
176+
domainName=${domainUID}
243177

244178
# Generate the properties file that will be used when creating the weblogic domain
245179
echo Generating ${domainPropertiesOutput}
246180

181+
if [ "${productionModeEnabled}" = true ]; then
182+
serverStartMode="prod"
183+
else
184+
serverStartMode="dev"
185+
fi
186+
247187
cp ${domainPropertiesInput} ${domainPropertiesOutput}
248188
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${domainPropertiesOutput}
249189
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${domainPropertiesOutput}
@@ -254,6 +194,7 @@ function createFiles {
254194
sed -i -e "s:%CLUSTER_NAME%:${clusterName}:g" ${domainPropertiesOutput}
255195
sed -i -e "s:%PRODUCTION_MODE_ENABLED%:${productionModeEnabled}:g" ${domainPropertiesOutput}
256196
sed -i -e "s:%CLUSTER_TYPE%:${clusterType}:g" ${domainPropertiesOutput}
197+
sed -i -e "s:%SERVER_START_MODE%:${serverStartMode}:g" ${domainPropertiesOutput}
257198
sed -i -e "s:%JAVA_OPTIONS%:${javaOptions}:g" ${domainPropertiesOutput}
258199
sed -i -e "s:%T3_CHANNEL_PORT%:${t3ChannelPort}:g" ${domainPropertiesOutput}
259200
sed -i -e "s:%T3_PUBLIC_ADDRESS%:${t3PublicAddress}:g" ${domainPropertiesOutput}
@@ -304,20 +245,43 @@ function createFiles {
304245
# Function to build docker image and create WebLogic domain home
305246
#
306247
function createDomainHome {
307-
cp ${domainPropertiesOutput} ./docker-images/OracleWebLogic/samples/12213-domain-home-in-image/properties/docker_build
308-
309-
cd docker-images/OracleWebLogic/samples/12213-domain-home-in-image
248+
if [ -z $imagePath ]; then
249+
imagePath="12213-domain-home-in-image-wdt"
250+
fi
310251

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
252+
if [ -z $imageName ]; then
253+
imageName="${imagePath}:latest"
254+
fi
255+
# now we know which image to use, update the domain yaml file
256+
sed -i -e "s|%IMAGE_NAME%|${imageName}|g" ${dcrOutput}
257+
258+
dockerDir=${scriptDir}/docker-images/OracleWebLogic/samples/${imagePath}
259+
dockerPropsDir=${dockerDir}/properties
260+
cp ${domainPropertiesOutput} ${dockerPropsDir}
261+
262+
# 12213-domain-home-in-image use one properties file for the credentials
263+
usernameFile="${dockerPropsDir}/docker_build/domain_security.properties"
264+
passwordFile="${dockerPropsDir}/docker_build/domain_security.properties"
265+
266+
# 12213-domain-home-in-image-wdt uses two properties files for the credentials
267+
if [ ! -f $usernameFile ]; then
268+
usernameFile="${dockerPropsDir}/docker-build/adminuser.properties"
269+
passwordFile="${dockerPropsDir}/docker-build/adminpass.properties"
270+
fi
271+
272+
sed -i -e "s|myuser|${username}|g" $usernameFile
273+
sed -i -e "s|mypassword1|${password}|g" $passwordFile
274+
275+
if [ ! -z $baseImage ]; then
276+
sed -i -e "s|\(FROM \).*|\1 ${baseImage}|g" Dockerfile
277+
fi
313278

314-
./build.sh
279+
sh ${dockerDir}/build.sh
315280

316281
if [ "$?" != "0" ]; then
317282
fail "Create domain ${domainName} failed."
318283
fi
319284

320-
cd -
321285
echo ""
322286
echo "Create domain ${domainName} successfully."
323287
}
@@ -343,43 +307,10 @@ function printSummary {
343307
echo " ${domainOutputDir}/create-domain-inputs.yaml"
344308
echo " ${domainPropertiesOutput}"
345309
echo " ${dcrOutput}"
310+
echo ""
311+
echo "Completed"
346312
}
347313

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
314+
# Perform the sequence of steps to create a domain
315+
createDomain
385316

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ DERBY_FLAG=true
1313
PRODUCTION_MODE_ENABLED=%PRODUCTION_MODE_ENABLED%
1414
CLUSTER_TYPE=%CLUSTER_TYPE%
1515
JAVA_OPTIONS=%JAVA_OPTIONS%
16+
SERVER_START_MODE=%SERVER_START_MODE%
1617
T3_CHANNEL_PORT=%T3_CHANNEL_PORT%
1718
T3_PUBLIC_ADDRESS=%T3_PUBLIC_ADDRESS%
1819
#Derby Data Source parameters

0 commit comments

Comments
 (0)