Skip to content

Commit 7a72c13

Browse files
committed
Merge pull request #1 from brunoborges/master
Add WebLogic Dockerfiles and scripts
2 parents d75536d + 3870a36 commit 7a72c13

31 files changed

+1253
-2
lines changed

OracleWebLogic/LICENSE

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Unless otherwise noted, all files in this distribution are released
2+
under the Common Development and Distribution License (CDDL) 1.0
3+
and GNU Public License 2.0 licenses.

OracleWebLogic/README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
WebLogic 12c on Docker
2+
===============
3+
Docker configurations to facilitate installation, configuration, and environment setup for developers.
4+
5+
## Based on Oracle Linux Docker image
6+
For more information please read the [Docker Images from Oracle Linux](http://public-yum.oracle.com/docker-images) page.
7+
8+
## How to build and run
9+
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.
10+
11+
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.
12+
13+
### Building an image
14+
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.
15+
16+
$ ./buildDockerImage.sh -h
17+
Usage: buildDockerImage.sh [-d]
18+
19+
-d: creates image based on 'weblogic12c-developer' distribution, if present.
20+
'weblogic12c-generic' otherwhise.
21+
22+
The Dockerfiles for both distributions will create same WebLogic Domain with the following patches and configurations:
23+
24+
#### For Developers (weblogic12c-developer)
25+
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:
26+
27+
* JPA 2.1 enabled
28+
* JAX-RS 2.0 shared library deployed
29+
* Admin Username: **weblogic**
30+
* Admin Password: **welcome1**
31+
* Oracle Linux Username: **oracle**
32+
* Oracle Linux Password: **welcome1**
33+
* WebLogic Domain Name: **base_domain**
34+
35+
#### Generic Installer (weblogic12c-generic)
36+
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.
37+
38+
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.
39+
40+
### Write your own WebLogic domain with WLST
41+
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.
42+
43+
You can also extend images and override the existing domain, or create a new one with WLST.
44+
45+
### Running WebLogic AdminServer
46+
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:
47+
48+
$ ./dockWebLogic.sh -h
49+
Usage: dockWebLogic.sh [-a [-p port]] [-n mywlsadmin]
50+
51+
-a : attach AdminServer port to host. If -a is present, will attach. Change default (7001) with -p port
52+
-p port: which port on host to attach AdminServer. Default: 7001
53+
-n name: give a different name for the container. Default: wlsadmin
54+
55+
### Create a Cluster
56+
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.
57+
58+
To easily plug newly created **Machines** to a domain running on another container, use the [dockNodeManager.sh]() script.
59+
60+
$ ./dockNodeManager.sh -h
61+
Usage: dockNodeManager.sh [-n wls_admin_container_name]
62+
63+
-n: name of the container with a WebLogic AdminServer orchestrating a WebLogic Domain.
64+
Defaults to 'wlsadmin'
65+
66+
67+
## Choose your WebLogic Distribution
68+
This project hosts two configurations for building Docker images with WebLogic 12c.
69+
70+
* Developer Distribution
71+
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).
72+
* Generic Full Distribution
73+
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).
74+
75+
## License
76+
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).
77+
78+
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).
79+
80+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
3+
SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
4+
. $SCRIPTS_DIR/setDockerEnv.sh $*
5+
6+
while getopts "hdf" optname
7+
do
8+
case "$optname" in
9+
"h")
10+
echo "Usage: buildDockerImage.sh [-d]"
11+
echo ""
12+
echo " -d: creates image based on 'weblogic12c-developer' distribution. "
13+
echo " 'weblogic12c-generic' otherwhise."
14+
echo ""
15+
exit 0
16+
;;
17+
"d")
18+
setup_developer
19+
;;
20+
"f")
21+
FLATTEN_IMAGE=true
22+
;;
23+
*)
24+
# Should not occur
25+
echo "Unknown error while processing options inside buildDockerImage.sh"
26+
;;
27+
esac
28+
done
29+
30+
31+
DOCKER_SCRIPTS_HOME=$SCRIPTS_DIR/../
32+
33+
echo "Building image '$IMAGE_NAME' based on distribution '$DISTRIBUTION'..."
34+
35+
# GO INTO DISTRIBUTION FOLDER
36+
cd $DOCKER_SCRIPTS_HOME/$DISTRIBUTION
37+
38+
# Validate Java Package
39+
if [ ! -e $JAVA_PKG ]
40+
then
41+
echo "====================="
42+
echo "Download the Oracle JDK ${JAVA_VERSION} RPM for 64 bit and"
43+
echo "drop the file $JAVA_PKG in folder '$DISTRIBUTION' before"
44+
echo "building this image!"
45+
exit
46+
fi
47+
48+
49+
check_md5 $JAVA_PKG $JAVA_PKG_MD5
50+
if [ "$?" -ne 0 ]
51+
then
52+
echo "MD5 for $JAVA_PKG does not match! Download again!"
53+
exit
54+
fi
55+
56+
#
57+
# Validate WLS Package
58+
if [ ! -e $WLS_PKG ]
59+
then
60+
echo "====================="
61+
echo "Download the WebLogic 12c installer and"
62+
echo "drop the file $WLS_PKG in this folder before"
63+
echo "building this WLS Docker image!"
64+
exit
65+
fi
66+
67+
check_md5 $WLS_PKG $WLS_PKG_MD5
68+
if [ "$?" -ne 0 ]
69+
then
70+
echo "MD5 for $WLS_PKG does not match! Download again!"
71+
exit
72+
fi
73+
74+
echo "====================="
75+
76+
# BUILD THE IMAGE
77+
docker build --force-rm=true --no-cache=true --rm=true -t $IMAGE_NAME .
78+
79+
flatten_image() {
80+
if [ ! $FLATTEN_IMAGE ]
81+
then
82+
return 0
83+
fi
84+
echo "Flatten image flag found. Will flat this image..."
85+
docker tag $IMAGE_NAME ${IMAGE_NAME}-flatten
86+
CONTAINER=$(docker run -d ${IMAGE_NAME}-flatten echo)
87+
docker export $CONTAINER | docker import - $IMAGE_NAME
88+
docker rm -f $CONTAINER
89+
docker rmi -f ${IMAGE_NAME}-flatten
90+
}
91+
92+
if [ $? -eq 0 ]
93+
then
94+
flatten_image
95+
if [ $? -eq 0 ]
96+
then
97+
echo ""
98+
echo "WebLogic Docker Container is ready to be used. To start, run 'dockWebLogic.sh'"
99+
else
100+
echo ""
101+
echo "There was an error trying to flatten the image. Please try without the '-f' flag"
102+
fi
103+
else
104+
echo ""
105+
echo "WebLogic Docker Container was NOT successfully created. Check the output and correct any reported problems with the docker build operation."
106+
fi

