Example 3 - WebApp Deployment
Overview
This example shows how BundleWorks can be used to deploy a custom Java web application into multiple environments running the Tomcat servlet container. The next example shows how this same custom web application can be built and bundled using ant and BundleWorks.
In this example, there are two environments, staging and test. Each environment contains both the JDK and Tomcat deployed bundles. The JDK bundle is a loadable bundle, while the Tomcat bundle is an executable bundle. Both the staging and test environments have separate Tomcat instances, each with their own work directories but sharing the same Tomcat bundle in /opt/bundles.
In this example, the staging environment contains a more stable version (1.0) of the custom web application, helloweb. The test environment contains the latest development version of helloweb (2.0rc1). The helloweb bundle contains scripts for installing, upgrading, and rolling back the application. These scripts use a BundleWorks feature called broadcasting. This allows a bundle to broadcast a message to other bundles within an environment. In this case, the webhello bundle broadcasts wardeploy and warundeploy messages, which the Tomcat bundle handles by updating its webapp directory.
Bundles
- Tomcat 5.5.25 - Apache Tomcat servlet container
- JDK 1.5.0_13 - Java5 development kit
- helloweb 1.0 and 2.0rc1 - Custom Java web application
Environments
- staging - contains Tomcat, JDK and a stable version of helloweb (1.0)
- test - contains Tomcat, JDK, and a development version of helloweb (2.0rc1)
Details
/opt/bundles
helloweb/
1.0/ [1]
bundle/
actions/ [2]
install.sh
rollback.sh
uninstall.sh
upgrade.sh
config/
hello.properties [3]
info [4]
shared/
war
helloweb.war [5]
2.0rc1/
bundle/
actions/ [6]
install.sh
rollback.sh
uninstall.sh
upgrade.sh
config/
hello.properties [7]
info
shared/
war
helloweb.war
jdk/
1.5.0_13/ [8]
bundle/
actions/
load.sh
unload.sh
info
tomcat/
5.5.25/ [9]
bundle/
actions/ [10]
common.sh [11]
install.sh
kill.sh
setup.sh
start.sh
status.sh
stop.sh
wardeploy.sh [12]
warundeploy.sh
info
shared/ [13]
bin/, common/, conf/, ...
/var/env/
staging/ [14]
env/
info
helloweb/
bundle [15]
work/
config/
hello.properties [16]
logs/
tomcat/
bundle
work/ [17]
conf/
logs/
shared/
temp/
tomcat.err
tomcat.out
tomcat.pid
webapps/
webhello/ [18]
work/
uses/
jdk [19]
test/
env/
info
helloweb/
bundle [20]
work/
config/
hello.properties [21]
logs/
tomcat/
bundle
work/
conf/
logs/
shared/
temp/
tomcat.err
tomcat.out
tomcat.pid
webapps/
webhello/
work/
uses/
jdk
- This is version 1.0 of the helloweb bundle. This bundle and the later 2.0rc1 version were built using the BundleWorks java-webapp bundler which builds deployable bundles from war files.
- The actions directory inside the helloweb bundle contain the various scripts need to deploy this application. These scripts, or hooks, are called in response to various BundleWorks commands like deploy and undeploy. For example, the install.sh script is called when a bundle is deployed into an environment for the first time. The upgrade.sh script is called if deploying to an environment with an older version, while the rollback.sh script is called if deploying to an environment with a newer version. Finally, the uninstall.sh script is called in respsonse to the BundleWorks undeploy command.
- The hello.properties file here is a template configuration file. It contains the token @{HELLO_MESSAGE}, which will be replaced with a value entered by the user during installation. This is done in the install.sh script using the built-in BundleWorks functions prompt_for_string and replace_vars.
-
The info file inside the helloweb bundle contains information about when the bundle was built. It also contains the following line which indicates where its configuration is kept:
Runtime-Config: config/*.properties
This line helps BundleWorks track changes to configuration within any helloweb deployment. BundleWorks stores a complete history of all configuration changes and provides various commands for accessing this history.
- The helloweb.war file is a standard Java war file. This web application takes advantage of the configuration versioning feature of BundleWorks by storing its configuration outside the war file, but otherwise it is a standard Java web application. The next example shows how this war file is built and bundled using ant and the BundleWorks ant tasks.
- This actions directory contains the scripts needed to deploy the 2.0 version of the helloweb application. These scripts need to handle the extra property added to the hello.properties file. They use the built-in BundleWork functions add_property and remove_property to handle this extra property during upgrade and rollback.
- The hello.properties file inside the helloweb 2.0rc1 bundle contains an extra property from the 1.0 version. The bundle scripts handle this extra property correctly whether this bundle is being installed for the first time or being upgraded from a previous version.
- This is version 1.5.0_13 of the Java Development Kit bundled using the BundleWorks jdk bundler. See the first example for details about this bundle.
- This Tomcat bundle was built using the BundleWorks tomcat bundler and the 5.5.25 distribution of Tomcat from Apache.
- The actions directory of the Tomcat 5.5.25 bundle contains the scripts needed to set up and manage an instance of Tomcat within an environment. BundleWorks automatically generates these scripts.
- This common script is shared by a number of the Tomcat bundle scripts. It sets two environment variables: CATALINA_HOME and CATALINA_BASE, taking advantage of Tomcat's ability to have multiple "base" directories which share the same "home" directory. The CATALINA_HOME variable is set to $BUNDLE_HOME/shared to point to the Tomcat distribution inside the bundle. The CATALINA_BASE variable is set to $WORK_DIR, which is the work directory of a Tomcat deployment.
- The wardeploy script and the warundeploy script define Tomcat's response to the messages broadcast by web applications during deployment. In this case, Tomcat responds by updating its webapp and work directories as needed.
- This shared directory contains the entire 5.5.25 distribution of Tomcat from Apache. No modifications to the distribution are necessary to use Tomcat with BundleWorks.
- The staging environment was created using the BundleWorks envcreate command. The helloweb, jdk, and tomcat bundles were deployed to this environment using the BundleWorks deploy command.
- This bundle reference inside the helloweb deployment within the 'staging' environment points to version 1.0 of the application (/opt/bundles/helloweb/1.0). When the application is upgraded, this reference is changed to point to the new bundle.
- This hello.properties is the result of deploying the helloweb bundle to the staging environment. This file contains the single property needed by the 1.0 version of helloweb.
- This work directory inside the tomcat deployment within the staging environment defines a separate instance of Tomcat. This directory is created and populated when the tomcat bundle is installed into an environment. It contains all of the runtime files needed by Tomcat as well as files created by BundleWorks to capture the standard out, standard error, and process id of the launched Tomcat.
- This Tomcat webapp directory contains the exploded war file from the helloweb 1.0 bundle. In the 'test' environment, the webapp directory contains the exploded war file from the helloweb 2.0rc1 bundle.
- This jdk file is a reference to the jdk 1.5.0_13 bundle inside /opt/bundles. It determines which version of Java is used by this environment.
- This bundle reference inside the helloweb deployment within the 'test' environment points to version 2.0rc1 of the application (/opt/bundles/helloweb/2.0rc1).
- This hello.properties is the result of upgrading the helloweb bundle in the test environment from 1.0 to 2.0rc1. This file contains the extra property needed by the 2.0 version of helloweb.