Skip to content

Issue#owls 69931 align docker sample with operator #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 104 additions & 54 deletions samples/docker-domain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Copyright (c) 2014-2018 Oracle and/or its affiliates. All rights reserved.
#Copyright (c) 2018 Oracle 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.
#
Expand All @@ -11,88 +11,138 @@
#
# HOW TO BUILD THIS IMAGE
# -----------------------
# Put all downloaded files in the same directory as this Dockerfile

# Build the deployment archive file using the build-archive.sh script.
# $ ./build-archive.sh
#
# Run:
# $ sudo docker build \
# --build-arg CUSTOM_ADMIN_HOST=wlsadmin \
# --build-arg CUSTOM_ADMIN_PORT=7001 \
# --build-arg CUSTOM_ADMIN_NAME=7001 \
# --build-arg CUSTOM_MANAGED_SERVER_PORT=8001 \
# --build-arg CUSTOM_DOMAIN_NAME=base_domain \
# --build-arg CUSTOM_DEBUG_PORT=8453 \
# --build-arg WDT_MODEL=simple-topology.yaml \
# --build-arg WDT_ARCHIVE=archive.zip \
# --build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
# --force-rm=true \
# -t 12213-domain-wdt .
#
# If the ADMIN_HOST, ADMIN_PORT, MS_PORT, DOMAIN_NAME are not provided, the variables
# are set to default values. (The values shown in the build statement).
#
# You must insure that the build arguments align with the values in the model.
# The sample model replaces the attributes with tokens that are resolved from values in the
# corresponding property file domain.properties. The container-scripts/setEnv.sh script
# demonstrates parsing the variable file to build a string of --build-args that can
# be passed on the docker build command.
#
# Pull base image
# ---------------
# FROM store/oracle/weblogic:12.2.1.3
FROM oracle/weblogic:12.2.1.3-developer
FROM store/oracle/weblogic:12.2.1.3-dev

# Maintainer
# ----------
MAINTAINER Monica Riccelli <monica.riccelli@oracle.com>
MAINTAINER Richard Killen <richard.killen@oracle.com>

ARG WDT_MODEL
ARG WDT_ARCHIVE
ARG WDT_VARIABLE
ARG WDT_MODEL
ARG CUSTOM_ADMIN_NAME=admin-server
ARG CUSTOM_ADMIN_HOST=wlsadmin
ARG CUSTOM_ADMIN_PORT=7001
ARG CUSTOM_MANAGED_SERVER_PORT=8001
ARG CUSTOM_DOMAIN_NAME=base_domain
ARG CUSTOM_DEBUG_PORT=8453

# WLS Configuration
# Persist arguments - for ports to expose and container to use
# Create a placeholder for the manager server name. This will be provided when run the container
# Weblogic and Domain locations
# Set the start derby in admin server flag to true. Override this in the runtime properties
# The boot.properties will be created under the DOMAIN_HOME when the admin server container is run
# WDT installation
# ---------------------------
ENV ADMIN_HOST="wlsadmin" \
NM_PORT="5556" \
MS_PORT="8001" \
DEBUG_PORT="8453" \
ENV ADMIN_NAME=${CUSTOM_ADMIN_NAME} \
ADMIN_HOST=${CUSTOM_ADMIN_HOST} \
ADMIN_PORT=${CUSTOM_ADMIN_PORT} \
MANAGED_SERVER_NAME=${MANAGED_SERVER_NAME} \
MANAGED_SERVER_PORT=${CUSTOM_MANAGED_SERVER_PORT} \
DEBUG_PORT=${CUSTOM_DEBUG_PORT} \
DERBY_FLAG="true" \
ORACLE_HOME=/u01/oracle \
SCRIPT_FILE=/u01/oracle/createAndStartWLSDomain.sh \
CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true" \
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

# Domain and Server environment variables
# ------------------------------------------------------------
ENV DOMAIN_NAME="${DOMAIN_NAME:-base_domain}" \
PRE_DOMAIN_HOME=/u01/oracle/user_projects \
ADMIN_PORT="${ADMIN_PORT:-7001}" \
WDT_MODEL="$WDT_MODEL" \
WDT_ARCHIVE="$WDT_ARCHIVE"
DOMAIN_NAME=${CUSTOM_DOMAIN_NAME} \
DOMAIN_PARENT=${ORACLE_HOME}/user_projects/domains