OracleWebLogic/bin/dockNodeManager.sh

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/sh
2+
#
3+
# Usage:
4+
# $ sudo dockNodeManager.sh [-n <container name running admin server>]
5+
#
6+
# Since: October, 2014
7+
# Author: bruno.borges@oracle.com
8+
# 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
9+
#
10+
11+
SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
12+
. $SCRIPTS_DIR/setDockerEnv.sh $*
13+
14+
# CHECK FOR ARGUMENTS
15+
# -n [name] = the name of the admin server container which this NM will automatically plug to. Must exist. Defaults to 'wlsadmin'.
16+
while getopts "i:dhn:" optname
17+
do
18+
case "$optname" in
19+
"i")
20+
IMAGE_NAME="$OPTARG"
21+
;;
22+
"d")
23+
setup_developer
24+
;;
25+
"h")
26+
echo "Usage: dockNodeManager.sh [-i image] [-n wls_admin_container_name] [-d]"
27+
echo ""
28+
echo " -i image: name of your custom WebLogic Docker image. Default: $IMAGE_NAME."
29+
echo " -n name : name of the container with a WebLogic AdminServer orchestrating a domain."
30+
echo " Defaults to 'wlsadmin'"
31+
echo " -d : use the developer image to run the container"
32+
echo ""
33+
exit 0
34+
;;
35+
"n")
36+
ADMIN_CONTAINER_NAME="$OPTARG"
37+
;;
38+
*)
39+
exit 1
40+
;;
41+
esac
42+
done
43+
44+
# CHECK IF CONTAINER EXISTS AND IS RUNNING
45+
# Based on https://gist.github.com/ekristen/11254304 (MIT Licensed)
46+
echo -n "Inspecting image name of AdminServer '$ADMIN_CONTAINER_NAME'..."
47+
IMAGE_OF_ADMIN=$(docker inspect -f '{{.Config.Image}}' $ADMIN_CONTAINER_NAME 2> /dev/null)
48+
if [ "$IMAGE_OF_ADMIN" != "$IMAGE_NAME" ]; then
49+
echo ""
50+
echo "Admin container '$ADMIN_CONTAINER_NAME' is from a different image: '$IMAGE_OF_ADMIN', while you want to use image '$IMAGE_NAME'."
51+
exit $?
52+
fi
53+
54+
echo -n "Inspecting running state of AdminServer '$ADMIN_CONTAINER_NAME'..."
55+
ADMIN_CONTAINER_RUNNING=$(docker inspect --format="{{ .State.Running }}" $ADMIN_CONTAINER_NAME 2> /dev/null)
56+
57+
if [ $? -eq 1 ]; then
58+
echo ""
59+
echo "Admin container '$ADMIN_CONTAINER_NAME' with WLS Admin Server running does not exist. Create one first calling 'dockWebLogic.sh -n $ADMIN_CONTAINER_NAME'"
60+
exit $?
61+
fi
62+
63+
if [ "$ADMIN_CONTAINER_RUNNING" = "false" ]; then
64+
echo ""
65+
echo "Admin container '$ADMIN_CONTAINER_NAME' is not running. Unpause or start it"
66+
exit $?
67+
fi
68+
69+
echo "[OK]!"
70+
71+
echo -n "Inspecting ghost state of AdminServer..."
72+
GHOST_STATUS=$(docker inspect --format="{{ .State.Ghost }}" $ADMIN_CONTAINER_NAME)
73+
74+
if [ "$GHOST_STATUS" = "true" ]; then
75+
echo ""
76+
echo "Admin container '$ADMIN_CONTAINER_NAME' has been ghosted. Destroy it and create again."
77+
exit $?
78+
fi
79+
80+
if [ $? -eq 1 ]; then
81+
exit $?
82+
fi;
83+
84+
echo "[OK!]"
85+
86+
# RUN DOCKER
87+
echo -n "Creating NodeManager container..."
88+
docker run -d \
89+
--name ${NM_CONTAINER_NAME} \
90+
-e DOCKER_CONTAINER_NAME=${NM_CONTAINER_NAME} \
91+
--link $ADMIN_CONTAINER_NAME:wlsadmin $IMAGE_NAME \
92+
/u01/oracle/createMachine.sh > /dev/null 2>&1
93+
94+
echo "[OK!]"
95+
96+
if [ $? -eq 1 ]; then
97+
echo ""
98+
exit $?
99+
fi;
100+
101+
echo -n "Inspecting IP address of newly created NodeManger container with name '$NM_CONTAINER_NAME'..."
102+
NMIP=$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $NM_CONTAINER_NAME)
103+
echo "[OK!]"
104+
echo "===================="
105+
echo "New NodeManager [$NM_CONTAINER_NAME] started on IP Address: $NMIP."
106+
echo "Hopefully this Machine was automatically added to 'base_domain' in the [$ADMIN_CONTAINER_NAME] admin server."
107+
echo "If not, go to Admin Console and try to add it manually with this IP address."

