Skip to content

Commit eb6bf9f

Browse files
authoredDec 7, 2018
Merge pull request #196 from oracle/Issue#OWLS-69931-align-docker-sample-with-operator
Issue#owls 69931 align docker sample with operator
2 parents e2b0063 + 218213c commit eb6bf9f

14 files changed

+431
-200
lines changed
 

‎samples/docker-domain/Dockerfile

Lines changed: 104 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Copyright (c) 2014-2018 Oracle and/or its affiliates. All rights reserved.
1+
#Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22
#
33
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44
#
@@ -11,88 +11,138 @@
1111
#
1212
# HOW TO BUILD THIS IMAGE
1313
# -----------------------
14-
# Put all downloaded files in the same directory as this Dockerfile
14+
1515
# Build the deployment archive file using the build-archive.sh script.
1616
# $ ./build-archive.sh
1717
#
1818
# Run:
1919
# $ sudo docker build \
20+
# --build-arg CUSTOM_ADMIN_HOST=wlsadmin \
21+
# --build-arg CUSTOM_ADMIN_PORT=7001 \
22+
# --build-arg CUSTOM_ADMIN_NAME=7001 \
23+
# --build-arg CUSTOM_MANAGED_SERVER_PORT=8001 \
24+
# --build-arg CUSTOM_DOMAIN_NAME=base_domain \
25+
# --build-arg CUSTOM_DEBUG_PORT=8453 \
2026
# --build-arg WDT_MODEL=simple-topology.yaml \
2127
# --build-arg WDT_ARCHIVE=archive.zip \
28+
# --build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
2229
# --force-rm=true \
2330
# -t 12213-domain-wdt .
2431
#
32+
# If the ADMIN_HOST, ADMIN_PORT, MS_PORT, DOMAIN_NAME are not provided, the variables
33+
# are set to default values. (The values shown in the build statement).
34+
#
35+
# You must insure that the build arguments align with the values in the model.
36+
# The sample model replaces the attributes with tokens that are resolved from values in the
37+
# corresponding property file domain.properties. The container-scripts/setEnv.sh script
38+
# demonstrates parsing the variable file to build a string of --build-args that can
39+
# be passed on the docker build command.
40+
#
2541
# Pull base image
2642
# ---------------
2743
# FROM store/oracle/weblogic:12.2.1.3
28-
FROM oracle/weblogic:12.2.1.3-developer
44+
FROM store/oracle/weblogic:12.2.1.3-dev
2945

3046
# Maintainer
3147
# ----------
32-
MAINTAINER Monica Riccelli <monica.riccelli@oracle.com>
48+
MAINTAINER Richard Killen <richard.killen@oracle.com>
3349

34-
ARG WDT_MODEL
3550
ARG WDT_ARCHIVE
51+
ARG WDT_VARIABLE
52+
ARG WDT_MODEL
53+
ARG CUSTOM_ADMIN_NAME=admin-server
54+
ARG CUSTOM_ADMIN_HOST=wlsadmin
55+
ARG CUSTOM_ADMIN_PORT=7001
56+
ARG CUSTOM_MANAGED_SERVER_PORT=8001
57+
ARG CUSTOM_DOMAIN_NAME=base_domain
58+
ARG CUSTOM_DEBUG_PORT=8453
3659

37-
# WLS Configuration
60+
# Persist arguments - for ports to expose and container to use
61+
# Create a placeholder for the manager server name. This will be provided when run the container
62+
# Weblogic and Domain locations
63+
# Set the start derby in admin server flag to true. Override this in the runtime properties
64+
# The boot.properties will be created under the DOMAIN_HOME when the admin server container is run
65+
# WDT installation
3866
# ---------------------------
39-
ENV ADMIN_HOST="wlsadmin" \
40-
NM_PORT="5556" \
41-
MS_PORT="8001" \
42-
DEBUG_PORT="8453" \
67+
ENV ADMIN_NAME=${CUSTOM_ADMIN_NAME} \
68+
ADMIN_HOST=${CUSTOM_ADMIN_HOST} \
69+
ADMIN_PORT=${CUSTOM_ADMIN_PORT} \
70+
MANAGED_SERVER_NAME=${MANAGED_SERVER_NAME} \
71+
MANAGED_SERVER_PORT=${CUSTOM_MANAGED_SERVER_PORT} \
72+
DEBUG_PORT=${CUSTOM_DEBUG_PORT} \
73+
DERBY_FLAG="true" \
4374
ORACLE_HOME=/u01/oracle \
44-
SCRIPT_FILE=/u01/oracle/createAndStartWLSDomain.sh \
45-
CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true" \
46-
PATH=$PATH:/u01/oracle/oracle_common/common/bin:/u01/oracle/wlserver/common/bin:/u01/oracle/user_projects/domains/${DOMAIN_NAME:-base_domain}/bin:/u01/oracle
47-
48-
# Domain and Server environment variables
49-
# ------------------------------------------------------------
50-
ENV DOMAIN_NAME="${DOMAIN_NAME:-base_domain}" \
51-
PRE_DOMAIN_HOME=/u01/oracle/user_projects \
52-
ADMIN_PORT="${ADMIN_PORT:-7001}" \
53-
WDT_MODEL="$WDT_MODEL" \
54-
WDT_ARCHIVE="$WDT_ARCHIVE"
75+
DOMAIN_NAME=${CUSTOM_DOMAIN_NAME} \
76+
DOMAIN_PARENT=${ORACLE_HOME}/user_projects/domains
5577

