Skip to content

Latest commit

 

History

History
143 lines (89 loc) · 6.65 KB

README.md

File metadata and controls

143 lines (89 loc) · 6.65 KB

*For other versions of OpenShift, follow the instructions in the corresponding branch.

CI/CD Demo - OpenShift Container Platform 4.3

This repository includes the infrastructure and pipeline definition for continuous delivery using Jenkins, Nexus, SonarQube and CodeReady Workspaces/Eclipse Che (Optional) on OpenShift.

Introduction

On every pipeline execution, the code goes through the following steps:

  1. Code is cloned from Gogs, built, tested and analyzed for bugs and bad patterns
  2. The WAR artifact is pushed to Nexus Repository manager
  3. A container image (tasks:latest) is built based on the Tasks application WAR artifact deployed on WildFly
  4. The Tasks container image is deployed in a fresh new container in DEV project
  5. If tests successful, the pipeline is paused for the release manager to approve the release to STAGE
  6. If approved, the DEV image is tagged in the STAGE project.
  7. 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

Prerequisites

git config user.name "First Last"
git congig user.email "first.last@email.com"
  • Login into the openshift cluster

Deploy on OpenShift

When the demo is deployed, the following will be created:

  • a cicd project where Jenkins, Nexus, Gogs, and Sonarqube are deployed and running
  • a dev project representing the DEV environment
  • a stage project representing the STAGING environment

Each project is appended with the username. For e.g if user is user1, the cicd project will be created as cicd-user1.

Running the deployment

Please run the following command first to install all the templates locally.

./scripts/install-local-templates.sh --help
./scripts/install-local-templates.sh deploy

You can use the scripts/provision.sh script provided to deploy the entire demo

./scripts/provision.sh --help
./scripts/provision.sh deploy --private

To run this in a fully public environment, you can remove the --private option

To append the projects with a value other than the user, use the --project-suffix option

To delete everything

./scripts/provision.sh delete 
./scripts/install-local-templates.sh delete

Troubleshooting

  • 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.

  • If running into Permission denied issues on minishift or CDK, run the following to adjust minishift persistent volume permissions:

    minishift ssh
    chmod 777 -R /var/lib/minishift/
    

Demo Guide

  • Take note of these credentials and then follow the demo guide below:

    • Gogs: gogs/gogs
    • Nexus: admin/admin123
    • SonarQube: admin/admin
  • 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 @Ignore annotation from src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.java test 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.java and run it in the IDE.

  • Fix the test by modifying src/main/java/org/jboss/as/quickstarts/tasksrs/service/UserResource.java and 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

You can install CodeReady Workspaces on OpenShift 4 using the OperatorHub. Follow the Installing Che on OpenShift 4 from OperatorHub docs in order to install Eclipse Che 7. Alternatively, if you OpenShift cluster is accessible over the internet, you can use the hosted Eclipse Che service at https://che.openshift.io .

You can then follow these instructions to use Eclipse Che for editing code in the above demo flow.