OracleWebLogic/bin/dockWebLogic.sh

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/sh
2+
#
3+
# Usage:
4+
# -a [port]: attach AdminServer port to host. If -a is present, will attach. Defaults to 7001.
5+
# -n [name]: give a different name for the container. default: wlsadmin
6+
# -d : use the developer image to run the container
7+
# $ sudo sh dockWebLogic.sh -n [container name running admin server]
8+
#
9+
# Since: October, 2014
10+
# Author: bruno.borges@oracle.com
11+
# Description: script to create a container with WLS Admin Server
12+
# based on IMAGE_NAME within it.
13+
#
14+
15+
SCRIPTS_DIR="$( cd "$( dirname "$0" )" && pwd )"
16+
. $SCRIPTS_DIR/setDockerEnv.sh $*
17+
18+
# CHECK AND READ ARGUMENTS
19+
while getopts "ai:n:p:hd" optname
20+
do
21+
case "$optname" in
22+
"h")
23+
echo "Starts the WebLogic AdminServer within a Docker container."
24+
echo "Usage: dockWebLogic.sh [-i image] [-a [-p port]] [-n mywlsadmin] [-d]"
25+
echo ""
26+
echo " -a : attach AdminServer port to host. If -a is present, will attach. Change default (7001) with -p port"
27+
echo " -p port : which port on host to attach AdminServer. Default: 7001"
28+
echo " -i image: name of your custom WebLogic Docker image. Default: $IMAGE_NAME"
29+
echo " -n name : give a different name for the container. Default: wlsadmin"
30+
echo " -d : use the developer image to run the container"
31+
echo ""
32+
exit 0
33+
;;
34+
"a")
35+
MUST_ATTACH=true
36+
;;
37+
"p")
38+
ATTACH_ADMIN_TO="$OPTARG"
39+
;;
40+
"n")
41+
ADMIN_CONTAINER_NAME="$OPTARG"
42+
;;
43+
"i")
44+
IMAGE_NAME="$OPTARG"
45+
;;
46+
"d")
47+
setup_developer
48+
;;
49+
*)
50+
exit 1
51+
;;
52+
esac
53+
done
54+
55+
if [ $MUST_ATTACH ]; then
56+
ATTACH_DEFAULT_PORT="-p $ATTACH_ADMIN_TO:7001"
57+
fi
58+
59+
# RUN THE DOCKER COMMAND
60+
docker run \
61+
-d $ATTACH_DEFAULT_PORT \
62+
--name $ADMIN_CONTAINER_NAME $IMAGE_NAME \
63+
/u01/oracle/weblogic/user_projects/domains/base_domain/startWebLogic.sh
64+
65+
if [ $? -eq 1 ]; then
66+
exit $?
67+
fi;
68+
69+
# EXTRACT THE IP ADDRESS
70+
if [ -n "${ATTACH_DEFAULT_PORT}" ]
71+
then
72+
WLS_ADMIN_IP=localhost
73+
else
74+
WLS_ADMIN_IP=$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $ADMIN_CONTAINER_NAME)
75+
fi
76+
77+
# REPORT IF DOCKER SUCCEEDED
78+
if [ "$?" = 0 ]; then
79+
echo "WebLogic starting... "
80+
sleep 10
81+
echo "Open WebLogic Console at http://${WLS_ADMIN_IP}:${ATTACH_ADMIN_TO}/console"
82+
else
83+
echo "There was an error trying to create a container"
84+
exit $?
85+
fi

0 commit comments

Comments
 (0)