Skip to content

Add WebLogic Dockerfiles and scripts #1

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 2 commits into from
Jan 22, 2015
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
3 changes: 3 additions & 0 deletions OracleWebLogic/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Unless otherwise noted, all files in this distribution are released
under the Common Development and Distribution License (CDDL) 1.0
and GNU Public License 2.0 licenses.
80 changes: 80 additions & 0 deletions OracleWebLogic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
WebLogic 12c on Docker
===============
Docker configurations to facilitate installation, configuration, and environment setup for developers.

## Based on Oracle Linux Docker image
For more information please read the [Docker Images from Oracle Linux](http://public-yum.oracle.com/docker-images) page.

## How to build and run
This project comes with two configurations for a WebLogic Docker Image. One is based on the Developer distribution, the other one on the Generic. See below for more details.

In this project you will find a [bin](https://github.com/weblogic-community/weblogic-docker/tree/master/bin) folder with scripts to help you build and run WebLogic on Docker, either with the Developer or the Generic distribution. See below for instructions and usage.

### Building an image
First decide which distribution you want to use, then download the required packages and drop them in the folder of your distribution of choice. Then go into the **bin** folder and run the **buildDockerImage.sh** script as root.

$ ./buildDockerImage.sh -h
Usage: buildDockerImage.sh [-d]

-d: creates image based on 'weblogic12c-developer' distribution, if present.
'weblogic12c-generic' otherwhise.

The Dockerfiles for both distributions will create same WebLogic Domain with the following patches and configurations:

#### For Developers (weblogic12c-developer)
This [Dockerfile](https://github.com/weblogic-community/weblogic-docker/blob/master/weblogic12c-developer/Dockerfile) will create an image using the Developer ZIP Installer for WebLogic 12c 12.1.3. It will configure a base_domain with the following settings:

* JPA 2.1 enabled
* JAX-RS 2.0 shared library deployed
* Admin Username: **weblogic**
* Admin Password: **welcome1**
* Oracle Linux Username: **oracle**
* Oracle Linux Password: **welcome1**
* WebLogic Domain Name: **base_domain**

#### Generic Installer (weblogic12c-generic)
This second [Dockerfile](https://github.com/weblogic-community/weblogic-docker/blob/master/weblogic12c-generic/Dockerfile) creates an image with only WebLogic 12c (Generic Installer) installed, and no domain configured.

For an example of how to extend this image and create your own domain, you can look into the third [Dockerfile](https://github.com/weblogic-community/weblogic-docker/blob/master/weblogic12c-generic/container-domain/Dockerfile) located in **weblogic12c-generic/container-domain** folder.

### Write your own WebLogic domain with WLST
The best way to create your own, or extend domains is by using [WebLogic Scripting Tool](http://docs.oracle.com/cd/E57014_01/cross/wlsttasks.htm). The WLST script used to create domains in both Dockerfiles (for [developers](https://github.com/weblogic-community/weblogic-docker/blob/master/weblogic12c-developer/container-scripts/create-wls-domain.py), and the extended example for [generic installer](https://github.com/weblogic-community/weblogic-docker/blob/master/weblogic12c-generic/container-domain/container-scripts/create-wls-domain.py)) is **create-wls-domain.py** (same for both distributions). This script by default adds JMS resources and a few other settings. You may want to tune this script with your own setup to create DataSources and Connection pools, Security Realms, deploy artifacts, and so on.

You can also extend images and override the existing domain, or create a new one with WLST.

### Running WebLogic AdminServer
To start the WebLogic AdminServer, you can simply call **docker run** command, but we recommend you use the [dockWebLogic.sh](https://github.com/weblogic-community/weblogic-docker/blob/master/bin/dockWebLogic.sh) script. It has the following usage:

$ ./dockWebLogic.sh -h
Usage: dockWebLogic.sh [-a [-p port]] [-n mywlsadmin]

-a : attach AdminServer port to host. If -a is present, will attach. Change default (7001) with -p port
-p port: which port on host to attach AdminServer. Default: 7001
-n name: give a different name for the container. Default: wlsadmin

### Create a Cluster
WebLogic has a [Machine](https://docs.oracle.com/middleware/1213/wls/WLACH/taskhelp/machines/ConfigureMachines.html) concept, which is an operational system with an agent, the Node Manager. This resource allows WebLogic to add [Managed Servers](https://docs.oracle.com/middleware/1213/wls/WLACH/taskhelp/domainconfig/CreateManagedServers.html) to an underlying domain in order to create a flexible environment of servers for different applications and resources, and also to define a [Cluster](). By using **Machines** from containers, you can easily create a [Dynamic Cluster]() by simply firing new NodeManagers containers that will be automatically added to the domain running on the AdminServer, started previously.

To easily plug newly created **Machines** to a domain running on another container, use the [dockNodeManager.sh]() script.

$ ./dockNodeManager.sh -h
Usage: dockNodeManager.sh [-n wls_admin_container_name]

-n: name of the container with a WebLogic AdminServer orchestrating a WebLogic Domain.
Defaults to 'wlsadmin'


## Choose your WebLogic Distribution
This project hosts two configurations for building Docker images with WebLogic 12c.

* Developer Distribution
For more information on the WebLogic 12c ZIP Developer Distribution, visit [WLS Zip Distribution for Oracle WebLogic Server 12.1.3.0](download.oracle.com/otn/nt/middleware/12c/wls/1213/README.txt).
* Generic Full Distribution
For more information on the WebLogic 12c Generic Full Distribution, visit [WebLogic 12.1.3 Documentation](http://docs.oracle.com/middleware/1213/wls/index.html).

## License
To download and run WebLogic 12c Distribution regardless of inside or outside a Docker container, and regardless of Generic or Developer distribution, you must agree and accept the [OTN Free Developer License Terms](http://www.oracle.com/technetwork/licenses/wls-dev-license-1703567.html).

To download and run Oracle JDK regardless of inside or outside a DOcker container, you must agree and accept the [Oracle Binary Code License Agreement for Java SE](http://www.oracle.com/technetwork/java/javase/terms/license/index.html).

All scripts and files hosted in this project and GitHub [weblogic-docker](https://github.com/weblogic-community/weblogic-docker/) repository required to build the Docker images are, unless otherwise noted, released under the Common Development and Distribution License (CDDL) 1.0 and GNU Public License 2.0 licenses.
106 changes: 106 additions & 0 deletions OracleWebLogic/bin/buildDockerImage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
. $SCRIPTS_DIR/setDockerEnv.sh $*

while getopts "hdf" optname
do
case "$optname" in
"h")
echo "Usage: buildDockerImage.sh [-d]"
echo ""
echo " -d: creates image based on 'weblogic12c-developer' distribution. "
echo " 'weblogic12c-generic' otherwhise."
echo ""
exit 0
;;
"d")
setup_developer
;;
"f")
FLATTEN_IMAGE=true
;;
*)
# Should not occur
echo "Unknown error while processing options inside buildDockerImage.sh"
;;
esac
done


DOCKER_SCRIPTS_HOME=$SCRIPTS_DIR/../

echo "Building image '$IMAGE_NAME' based on distribution '$DISTRIBUTION'..."

# GO INTO DISTRIBUTION FOLDER
cd $DOCKER_SCRIPTS_HOME/$DISTRIBUTION

# Validate Java Package
if [ ! -e $JAVA_PKG ]
then
echo "====================="
echo "Download the Oracle JDK ${JAVA_VERSION} RPM for 64 bit and"
echo "drop the file $JAVA_PKG in folder '$DISTRIBUTION' before"
echo "building this image!"
exit
fi


check_md5 $JAVA_PKG $JAVA_PKG_MD5
if [ "$?" -ne 0 ]
then
echo "MD5 for $JAVA_PKG does not match! Download again!"
exit
fi

#
# Validate WLS Package
if [ ! -e $WLS_PKG ]
then
echo "====================="
echo "Download the WebLogic 12c installer and"
echo "drop the file $WLS_PKG in this folder before"
echo "building this WLS Docker image!"
exit
fi

check_md5 $WLS_PKG $WLS_PKG_MD5
if [ "$?" -ne 0 ]
then
echo "MD5 for $WLS_PKG does not match! Download again!"
exit
fi

echo "====================="

# BUILD THE IMAGE
docker build --force-rm=true --no-cache=true --rm=true -t $IMAGE_NAME .

flatten_image() {
if [ ! $FLATTEN_IMAGE ]
then
return 0
fi
echo "Flatten image flag found. Will flat this image..."
docker tag $IMAGE_NAME ${IMAGE_NAME}-flatten
CONTAINER=$(docker run -d ${IMAGE_NAME}-flatten echo)
docker export $CONTAINER | docker import - $IMAGE_NAME
docker rm -f $CONTAINER
docker rmi -f ${IMAGE_NAME}-flatten
}

if [ $? -eq 0 ]
then
flatten_image
if [ $? -eq 0 ]
then
echo ""
echo "WebLogic Docker Container is ready to be used. To start, run 'dockWebLogic.sh'"
else
echo ""
echo "There was an error trying to flatten the image. Please try without the '-f' flag"
fi
else
echo ""
echo "WebLogic Docker Container was NOT successfully created. Check the output and correct any reported problems with the docker build operation."
fi
107 changes: 107 additions & 0 deletions OracleWebLogic/bin/dockNodeManager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/sh
#
# Usage:
# $ sudo dockNodeManager.sh [-n <container name running admin server>]
#
# Since: October, 2014
# Author: bruno.borges@oracle.com
# Description: script to create a WLS container based on IMAGE_NAME and start NodeManager within it. After NodeManager is started, a script 'add-machine.py' is called that will automatically add the NodeManager as Machine into the domain associated to ADMIN_CONTAINER_NAME
#

SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
. $SCRIPTS_DIR/setDockerEnv.sh $*

# CHECK FOR ARGUMENTS
# -n [name] = the name of the admin server container which this NM will automatically plug to. Must exist. Defaults to 'wlsadmin'.
while getopts "i:dhn:" optname
do
case "$optname" in
"i")
IMAGE_NAME="$OPTARG"
;;
"d")
setup_developer
;;
"h")
echo "Usage: dockNodeManager.sh [-i image] [-n wls_admin_container_name] [-d]"
echo ""
echo " -i image: name of your custom WebLogic Docker image. Default: $IMAGE_NAME."
echo " -n name : name of the container with a WebLogic AdminServer orchestrating a domain."
echo " Defaults to 'wlsadmin'"
echo " -d : use the developer image to run the container"
echo ""
exit 0
;;
"n")
ADMIN_CONTAINER_NAME="$OPTARG"
;;
*)
exit 1
;;
esac
done

# CHECK IF CONTAINER EXISTS AND IS RUNNING
# Based on https://gist.github.com/ekristen/11254304 (MIT Licensed)
echo -n "Inspecting image name of AdminServer '$ADMIN_CONTAINER_NAME'..."
IMAGE_OF_ADMIN=$(docker inspect -f '{{.Config.Image}}' $ADMIN_CONTAINER_NAME 2> /dev/null)
if [ "$IMAGE_OF_ADMIN" != "$IMAGE_NAME" ]; then
echo ""
echo "Admin container '$ADMIN_CONTAINER_NAME' is from a different image: '$IMAGE_OF_ADMIN', while you want to use image '$IMAGE_NAME'."
exit $?
fi

echo -n "Inspecting running state of AdminServer '$ADMIN_CONTAINER_NAME'..."
ADMIN_CONTAINER_RUNNING=$(docker inspect --format="{{ .State.Running }}" $ADMIN_CONTAINER_NAME 2> /dev/null)

if [ $? -eq 1 ]; then
echo ""
echo "Admin container '$ADMIN_CONTAINER_NAME' with WLS Admin Server running does not exist. Create one first calling 'dockWebLogic.sh -n $ADMIN_CONTAINER_NAME'"
exit $?
fi

if [ "$ADMIN_CONTAINER_RUNNING" = "false" ]; then
echo ""
echo "Admin container '$ADMIN_CONTAINER_NAME' is not running. Unpause or start it"
exit $?
fi

echo "[OK]!"

echo -n "Inspecting ghost state of AdminServer..."
GHOST_STATUS=$(docker inspect --format="{{ .State.Ghost }}" $ADMIN_CONTAINER_NAME)

if [ "$GHOST_STATUS" = "true" ]; then
echo ""
echo "Admin container '$ADMIN_CONTAINER_NAME' has been ghosted. Destroy it and create again."
exit $?
fi

if [ $? -eq 1 ]; then
exit $?
fi;

echo "[OK!]"

# RUN DOCKER
echo -n "Creating NodeManager container..."
docker run -d \
--name ${NM_CONTAINER_NAME} \
-e DOCKER_CONTAINER_NAME=${NM_CONTAINER_NAME} \
--link $ADMIN_CONTAINER_NAME:wlsadmin $IMAGE_NAME \
/u01/oracle/createMachine.sh > /dev/null 2>&1

echo "[OK!]"

if [ $? -eq 1 ]; then
echo ""
exit $?
fi;

echo -n "Inspecting IP address of newly created NodeManger container with name '$NM_CONTAINER_NAME'..."
NMIP=$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $NM_CONTAINER_NAME)
echo "[OK!]"
echo "===================="
echo "New NodeManager [$NM_CONTAINER_NAME] started on IP Address: $NMIP."
echo "Hopefully this Machine was automatically added to 'base_domain' in the [$ADMIN_CONTAINER_NAME] admin server."
echo "If not, go to Admin Console and try to add it manually with this IP address."
85 changes: 85 additions & 0 deletions OracleWebLogic/bin/dockWebLogic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/sh
#
# Usage:
# -a [port]: attach AdminServer port to host. If -a is present, will attach. Defaults to 7001.
# -n [name]: give a different name for the container. default: wlsadmin
# -d : use the developer image to run the container
# $ sudo sh dockWebLogic.sh -n [container name running admin server]
#
# Since: October, 2014
# Author: bruno.borges@oracle.com
# Description: script to create a container with WLS Admin Server
# based on IMAGE_NAME within it.
#

SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
. $SCRIPTS_DIR/setDockerEnv.sh $*

# CHECK AND READ ARGUMENTS
while getopts "ai:n:p:hd" optname
do
case "$optname" in
"h")
echo "Starts the WebLogic AdminServer within a Docker container."
echo "Usage: dockWebLogic.sh [-i image] [-a [-p port]] [-n mywlsadmin] [-d]"
echo ""
echo " -a : attach AdminServer port to host. If -a is present, will attach. Change default (7001) with -p port"
echo " -p port : which port on host to attach AdminServer. Default: 7001"
echo " -i image: name of your custom WebLogic Docker image. Default: $IMAGE_NAME"
echo " -n name : give a different name for the container. Default: wlsadmin"
echo " -d : use the developer image to run the container"
echo ""
exit 0
;;
"a")
MUST_ATTACH=true
;;
"p")
ATTACH_ADMIN_TO="$OPTARG"
;;
"n")
ADMIN_CONTAINER_NAME="$OPTARG"
;;
"i")
IMAGE_NAME="$OPTARG"
;;
"d")
setup_developer
;;
*)
exit 1
;;
esac
done

if [ $MUST_ATTACH ]; then
ATTACH_DEFAULT_PORT="-p $ATTACH_ADMIN_TO:7001"
fi

# RUN THE DOCKER COMMAND
docker run \
-d $ATTACH_DEFAULT_PORT \
--name $ADMIN_CONTAINER_NAME $IMAGE_NAME \
/u01/oracle/weblogic/user_projects/domains/base_domain/startWebLogic.sh

if [ $? -eq 1 ]; then
exit $?
fi;

# EXTRACT THE IP ADDRESS
if [ -n "${ATTACH_DEFAULT_PORT}" ]
then
WLS_ADMIN_IP=localhost
else
WLS_ADMIN_IP=$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $ADMIN_CONTAINER_NAME)
fi

# REPORT IF DOCKER SUCCEEDED
if [ "$?" = 0 ]; then
echo "WebLogic starting... "
sleep 10
echo "Open WebLogic Console at http://${WLS_ADMIN_IP}:${ATTACH_ADMIN_TO}/console"
else
echo "There was an error trying to create a container"
exit $?
fi
Loading