56-
# Add files required to build this image
57-
COPY container-scripts/* /u01/oracle/
58-
COPY weblogic-deploy.zip /u01
59-
COPY ${WDT_MODEL} ${ARCHIVE_FILE} /u01/
78+
ENV DOMAIN_HOME=${DOMAIN_PARENT}/${DOMAIN_NAME} \
79+
PROPERTIES_FILE_DIR=$ORACLE_HOME/properties \
80+
WDT_HOME="/u01" \
81+
SCRIPT_HOME="${ORACLE_HOME}" \
82+
PATH=$PATH:${ORACLE_HOME}/oracle_common/common/bin:${ORACLE_HOME}/wlserver/common/bin:${DOMAIN_HOME}:${DOMAIN_HOME}/bin:${ORACLE_HOME}
6083

61-
# this file contains credentials.
62-
# be sure to build with --force-rm to eliminate this container layer
63-
COPY properties /u01/oracle
84+
COPY weblogic-deploy.zip ${WDT_HOME}
85+
COPY container-scripts/* ${SCRIPT_HOME}/
6486

65-
# Create directory where domain will be written to
87+
# Create the properties file directory and the domain home parent with the correct permissions / owner.
88+
# Unzip and install the WDT image and change the permissions / owner.
6689
USER root
67-
RUN chmod +xw /u01/oracle/*.sh && \
68-
chmod +xw /u01/oracle/*.py && \
69-
mkdir -p $PRE_DOMAIN_HOME && \
70-
mkdir -p $PRE_DOMAIN_HOME/domains && \
71-
chmod a+xr $PRE_DOMAIN_HOME && \
72-
chown -R oracle:oracle $PRE_DOMAIN_HOME && \
73-
cd /u01 && \
74-
$JAVA_HOME/bin/jar xf /u01/weblogic-deploy.zip && \
75-
chmod +xw /u01/weblogic-deploy/bin/*.sh && \
76-
chmod -R +xw /u01/weblogic-deploy/lib/python && \
77-
if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file /u01/$WDT_MODEL"; fi && \
78-
if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file /u01/$WDT_ARCHIVE"; fi && \
79-
/u01/weblogic-deploy/bin/createDomain.sh \
90+
RUN chmod +xw $SCRIPT_HOME/*.sh && \
91+
chown -R oracle:oracle ${SCRIPT_HOME} && \
92+
mkdir -p +xwr $PROPERTIES_FILE_DIR && \
93+
chown -R oracle:oracle $PROPERTIES_FILE_DIR && \
94+
mkdir -p $DOMAIN_PARENT && \
95+
chown -R oracle:oracle $DOMAIN_PARENT && \
96+
chmod -R a+xwr $DOMAIN_PARENT && \
97+
cd ${WDT_HOME} && \
98+
$JAVA_HOME/bin/jar xf ./weblogic-deploy.zip && \
99+
rm weblogic-deploy.zip && \
100+
chmod +xw weblogic-deploy/bin/*.sh && \
101+
chmod -R +xw weblogic-deploy/lib/python && \
102+
chown -R oracle:oracle weblogic-deploy
103+
104+
# Persist the WDT tool home location
105+
ENV WDT_HOME=$WDT_HOME/weblogic-deploy
106+
107+
# Copy the WDT model, archive file, variable file and credential secrets to the property file directory.
108+
# These files will be removed after the image is built.
109+
# Be sure to build with --force-rm to eliminate this container layer
110+
111+
COPY ${WDT_MODEL} ${WDT_ARCHIVE} ${WDT_VARIABLE} properties/docker-build/*.properties ${PROPERTIES_FILE_DIR}/
112+
# --chown for COPY is available in docker version 18 'COPY --chown oracle:oracle'
113+
RUN chown -R oracle:oracle ${PROPERTIES_FILE_DIR}
114+
115+
# Create the domain home in the docker image.
116+
#
117+
# The create domain tool creates a domain at the DOMAIN_HOME location
118+
# The domain name is set using the value in the model / variable files
119+
# The domain name can be different from the DOMAIN_HOME domain folder name.
120+
#
121+
# Set WORKDIR for @@PWD@@ global token in model file
122+
WORKDIR $ORACLE_HOME
123+
USER oracle
124+
RUN if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file $PROPERTIES_FILE_DIR/${WDT_MODEL##*/}"; fi && \
125+
if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file $PROPERTIES_FILE_DIR/${WDT_ARCHIVE##*/}"; fi && \
126+
if [ -n "$WDT_VARIABLE" ]; then VARIABLE_OPT="-variable_file $PROPERTIES_FILE_DIR/${WDT_VARIABLE##*/}"; fi && \
127+
${WDT_HOME}/bin/createDomain.sh \
80128
-oracle_home $ORACLE_HOME \
81-
-java_home ${JAVA_HOME} \
82-
-domain_parent $PRE_DOMAIN_HOME/domains \
129+
-java_home $JAVA_HOME \
130+
-domain_home $DOMAIN_HOME \
83131
-domain_type WLS \
84-
-variable_file /u01/oracle/domain.properties \
132+
$VARIABLE_OPT \
85133
$MODEL_OPT \
86134
$ARCHIVE_OPT && \
87-
chown -R oracle:oracle $PRE_DOMAIN_HOME && \
88-
rm /u01/oracle/domain.properties
135+
chmod -R a+x $DOMAIN_HOME/bin/*.sh && \
136+
rm -rf $PROPERTIES_FILE_DIR
89137

90-
VOLUME $PRE_DOMAIN_HOME
91-
# Expose Node Manager default port, and also default for admin and managed server
92-
EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT $DEBUG_PORT
138+
# Mount the domain home and the WDT home for easy access.
139+
VOLUME $DOMAIN_HOME
140+
VOLUME $WDT_HOME
93141

94-
USER oracle
95-
WORKDIR $ORACLE_HOME
142+
# Expose admin server, managed server port and domain debug port
143+
EXPOSE $ADMIN_PORT $MANAGED_SERVER_PORT $DEBUG_PORT
144+
145+
WORKDIR $DOMAIN_HOME
96146

97-
# Define default command to start bash.
98-
CMD ["/u01/oracle/startWLSDomain.sh"]
147+
# Define default command to start Admin Server in a container.
148+
CMD ["/u01/oracle/startAdminServer.sh"]

‎samples/docker-domain/README.md

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ This sample includes a basic WDT model, `simple-topology.yaml`, that describes t
1212

1313
Another option is to use the WDT `discoverDomain` tool to create a model. This process is also described in the WDT project's README file. A user can use the tool to analyze an existing domain, and create a model based on its configuration. The user may choose to customize the model before using it to create a new Docker image.
1414

15+
The sample model is accompanied by a properties file whose values can be changed to customize a domain. The model's variable tokens are replaced with values from 'simple-topology.properties' when building the docker image. The properties files can be created and modified using a text editor. Select variables in the properties file are used by the Dockerfile during the build to persist ENV variables and expose ports in the image.
16+
17+
Care should be taken to secure the credentials that are present in the model. The ADMIN credential attributes in the sample model have a file token referencing a special property file. Each special property file must only contain a single property and can be created and modified using a text editor. The sample includes the files adminuser.properties and the adminpass.properties in the properties/docker_build directory.
18+
19+
See the README file for more information on using property and file tokens in the WDT model.
20+
21+
The ADMIN credentials are necessary to start the Admin or Managed Server in a docker container. The sample provides security.properties in the properties/docker-run directory. This file contains the admin credentials and additional properties used to customize the Weblogic Server start.
22+
23+
Note: Oracle recommends that the adminpass.properties, adminuser.properties and security.properties files be deleted or secured after the image is built and the WebLogic Server are started so that the user name and password are not inadvertently exposed.
24+
1525
Domain creation may require the deployment of applications and libraries. This is accomplished by creating a ZIP archive with a specific structure, then referencing those items in the model. This sample creates and deploys a simple ZIP archive containing a small application WAR. That archive is built in the sample directory prior to creating the Docker image.
1626

1727
When the WDT `discoverDomain` tool is used on an existing domain, a ZIP archive is created containing any necessary applications and libraries. The corresponding configuration for those applications and libraries is added to the model.
@@ -28,27 +38,76 @@ This sample deploys a simple, one-page web application contained in a ZIP archiv
2838

2939
$ ./build-archive.sh
3040

31-
To build this sample, run:
41+
The sample requires the Admin Host, Admin Port and Admin Name. It also requires the Managed Server port and the domain Debug
42+
Port. The ports will be EXPOSED through Docker. The other arguments are persisted in the image to be used when running a
43+
container. If an attribute is not provided as a --build-arg on the build command, the following defaults are set.
44+
45+
CUSTOM_ADMIN_NAME = admin-server
46+
The value is persisted to the image as ADMIN_NAME
47+
48+
CUSTOM_ADMIN_HOST = wlsadmin
49+
The value is persisted to the image as ADMIN_HOST
50+
51+
CUSTOM_ADMIN_PORT = 7001
52+
The value is persisted to the image as ADMIN_PORT
53+
54+
CUSTOM_MANAGED_SERVER_PORT = 8001
55+
The value is persisted to the image as MANAGED_SERVER_PORT
56+
57+
CUSTOM_DEBUG_PORT = 8453
58+
The value is persisted to the image as DEBUG_PORT
59+
60+
CUSTOM_DOMAIN_NAME = base_domain
61+
The value is persisted to the image as DOMAIN_NAME
62+
63+
To build this sample taking the defaults, run:
3264

3365
$ docker build \
3466
--build-arg WDT_MODEL=simple-topology.yaml \
3567
--build-arg WDT_ARCHIVE=archive.zip \
68+
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
3669
--force-rm=true \
3770
-t 12213-domain-wdt .
3871

39-
This will use the model file and archive in the sample directory.
72+
This will use the model, variable and archive files in the sample directory.
73+
74+
This sample provides a script which will read the model variable file and parse the domain, admin and managed server information
75+
into a string of --build-arg statements. This build arg string is exported as environment variable BUILD_ARG.
76+
The sample script specifically parses the sample variable file. Use it as an example to parse a custom variable file.
77+
This will insure that the values docker exposes and persists in the image are the same values configured in the domain.
78+
79+
To parse the sample variable file and build the sample, run:
80+
81+
$ container-scripts/setEnv.sh properties/docker-build/domain.properties
82+
83+
$ docker build \
84+
$BUILD_ARG \
85+
--build-arg WDT_MODEL=simple-topology.yaml \
86+
--build-arg WDT_ARCHIVE=archive.zip \
87+
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
88+
--force-rm=true \
89+
-t 12213-domain-wdt .
90+
91+
This sample provides a Derby Data Source that is targeted to the Managed Server cluster. The Derby database is created
92+
in the Admin Server container when the container is run. To turn off the database create, set DERBY_FLAG="false" in the
93+
runtime security.properties used on the docker run statement.
94+
95+
The Admin Server and each Managed Server are run in containers from this build image. In the sample, the securities.properties file
96+
is provided on the docker run command. In addition to the credentials and DERBY_FLAG, the file contains the JAVA_OPTS for the
97+
running Admin or Managed server. Mount the properties/docker-run directory to the container so that file can be accessed by the
98+
server start script. It is the responsibility of the user to manage this volume, and the security.properties, in the container.
4099

41100
To start the containerized Administration Server, run:
42101

43-
$ docker run -d --name wlsadmin --hostname wlsadmin -p 7001:7001 -v <sample-directory>/properties:/u01/oracle/properties 12213-domain-wdt
102+
$ docker run -d --name wlsadmin --hostname wlsadmin -p 7001:7001 -v <sample-directory>/properties/docker_run:/u01/oracle/properties 12213-domain-wdt
44103

45-
To start a containerized Managed Server (ms-1) to self-register with the Administration Server above, run:
104+
To start a containerized Managed Server (managed-server-1) to self-register with the Administration Server above, run:
46105

47-
$ docker run -d --name ms-1 --link wlsadmin:wlsadmin -p 9001:9001 -v <sample-directory>/properties:/u01/oracle/properties -e MS_NAME=ms-1 12213-domain-wdt startManagedServer.sh
106+
$ docker run -d --name managed-server-1 --link wlsadmin:wlsadmin -p 9001:9001 -v <sample-directory>/properties/docker_run:/u01/oracle/properties -e MANAGED_SERVER_NAME=managed-server-1 12213-domain-wdt startManagedServer.sh
48107

49-
To start an additional Managed Server (in this example ms-2), run:
108+
To start an additional Managed Server (in this example managed-server-2), run:
50109

51-
$ docker run -d --name ms-2 --link wlsadmin:wlsadmin -p 9002:9001 -v <sample-directory>/properties:/u01/oracle/properties -e MS_NAME=ms-2 12213-domain-wdt startManagedServer.sh
110+
$ docker run -d --name managed-server-2 --link wlsadmin:wlsadmin -p 9002:9001 -v <sample-directory>/properties/docker_run/:/u01/oracle/properties -e MANAGED_SERVER_NAME=managed-server-2 12213-domain-wdt startManagedServer.sh
52111

53112
The above scenario from this sample will give you a WebLogic domain with a dynamic cluster set up on a single host environment.
54113

‎samples/docker-domain/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
#
55
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
66
#
7+
8+
# parse the ADMIN_HOST, ADMIN_PORT, MS_PORT, and DOMAIN_NAME from the sample properties file and pass
9+
# as a string of --build-arg in the variable BUILD_ARG
10+
. container-scripts/setEnv.sh properties/docker-build/domain.properties
11+
12+
713
docker build \
14+
$BUILD_ARG \
815
--build-arg WDT_MODEL=simple-topology.yaml \
16+
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
917
--build-arg WDT_ARCHIVE=archive.zip \
18+
--force-rm=true \
1019
-t 12213-domain-wdt .
1120

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash ex
2+
3+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# This example creates the BUILD_ARG environment variable as a string of --build-arg for
7+
# the arguments passed on the docker build command. The variable file that is used for the WDT
8+
# create domain step is the input to this script. This insures that the values persisted
9+
# as environment variables in the docker image match the configured domain home.
10+
11+
BUILD_ARG=''
12+
if [ $# > 1 ]; then
13+
PROPERTIES_FILE=$1
14+
fi
15+
16+
if [ ! -e "${PROPERTIES_FILE}" ]; then
17+
echo "A properties file with variable definitions should be supplied."
18+
fi
19+
20+
echo Export environment variables from the ${PROPERTIES_FILE} properties file
21+
22+
DOMAIN_DIR=`awk '{print $1}' $PROPERTIES_FILE | grep ^DOMAIN_NAME= | cut -d "=" -f2`
23+
if [ ! -n "$DOMAIN_DIR" ]; then
24+
if [ -n "$DOMAIN_NAME" ]; then
25+
DOMAIN_DIR=$DOMAIN_NAME
26+
fi
27+
fi
28+
if [ -n "$DOMAIN_DIR" ]; then
29+
DOMAIN_NAME=$DOMAIN_DIR
30+
export DOMAIN_NAME
31+
echo DOMAIN_NAME=$DOMAIN_NAME
32+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_DOMAIN_NAME=$DOMAIN_NAME"
33+
fi
34+
35+
ADMIN_HOST=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_HOST= | cut -d "=" -f2`
36+
if [ -n "$ADMIN_HOST" ]; then
37+
export ADMIN_HOST
38+
echo ADMIN_HOST=$ADMIN_HOST
39+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_HOST=$ADMIN_HOST"
40+
fi
41+
42+
ADMIN_NAME=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_NAME= | cut -d "=" -f2`
43+
if [ -n "$ADMIN_NAME" ]; then
44+
export ADMIN_NAME
45+
echo ADMIN_NAME=$ADMIN_NAME
46+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_NAME=$ADMIN_NAME"
47+
fi
48+
49+
ADMIN_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_PORT= | cut -d "=" -f2`
50+
if [ -n "$ADMIN_PORT" ]; then
51+
export ADMIN_PORT
52+
echo ADMIN_PORT=$ADMIN_PORT
53+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_PORT=$ADMIN_PORT"
54+
fi
55+
56+
MANAGED_SERVER_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^MANAGED_SERVER_PORT= | cut -d "=" -f2`
57+
if [ -n "$MANAGED_SERVER_PORT" ]; then
58+
export MANAGED_SERVER_PORT
59+
echo MANAGED_SERVER_PORT=$MANAGED_SERVER_PORT
60+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_MANAGED_SERVER_PORT=$MANAGED_SERVER_PORT"
61+
fi
62+
63+
DEBUG_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^DEBUG_PORT= | cut -d "=" -f2`
64+
if [ -n "$DEBUG_PORT" ]; then
65+
export DEBUG_PORT
66+
echo DEBUG_PORT=$DEBUG_PORT
67+
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_DEBUG_PORT=$DEBUG_PORT"
68+
fi
69+
70+
echo BUILD_ARG=$BUILD_ARG

0 commit comments

Comments
 (0)