*For other versions of OpenShift, follow the instructions in the corresponding branch e.g. ocp-3.9, ocp-3.7, etc
CI/CD Demo - OpenShift Container Platform 3.9
This repository includes the infrastructure and pipeline definition for continuous delivery using Jenkins, Nexus, SonarQube and Eclipse Che on OpenShift.
- Deploy on RHPDS
- Automated Deploy on OpenShift
- Manual Deploy on OpenShift
- Demo Guide
- Using Eclipse Che for Editing Code
On every pipeline execution, the code goes through the following steps:
- Code is cloned from Gogs, built, tested and analyzed for bugs and bad patterns
- The WAR artifact is pushed to Nexus Repository manager
- A container image (tasks:latest) is built based on the Tasks application WAR artifact deployed on JBoss EAP 6
- The Tasks container image is deployed in a fresh new container in DEV project
- If tests successful, the DEV image is tagged with the application version (tasks:7.x) in the STAGE project
- The staged image is deployed in a fresh new container in the STAGE project
The following diagram shows the steps included in the deployment pipeline:
The application used in this pipeline is a JAX-RS application which is available on GitHub and is imported into Gogs during the setup process: https://github.com/OpenShiftDemos/openshift-tasks
- 10+ GB memory
- JBoss EAP 7 imagestreams imported to OpenShift (see Troubleshooting section for details)
Deploy on RHPDS
If you have access to RHPDS, provisioning of this demo is automated via the service catalog under OpenShift Demos → OpenShift CI/CD for Monolith. If you don't know what RHPDS is, read the instructions in the next section.
Automated Deploy on OpenShift
You can se the
scripts/provision.sh script provided to deploy the entire demo:
./provision.sh --help ./provision.sh deploy --deploy-che --ephemeral ./provision.sh delete
Manual Deploy on OpenShift
Follow these instructions in order to create a local OpenShift cluster. Otherwise using your current OpenShift cluster, create the following projects for CI/CD components, Dev and Stage environments:
# Create Projects oc new-project dev --display-name="Tasks - Dev" oc new-project stage --display-name="Tasks - Stage" oc new-project cicd --display-name="CI/CD" # Grant Jenkins Access to Projects oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n dev oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n stage
And then deploy the demo:
# Deploy Demo oc new-app -n cicd -f cicd-template.yaml # Deploy Demo with Eclipse Che oc new-app -n cicd -f cicd-template.yaml --param=WITH_CHE=true
To use custom project names, change
stage in the above commands to
your own names and use the following to create the demo:
oc new-app -n cicd -f cicd-template.yaml --param DEV_PROJECT=dev-project-name --param STAGE_PROJECT=stage-project-name
If pipeline execution fails with
error: no match for "jboss-eap70-openshift", import the jboss imagestreams in OpenShift.
oc create -f https://raw.githubusercontent.com/jboss-openshift/application-templates/ose-v1.4.14/eap/eap70-image-stream.json -n openshift
If Maven fails with
/opt/rh/rh-maven33/root/usr/bin/mvn: line 9: 298 Killed(e.g. during static analysis), you are running out of memory and need more memory for OpenShift.
Take note of these credentials and then follow the demo guide below:
A Jenkins pipeline is pre-configured which clones Tasks application source code from Gogs (running on OpenShift), builds, deploys and promotes the result through the deployment pipeline. In the CI/CD project, click on Builds and then Pipelines to see the list of defined pipelines.
Click on tasks-pipeline and Configuration and explore the pipeline definition.
You can also explore the pipeline job in Jenkins by clicking on the Jenkins route url, logging in with the OpenShift credentials and clicking on tasks-pipeline and Configure.
Run an instance of the pipeline by starting the tasks-pipeline in OpenShift or Jenkins.
During pipeline execution, verify a new Jenkins slave pod is created within CI/CD project to execute the pipeline.
Pipelines pauses at Deploy STAGE for approval in order to promote the build to the STAGE environment. Click on this step on the pipeline and then Promote.
After pipeline completion, demonstrate the following:
- Explore the snapshots repository in Nexus and verify openshift-tasks is pushed to the repository
- Explore SonarQube and show the metrics, stats, code coverage, etc
- Explore Tasks - Dev project in OpenShift console and verify the application is deployed in the DEV environment
- Explore Tasks - Stage project in OpenShift console and verify the application is deployed in the STAGE environment
Clone and checkout the eap-7 branch of the openshift-tasks git repository and using an IDE (e.g. JBoss Developer Studio), remove the
src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.javatest methods to enable the unit tests. Commit and push to the git repo.
Check out Jenkins, a pipeline instance is created and is being executed. The pipeline will fail during unit tests due to the enabled unit test.
Check out the failed unit and test
src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.javaand run it in the IDE.
Fix the test by modifying
src/main/java/org/jboss/as/quickstarts/tasksrs/service/UserResource.javaand uncommenting the sort function in getUsers method.
Run the unit test in the IDE. The unit test runs green.
Commit and push the fix to the git repository and verify a pipeline instance is created in Jenkins and executes successfully.
Using Eclipse Che for Editing Code
If you deploy the demo template using
WITH_CHE=true paramter, or the deploy script and use
--deploy-che flag, then an Eclipse Che instances will be deployed within the CI/CD project which allows you to use the Eclipse Che web-based IDE for editing code in this demo.
Here is a step-by-step guide for editing and pushing the code to the Gogs repository (step 6) using Eclipse Che.
Click on Eclipse Che route url in the CI/CD project which takes you to the workspace administration page. Select the Java stack and click on the Create button to create a workspace for yourself.
Once the workspace is created, click on Open button to open your workspace in the Eclipse Che in the browser.
It might take a little while before your workspace is set up and ready to be used in your browser. Once it's ready, click on Import Project... in order to import the
openshift-tasks Gogs repository into your workspace.
Enter the Gogs repository HTTPS url for
openshift-tasks as the Git repository url with Git username and password in the
You can find the repository url in Gogs web console. Make sure the check the Branch field and enter
eap-7 in order to clone the
eap-7 branch which is used in this demo. Click on Import
Change the project configuration to Maven and then click Save
Configure you name and email to be stamped on your Git commity by going to Profile > Preferences > Git > Committer.
Follow the steps 6-10 in the above guide to edit the code in your workspace.
In order to run the unit tests within Eclipse Che, wait till all dependencies resolve first. To make sure they are resolved, run a Maven build using the commands palette icon or by clicking on Run > Commands Palette > build.
Make sure you run the build again, after fixing the bug in the service class.
Run the unit tests in the IDE after you have corrected the issue by right clicking on the unit test class and then Run Test > Run JUnit Test
Click on Git > Commit to commit the changes to the
openshift-tasks git repository. Make sure Push commited changes to ... is checked. Click on Commit button.
As soon the changes are committed to the git repository, a new instances of pipeline gets triggers to test and deploy the code changes.