This repository contains the source code and step-by-step instructions needed to reproduce the Continuous Delivery with Docker Containers & Java EE webinar.
This demo sets up a complete Continuous Delivery environment using Docker containers.
This demo uses Docker Compose as a simple orchestration tool. Docker is used for simplicity in this demo and is not essential to the delivery pipeline.
More details discused in Markus' Blog.
This demo uses various components to create a delivery pipeline. Jenkins, Nexus and Sonar run in their own Docker containers while GitHub is used as an external Git-based source repository.
-
Jenkins
Description: continuous delivery orchestration engine
Address: http://DOCKER_HOST:8080/jenkins
-
Sonatype Nexus
Description: artifact repository for archiving release binaries
Address: http://DOCKER_HOST:8081/nexus
-
SonarQube
Description: static code analysis engine extracting various quality metrics from the code
Address: http://DOCKER_HOST:9000
-
GitHub
Description: source repository hosting the ticket-monster Java application
Note
|
If running boot2docker on Mac OSX, DOCKER_HOST is the ip of boot2docker virtual machine |
The delivery pipeline in this demo is divided into five phases each containing a number of activities (jobs) that need to succeed in order to promote the artifact to the next phase. Each change in the application is a potential production release according to Continuous Delivery principles and can go in production if it successfully passes through all the phases in the pipeline.
-
Build: compilation and unit test, integration tests and static code analysis
-
Dev: release to Nexus, create release tag in Git, deploy to DEV server and run functional tests
-
System Test: deploy to System Test server and run system tests
-
Perf Test: deploy to Performance Test server and run performance tests
-
Pre Production (Stage): deploy to Pre-Production server
Continuous Delivery from dev → prod in a Docker environment will be demonstrated in this exercise using the Ticket Monster JEE application.
The Ticket Monster JEE project is a moderately complex application that demonstrates how to build modern applications using JBoss web technologies.
-
Network Bandwidth
During this lab exercise, Docker images will be pulled from the internet. You’ll want a high-speed broadband connection and open access to the internet.
-
Hardware
To execute this lab exercise, three machines will be needed. Each machine should consist of a minimum of 2 cores and 4G RAM. The machines can run locally or as VMs in a cloud environment.
-
Red Hat Network Subscription
You must have a valid _Red Hat Network (RHN) subscription with entitlements that allow for:
-
management of rhel-server-7 operating systems.
-
download of supported Red Hat JBoss middleware software.
-
-
Operating System
Currently, the host operating system required to build the docker images provided in this project needs to be Red Hat Enterprise Linux (RHEL) 7. The RHEL7 hosts should be registered with the Red Hat Network (RHN) via subscription-manager.
In the near future, Red Hat will be providing a RHEL CDK (Container Development Kit). The RHEL CDK will allow for building of images in this project on host operating systems such as Fedora, OSX and Windows.
-
github account
A
github
account will be needed to fork the originalticket-monster
source code -
git
Ensure that
git
is installed on the operating system of all machines. -
Docker
Ensure that
docker
is installed and running on the operating system of all machines -
docker-compose
is a handy utility for defining and running complex applications with Docker. It is not a feature complete paas. However, it does a nice job of facilitating the use of multiple Docker containers in thisContinuous Delivery
exercise.
This lab requires the following 3 machines as per the specifications listed in the Pre-requisites section:
-
dev
-
systest
-
prod
These hosts may be either virtual machines or bare-metal. They should be on a network that allows TCP assessibility between them.
This project needs to be cloned on all machines (dev
, systest
and prod
) used in this project.
git clone https://github.com/jbossdemocentral/continuous-delivery-javaee-container-src.git
Doing so creates a directory on your local workstation called: continuous-delivery-javaee-container-src.
Note
|
For the remainder of these instructions, the directory created from having cloned this project will be referred to as: $PROJECT_HOME. |
In this demo, SSH keys are used for the following purposes:
-
Authentication to Github
This lab makes use of the Maven Release Plugin. One of the operations attempted by the Maven Release Plugin will be to push changes to your project repository in Github. SSH kays will be shared between the Maven Release Plugin and your Github account to allow maven to push these commits.
-
ssh connections to
systest
andprod
hostsThis lab makes use of Jenkins jobs that push releases from your Jenkins container to your
systest
andprod
host machines. SSH key pair authentication is used to allow for creation ofssh / scp
connections between lab environments.
In this step, an ssh key pair will be created in your dev
machine.
-
cd $PROJECT_HOME/demo
-
execute:
ssh-keygen -q -f images/jenkins-ci/config/.ssh/id_rsa -t rsa -N ''
The key pair will be created (with no passphrase) in the directory:
$PROJECT_HOME/demo/images/jenkins-ci/config/.ssh
To allow for authentication between the Maven Release Plugin
and Github, execute the following:
-
Authenticate into Github
-
Navigate to Github account settings
-
Click
SSH Keys → Add SSH Key
-
Copy and paste the contents of your previously created public key to the
key
text-box in Github.Your public key should be located at:
PROJECT_HOME/demo/images/jenkins-ci/config/.ssh/id_rsa.pub
. -
Click the
AddKey
button
Continouos Delivery from dev → prod is demonstrated using the Ticket Monster JEE application.
During the release
stage, the release version of the ticket-monster
project is updated (ie: 2.6.49-SNAPSHOT → 2.6.49.Final).
This change is version controlled.
Subsequently, a git repository of the ticket-monster
application is needed to push these release changes to.
The source to the ticket-monster
application can be found in Red Hat’s jbossdemocentral.
This git repository is public (any git client can clone the project) however direct commit access to this repository is controlled.
You’ll want to utilize a version of the ticket-monster
application that you can modify.
You’ll want to fork the ticket-monster
project using your own github account:
-
In your browser, navigate to:
https://github.com/jbossdemocentral/continuous-delivery-demo-app
-
Authenticate into gitub.
-
On the far right, click
Fork
-
After a few seconds, a fork of the
ticket-monster
app will appear in your own github account. -
Make note of the clone URL to your forked repository. You’ll make use of this URL through this exercise.
The pom.xml of the `ticket-monster
project includes references to the original git repository in jbossdemocentral
.
These references should be changed.
-
Clone the forked
ticket-monster
project to your local workstation. -
Using your favorite text editor, edit the following section of:
continuous-delivery-demo-app/pom.xml
:In particular, change all of the URLs in the
scm
section such that they reference your forked repository. -
Commit and push the change to your forked git repository.
Docker images from this project need to be built prior to the creation of docker containers.
Docker-compose is used to build the Docker images included in this project.
-
cd $PROJECT_HOME/demo
-
add jboss-eap-6.4
-
Use your RHN userId to access the Red Hat Support Portal.
-
Download jboss-eap-6.4.0.zip
-
Copy jboss-eap-6.4.0.zip to the following directory on the host machine:
$PROJECT_HOME/demo/images/appserverbase/resources
-
-
Build the project’s base image.
One limitation of docker_compose is that it’s not smart enough to build images in the order specified in the project’s docker-compose yaml config. Instead, docker-compose attempts to build images in alphabetic order. This becomes a problem when building the images defined in
$PROJECT_HOME/demo/baseimages.yml
.This docker-compose limitation can be overcome by explicitly specifying the order in which to build the project’s images.
execute:
docker-compose -f baseimages.yml build base
NoteDepending on network bandwidth, expect this step to take a few minutes while the RHEL7 base docker image is downloaded and updated. -
Build all other images specified in the project’s
baseimages.yml
config file.execute:
docker-compose -f baseimages.yml build
NoteExpect this step to take longer than the previous. Several products (such as Jenkins) are downloaded. -
Execute:
docker images
This command should provide a listing of all of the images that have been built thus far. The output should appear similar to the following:
-
cd $PROJECT_HOME/demo
-
docker run -d --name="demo_storage" demo_storage
-
docker-compose -f dev-env.yml up -d
NoteDepending on network bandwidth, expect this step to take a while as well as the Sonar and Nexus images are downloaded. -
docker-compose -f dev.yml up -d
This step starts a container that includes the
Ticket Monster
application. -
docker ps -a
Make note of the newly instantiated docker containers and their port mappings.
Your dev-env machine should now have the following running Docker containers:
-
demo_jenkins_1
Accessible via your browser at the following URL:
http://<address_of_dev_machine>:9080/jenkins
-
demo_nexus_1
Accessible via your browser at the following URL:
http://<address_of_dev_machine>:8081/nexus
-
demo_sonar_1
Accessible via your browser at the following URL:
http://<address_of_dev_machine>:9000
Several of the Jenkins jobs that come pre-configured in the jenkins-demo-1
container reference URL to the ticket-monster
application in github/jbossdemocentral
.
All of these jenkins jobs should instead reference the URL of your forked ticket-monster
app previously created in the section: Fork ticket-monster
project.
Of particular importance is the Jenkins job: ticket-monster-release
.
The ticket-monster-release
job is responsible for creating a release of the latest ticket-monster
application.
The ticket-monster-release
job updates the version
in the pom.xml of the application and pushes this change back to the ticket-monster
git repository.
Subsequently, your Jenkins jobs will need commit access to a ticket-monster
git repository.
Using the clone URL of your forked ticket-monster
project, modify the Jenkins jobs as follows:
-
In your browser, navigate to the jenkins dashboard.
-
Click the
ticket-monster-analysis link
-
On the left panel, click
Configure
-
Scroll down to the
Source Code Management
section -
Git
should already be selected as the repository type. -
Replace the value of the
Repository URL
with the URL of your forkedticket-monster
repository in github. -
Under the
Credentials
text box, click theAdd
button -
In the
Add Credentials
pop-up, populate with your preferred mechanism to authenticate into gihub (ie: username/password or ssh keys) -
Scroll to the bottom and click
Save
Repeat the above procedure for the following additional Jenkins jobs:
-
ticket-monster-build
-
ticket-monster-release
-
ticket-monster-test-int
The systest
environment consists of a single Docker container running JBoss EAP 6.4.
This infrastructure will be used as the test environment.
Execute the following steps in your systest
machine.
-
cd $PROJECT_HOME/demo
-
docker-compose -f systest.yml up -d
-
docker ps -a
Your systest machine should now have one running Docker container: demo_systest_1
This container is accessible via your browser at the following interfaces:
The production environment used in this project is identical to systest
.
On the production machine, start its containers in the same manner as was done previously in the systest
machine with one change:
execute docker-compose -f prod.yml up -d
After all images are built and containers started on all enviornments (dev, systest and prod), continuous delivery of a JEE application in a Docker environment can be demonstrated.
The Jenkins Delivery Pipeline
can be manually started via the Jenkins Dashboard.
At the far right of the dashboard, click the green start button corresponding to the ticket-monster-release
job.