|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 4 | +# |
| 5 | +# Description |
| 6 | +# This sample script creates a WebLogic domain home in docker image, and generates the domain resource |
| 7 | +# yaml file, which can be used to restart the Kubernetes artifacts of the corresponding domain. |
| 8 | +# |
| 9 | +# The domain creation inputs can be customized by editing create-domain-inputs.yaml |
| 10 | +# |
| 11 | +# The following pre-requisites must be handled prior to running this script: |
| 12 | +# * The WDT sample requires that JAVA_HOME is set to a java JDK version 1.8 or greater |
| 13 | +# * The kubernetes namespace must already be created |
| 14 | +# * The kubernetes secrets 'username' and 'password' of the admin account have been created in the namespace |
| 15 | +# * The host directory that will be used as the persistent volume must already exist |
| 16 | +# and have the appropriate file permissions set. |
| 17 | +# * If logHomeOnPV is enabled, the kubernetes persisitent volume must already be created |
| 18 | +# * If logHomeOnPV is enabled, the kubernetes persisitent volume claim must already be created |
| 19 | +# |
| 20 | + |
| 21 | +# Initialize |
| 22 | +script="${BASH_SOURCE[0]}" |
| 23 | +scriptDir="$( cd "$( dirname "${script}" )" && pwd )" |
| 24 | +source ${scriptDir}/../../common/utility.sh |
| 25 | +source ${scriptDir}/../../common/validate.sh |
| 26 | + |
| 27 | +function usage { |
| 28 | + echo usage: ${script} -o dir -i file -u username -p password [-k] [-e] [-v] [-h] |
| 29 | + echo " -i Parameter inputs file, must be specified." |
| 30 | + echo " -o Output directory for the generated properties and YAML files, must be specified." |
| 31 | + echo " -u Username used in building the Docker image for WebLogic domain in image." |
| 32 | + echo " -p Password used in building the Docker image for WebLogic domain in image." |
| 33 | + echo " -e Also create the resources in the generated YAML files, optional." |
| 34 | + echo " -v Validate the existence of persistentVolumeClaim, optional." |
| 35 | + echo " -k Keep what has been previously from cloned https://github.com/oracle/docker-images.git, optional. " |
| 36 | + echo " If not specified, this script will always remove existing project directory and clone again." |
| 37 | + echo " -h Help" |
| 38 | + exit $1 |
| 39 | +} |
| 40 | + |
| 41 | +# |
| 42 | +# Parse the command line options |
| 43 | +# |
| 44 | +doValidation=false |
| 45 | +executeIt=false |
| 46 | +cloneIt=true |
| 47 | +while getopts "evhki:o:u:p:" opt; do |
| 48 | + case $opt in |
| 49 | + i) valuesInputFile="${OPTARG}" |
| 50 | + ;; |
| 51 | + o) outputDir="${OPTARG}" |
| 52 | + ;; |
| 53 | + v) doValidation=true |
| 54 | + ;; |
| 55 | + e) executeIt=true |
| 56 | + ;; |
| 57 | + u) username="${OPTARG}" |
| 58 | + ;; |
| 59 | + p) password="${OPTARG}" |
| 60 | + ;; |
| 61 | + k) cloneIt=false; |
| 62 | + ;; |
| 63 | + h) usage 0 |
| 64 | + ;; |
| 65 | + *) usage 1 |
| 66 | + ;; |
| 67 | + esac |
| 68 | +done |
| 69 | + |
| 70 | +if [ -z ${valuesInputFile} ]; then |
| 71 | + echo "${script}: -i must be specified." |
| 72 | + missingRequiredOption="true" |
| 73 | +fi |
| 74 | + |
| 75 | +if [ -z ${username} ]; then |
| 76 | + echo "${script}: -u must be specified." |
| 77 | + missingRequiredOption="true" |
| 78 | +fi |
| 79 | + |
| 80 | +if [ -z ${password} ]; then |
| 81 | + echo "${script}: -p must be specified." |
| 82 | + missingRequiredOption="true" |
| 83 | +fi |
| 84 | + |
| 85 | +if [ -z ${outputDir} ]; then |
| 86 | + echo "${script}: -o must be specified." |
| 87 | + missingRequiredOption="true" |
| 88 | +fi |
| 89 | + |
| 90 | +if [ "${missingRequiredOption}" == "true" ]; then |
| 91 | + usage 1 |
| 92 | +fi |
| 93 | + |
| 94 | +# |
| 95 | +# Function to initialize and validate the output directory |
| 96 | +# for the generated properties and yaml files for this domain. |
| 97 | +# |
| 98 | +function initOutputDir { |
| 99 | + domainOutputDir="${outputDir}/weblogic-domains/${domainUID}" |
| 100 | + # Create a directory for this domain's output files |
| 101 | + mkdir -p ${domainOutputDir} |
| 102 | + |
| 103 | + removeFileIfExists ${domainOutputDir}/${valuesInputFile} |
| 104 | + removeFileIfExists ${domainOutputDir}/create-domain-inputs.yaml |
| 105 | + removeFileIfExists ${domainOutputDir}/domain.properties |
| 106 | + removeFileIfExists ${domainOutputDir}/domain.yaml |
| 107 | +} |
| 108 | + |
| 109 | +# try to execute docker to see whether docker is available |
| 110 | +function validateDockerAvailable { |
| 111 | + if ! [ -x "$(command -v docker)" ]; then |
| 112 | + validationError "docker is not installed" |
| 113 | + fi |
| 114 | +} |
| 115 | + |
| 116 | +# |
| 117 | +# Function to setup the environment to create domain |
| 118 | +# |
| 119 | +function initialize { |
| 120 | + |
| 121 | + # Validate the required files exist |
| 122 | + validateErrors=false |
| 123 | + |
| 124 | + validateDockerAvailable |
| 125 | + validateKubectlAvailable |
| 126 | + |
| 127 | + if [ -z "${valuesInputFile}" ]; then |
| 128 | + validationError "You must use the -i option to specify the name of the inputs parameter file (a modified copy of kubernetes/samples/scripts/create-fmw-infrastructure-domain/domain-home-in-image/create-domain-inputs.yaml)." |
| 129 | + else |
| 130 | + if [ ! -f ${valuesInputFile} ]; then |
| 131 | + validationError "Unable to locate the input parameters file ${valuesInputFile}" |
| 132 | + fi |
| 133 | + fi |
| 134 | + |
| 135 | + if [ -z "${outputDir}" ]; then |
| 136 | + validationError "You must use the -o option to specify the name of an existing directory to store the generated properties and yaml files in." |
| 137 | + fi |
| 138 | + |
| 139 | + domainPropertiesInput="${scriptDir}/properties-template.properties" |
| 140 | + if [ ! -f ${domainPropertiesInput} ]; then |
| 141 | + validationError "The template file ${domainPropertiesInput} for creating a WebLogic domain was not found" |
| 142 | + fi |
| 143 | + |
| 144 | + dcrInput="${scriptDir}/../../common/domain-template.yaml" |
| 145 | + if [ ! -f ${dcrInput} ]; then |
| 146 | + validationError "The template file ${dcrInput} for creating the domain resource was not found" |
| 147 | + fi |
| 148 | + |
| 149 | + failIfValidationErrors |
| 150 | + |
| 151 | + validateCommonInputs |
| 152 | + |
| 153 | + validateBooleanInputParamsSpecified logHomeOnPV |
| 154 | + failIfValidationErrors |
| 155 | + |
| 156 | + initOutputDir |
| 157 | + |
| 158 | + if [ "${cloneIt}" = true ] || [ ! -d ${domainHomeImageBuildPath} ]; then |
| 159 | + getDockerSample |
| 160 | + fi |
| 161 | +} |
| 162 | + |
| 163 | +# |
| 164 | +# Function to get the dependency docker sample |
| 165 | +# |
| 166 | +function getDockerSample { |
| 167 | + dockerImagesDir=${domainHomeImageBuildPath%/OracleFMWInfrastructure*} |
| 168 | + rm -rf ${dockerImagesDir} |
| 169 | + git clone https://github.com/oracle/docker-images.git ${dockerImagesDir} |
| 170 | +} |
| 171 | + |
| 172 | +# |
| 173 | +# Function to build docker image and create WebLogic domain home |
| 174 | +# |
| 175 | +function createDomainHome { |
| 176 | + dockerDir=${domainHomeImageBuildPath} |
| 177 | + dockerPropsDir=${dockerDir}/properties |
| 178 | + cp ${domainPropertiesOutput} ${dockerPropsDir} |
| 179 | + |
| 180 | + # 12213-domain-home-in-image use one properties file for the credentials |
| 181 | + usernameFile="${dockerPropsDir}/domain_security.properties" |
| 182 | + passwordFile="${dockerPropsDir}/domain_security.properties" |
| 183 | + |
| 184 | + rcuPropFile="${dockerPropsDir}/rcu.properties" |
| 185 | + rcuSecurityPropFile="${dockerPropsDir}/rcu_security.properties" |
| 186 | + |
| 187 | + # 12213-domain-home-in-image-wdt uses two properties files for the credentials |
| 188 | + if [ ! -f $usernameFile ]; then |
| 189 | + usernameFile="${dockerPropsDir}/adminuser.properties" |
| 190 | + passwordFile="${dockerPropsDir}/adminpass.properties" |
| 191 | + fi |
| 192 | + |
| 193 | + sed -i -e "s|myusername|${username}|g" $usernameFile |
| 194 | + sed -i -e "s|welcome1|${password}|g" $passwordFile |
| 195 | + |
| 196 | + sed -i -e "s|INFRA08|${rcuSchemaPrefix}|g" $rcuPropFile |
| 197 | + sed -i -e "s|InfraDB:1521/InfraPDB1.us.oracle.com|${rcuDatabaseURL}|g" $rcuPropFile |
| 198 | + |
| 199 | + if [ ! -z $domainHomeImageBase ]; then |
| 200 | + sed -i -e "s|\(FROM \).*|\1 ${domainHomeImageBase}|g" ${dockerDir}/Dockerfile |
| 201 | + fi |
| 202 | + |
| 203 | + cp ${domainPropertiesOutput} ${dockerPropsDir} |
| 204 | + sed -i '$ a extract_env IMAGE_TAG ${PROPERTIES_FILE} ' ${dockerDir}/container-scripts/setEnv.sh |
| 205 | + |
| 206 | + #exit -1000 |
| 207 | + sh ${dockerDir}/build.sh |
| 208 | + |
| 209 | + if [ "$?" != "0" ]; then |
| 210 | + fail "Create domain ${domainName} failed." |
| 211 | + fi |
| 212 | + |
| 213 | + # clean up the generated domain.properties file |
| 214 | + rm ${domainPropertiesOutput} |
| 215 | + |
| 216 | + echo "" |
| 217 | + echo "Create domain ${domainName} successfully." |
| 218 | +} |
| 219 | + |
| 220 | +# |
| 221 | +# Function to output to the console a summary of the work completed |
| 222 | +# |
| 223 | +function printSummary { |
| 224 | + |
| 225 | + # Get the IP address of the kubernetes cluster (into K8S_IP) |
| 226 | + getKubernetesClusterIP |
| 227 | + |
| 228 | + echo "" |
| 229 | + echo "Domain ${domainName} was created and will be started by the WebLogic Kubernetes Operator" |
| 230 | + echo "" |
| 231 | + if [ "${exposeAdminNodePort}" = true ]; then |
| 232 | + echo "Administration console access is available at http://${K8S_IP}:${adminNodePort}/console" |
| 233 | + fi |
| 234 | + if [ "${exposeAdminT3Channel}" = true ]; then |
| 235 | + echo "T3 access is available at t3://${K8S_IP}:${t3ChannelPort}" |
| 236 | + fi |
| 237 | + echo "The following files were generated:" |
| 238 | + echo " ${domainOutputDir}/create-domain-inputs.yaml" |
| 239 | + echo " ${dcrOutput}" |
| 240 | + echo "" |
| 241 | + echo "Completed" |
| 242 | +} |
| 243 | + |
| 244 | +# Perform the sequence of steps to create a domain |
| 245 | +createDomain true |
| 246 | + |
0 commit comments