# Add files required to build this image
COPY container-scripts/* /u01/oracle/
COPY weblogic-deploy.zip /u01
COPY ${WDT_MODEL} ${ARCHIVE_FILE} /u01/
ENV DOMAIN_HOME=${DOMAIN_PARENT}/${DOMAIN_NAME} \
PROPERTIES_FILE_DIR=$ORACLE_HOME/properties \
WDT_HOME="/u01" \
SCRIPT_HOME="${ORACLE_HOME}" \
PATH=$PATH:${ORACLE_HOME}/oracle_common/common/bin:${ORACLE_HOME}/wlserver/common/bin:${DOMAIN_HOME}:${DOMAIN_HOME}/bin:${ORACLE_HOME}

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

# Create directory where domain will be written to
# Create the properties file directory and the domain home parent with the correct permissions / owner.
# Unzip and install the WDT image and change the permissions / owner.
USER root
RUN chmod +xw /u01/oracle/*.sh && \
chmod +xw /u01/oracle/*.py && \
mkdir -p $PRE_DOMAIN_HOME && \
mkdir -p $PRE_DOMAIN_HOME/domains && \
chmod a+xr $PRE_DOMAIN_HOME && \
chown -R oracle:oracle $PRE_DOMAIN_HOME && \
cd /u01 && \
$JAVA_HOME/bin/jar xf /u01/weblogic-deploy.zip && \
chmod +xw /u01/weblogic-deploy/bin/*.sh && \
chmod -R +xw /u01/weblogic-deploy/lib/python && \
if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file /u01/$WDT_MODEL"; fi && \
if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file /u01/$WDT_ARCHIVE"; fi && \
/u01/weblogic-deploy/bin/createDomain.sh \
RUN chmod +xw $SCRIPT_HOME/*.sh && \
chown -R oracle:oracle ${SCRIPT_HOME} && \
mkdir -p +xwr $PROPERTIES_FILE_DIR && \
chown -R oracle:oracle $PROPERTIES_FILE_DIR && \
mkdir -p $DOMAIN_PARENT && \
chown -R oracle:oracle $DOMAIN_PARENT && \
chmod -R a+xwr $DOMAIN_PARENT && \
cd ${WDT_HOME} && \
$JAVA_HOME/bin/jar xf ./weblogic-deploy.zip && \
rm weblogic-deploy.zip && \
chmod +xw weblogic-deploy/bin/*.sh && \
chmod -R +xw weblogic-deploy/lib/python && \
chown -R oracle:oracle weblogic-deploy

# Persist the WDT tool home location
ENV WDT_HOME=$WDT_HOME/weblogic-deploy

# Copy the WDT model, archive file, variable file and credential secrets to the property file directory.
# These files will be removed after the image is built.
# Be sure to build with --force-rm to eliminate this container layer

COPY ${WDT_MODEL} ${WDT_ARCHIVE} ${WDT_VARIABLE} properties/docker-build/*.properties ${PROPERTIES_FILE_DIR}/
# --chown for COPY is available in docker version 18 'COPY --chown oracle:oracle'
RUN chown -R oracle:oracle ${PROPERTIES_FILE_DIR}

# Create the domain home in the docker image.
#
# The create domain tool creates a domain at the DOMAIN_HOME location
# The domain name is set using the value in the model / variable files
# The domain name can be different from the DOMAIN_HOME domain folder name.
#
# Set WORKDIR for @@PWD@@ global token in model file
WORKDIR $ORACLE_HOME
USER oracle
RUN if [ -n "$WDT_MODEL" ]; then MODEL_OPT="-model_file $PROPERTIES_FILE_DIR/${WDT_MODEL##*/}"; fi && \
if [ -n "$WDT_ARCHIVE" ]; then ARCHIVE_OPT="-archive_file $PROPERTIES_FILE_DIR/${WDT_ARCHIVE##*/}"; fi && \
if [ -n "$WDT_VARIABLE" ]; then VARIABLE_OPT="-variable_file $PROPERTIES_FILE_DIR/${WDT_VARIABLE##*/}"; fi && \
${WDT_HOME}/bin/createDomain.sh \
-oracle_home $ORACLE_HOME \
-java_home ${JAVA_HOME} \
-domain_parent $PRE_DOMAIN_HOME/domains \
-java_home $JAVA_HOME \
-domain_home $DOMAIN_HOME \
-domain_type WLS \
-variable_file /u01/oracle/domain.properties \
$VARIABLE_OPT \
$MODEL_OPT \
$ARCHIVE_OPT && \
chown -R oracle:oracle $PRE_DOMAIN_HOME && \
rm /u01/oracle/domain.properties
chmod -R a+x $DOMAIN_HOME/bin/*.sh && \
rm -rf $PROPERTIES_FILE_DIR

VOLUME $PRE_DOMAIN_HOME
# Expose Node Manager default port, and also default for admin and managed server
EXPOSE $NM_PORT $ADMIN_PORT $MS_PORT $DEBUG_PORT
# Mount the domain home and the WDT home for easy access.
VOLUME $DOMAIN_HOME
VOLUME $WDT_HOME

USER oracle
WORKDIR $ORACLE_HOME
# Expose admin server, managed server port and domain debug port
EXPOSE $ADMIN_PORT $MANAGED_SERVER_PORT $DEBUG_PORT

WORKDIR $DOMAIN_HOME

# Define default command to start bash.
CMD ["/u01/oracle/startWLSDomain.sh"]
# Define default command to start Admin Server in a container.
CMD ["/u01/oracle/startAdminServer.sh"]
73 changes: 66 additions & 7 deletions samples/docker-domain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ This sample includes a basic WDT model, `simple-topology.yaml`, that describes t

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.

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.

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.

See the README file for more information on using property and file tokens in the WDT model.

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.

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.

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.

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.
Expand All @@ -28,27 +38,76 @@ This sample deploys a simple, one-page web application contained in a ZIP archiv

$ ./build-archive.sh

To build this sample, run:
The sample requires the Admin Host, Admin Port and Admin Name. It also requires the Managed Server port and the domain Debug
Port. The ports will be EXPOSED through Docker. The other arguments are persisted in the image to be used when running a
container. If an attribute is not provided as a --build-arg on the build command, the following defaults are set.

CUSTOM_ADMIN_NAME = admin-server
The value is persisted to the image as ADMIN_NAME

CUSTOM_ADMIN_HOST = wlsadmin
The value is persisted to the image as ADMIN_HOST

CUSTOM_ADMIN_PORT = 7001
The value is persisted to the image as ADMIN_PORT

CUSTOM_MANAGED_SERVER_PORT = 8001
The value is persisted to the image as MANAGED_SERVER_PORT

CUSTOM_DEBUG_PORT = 8453
The value is persisted to the image as DEBUG_PORT

CUSTOM_DOMAIN_NAME = base_domain
The value is persisted to the image as DOMAIN_NAME

To build this sample taking the defaults, run:

$ docker build \
--build-arg WDT_MODEL=simple-topology.yaml \
--build-arg WDT_ARCHIVE=archive.zip \
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
--force-rm=true \
-t 12213-domain-wdt .

This will use the model file and archive in the sample directory.
This will use the model, variable and archive files in the sample directory.

This sample provides a script which will read the model variable file and parse the domain, admin and managed server information
into a string of --build-arg statements. This build arg string is exported as environment variable BUILD_ARG.
The sample script specifically parses the sample variable file. Use it as an example to parse a custom variable file.
This will insure that the values docker exposes and persists in the image are the same values configured in the domain.

To parse the sample variable file and build the sample, run:

$ container-scripts/setEnv.sh properties/docker-build/domain.properties

$ docker build \
$BUILD_ARG \
--build-arg WDT_MODEL=simple-topology.yaml \
--build-arg WDT_ARCHIVE=archive.zip \
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
--force-rm=true \
-t 12213-domain-wdt .

This sample provides a Derby Data Source that is targeted to the Managed Server cluster. The Derby database is created
in the Admin Server container when the container is run. To turn off the database create, set DERBY_FLAG="false" in the
runtime security.properties used on the docker run statement.

The Admin Server and each Managed Server are run in containers from this build image. In the sample, the securities.properties file
is provided on the docker run command. In addition to the credentials and DERBY_FLAG, the file contains the JAVA_OPTS for the
running Admin or Managed server. Mount the properties/docker-run directory to the container so that file can be accessed by the
server start script. It is the responsibility of the user to manage this volume, and the security.properties, in the container.

To start the containerized Administration Server, run:

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

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

$ 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
$ 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

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

$ 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
$ 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

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

Expand Down
9 changes: 9 additions & 0 deletions samples/docker-domain/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
#
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

# parse the ADMIN_HOST, ADMIN_PORT, MS_PORT, and DOMAIN_NAME from the sample properties file and pass
# as a string of --build-arg in the variable BUILD_ARG
. container-scripts/setEnv.sh properties/docker-build/domain.properties


docker build \
$BUILD_ARG \
--build-arg WDT_MODEL=simple-topology.yaml \
--build-arg WDT_VARIABLE=properties/docker-build/domain.properties \
--build-arg WDT_ARCHIVE=archive.zip \
--force-rm=true \
-t 12213-domain-wdt .

70 changes: 70 additions & 0 deletions samples/docker-domain/container-scripts/setEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash ex

# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
# The Universal Permissive License (UPL), Version 1.0
#
# This example creates the BUILD_ARG environment variable as a string of --build-arg for
# the arguments passed on the docker build command. The variable file that is used for the WDT
# create domain step is the input to this script. This insures that the values persisted
# as environment variables in the docker image match the configured domain home.

BUILD_ARG=''
if [ $# > 1 ]; then
PROPERTIES_FILE=$1
fi

if [ ! -e "${PROPERTIES_FILE}" ]; then
echo "A properties file with variable definitions should be supplied."
fi

echo Export environment variables from the ${PROPERTIES_FILE} properties file

DOMAIN_DIR=`awk '{print $1}' $PROPERTIES_FILE | grep ^DOMAIN_NAME= | cut -d "=" -f2`
if [ ! -n "$DOMAIN_DIR" ]; then
if [ -n "$DOMAIN_NAME" ]; then
DOMAIN_DIR=$DOMAIN_NAME
fi
fi
if [ -n "$DOMAIN_DIR" ]; then
DOMAIN_NAME=$DOMAIN_DIR
export DOMAIN_NAME
echo DOMAIN_NAME=$DOMAIN_NAME
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_DOMAIN_NAME=$DOMAIN_NAME"
fi

ADMIN_HOST=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_HOST= | cut -d "=" -f2`
if [ -n "$ADMIN_HOST" ]; then
export ADMIN_HOST
echo ADMIN_HOST=$ADMIN_HOST
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_HOST=$ADMIN_HOST"
fi

ADMIN_NAME=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_NAME= | cut -d "=" -f2`
if [ -n "$ADMIN_NAME" ]; then
export ADMIN_NAME
echo ADMIN_NAME=$ADMIN_NAME
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_NAME=$ADMIN_NAME"
fi

ADMIN_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^ADMIN_PORT= | cut -d "=" -f2`
if [ -n "$ADMIN_PORT" ]; then
export ADMIN_PORT
echo ADMIN_PORT=$ADMIN_PORT
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_ADMIN_PORT=$ADMIN_PORT"
fi

MANAGED_SERVER_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^MANAGED_SERVER_PORT= | cut -d "=" -f2`
if [ -n "$MANAGED_SERVER_PORT" ]; then
export MANAGED_SERVER_PORT
echo MANAGED_SERVER_PORT=$MANAGED_SERVER_PORT
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_MANAGED_SERVER_PORT=$MANAGED_SERVER_PORT"
fi

DEBUG_PORT=`awk '{print $1}' $PROPERTIES_FILE | grep ^DEBUG_PORT= | cut -d "=" -f2`
if [ -n "$DEBUG_PORT" ]; then
export DEBUG_PORT
echo DEBUG_PORT=$DEBUG_PORT
BUILD_ARG="$BUILD_ARG --build-arg CUSTOM_DEBUG_PORT=$DEBUG_PORT"
fi

echo BUILD_ARG=$BUILD_ARG
Loading