Code Monkey home page Code Monkey logo

openshift-cd-demo's Introduction

OpenShift 3 CI/CD Demo

This repository includes the infrastructure and pipeline definition for continuous delivery using Jenkins, Nexus and SonarQube on OpenShift. On every pipeline execution, the code goes through the following steps:

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

Setup

Create a new project for CI/CD components

$ oc new-project cicd --display-name="CI/CD"

Create the CI/CD compoentns based on the provided template

$ oc process -f cicd-gogs-template.yaml | oc create -f -

Create Dev and Stage projects for Tasks JAX-RS application

$ oc new-project dev --display-name="Tasks - Dev"
$ oc new-project stage --display-name="Tasks - Stage"

Jenkins needs to access OpenShift API to discover slave images as well accessing container images. Grant Jenkins service account enough privileges to invoke OpenShift API for the created projects:

$ oc policy add-role-to-user edit system:serviceaccount:cicd:default -n cicd
$ oc policy add-role-to-user edit system:serviceaccount:cicd:default -n dev
$ oc policy add-role-to-user edit system:serviceaccount:cicd:default -n stage

Demo Guide

  1. RunJenkins has the Pipeline plugin pre-installed. A Jenkins pipeline job is also pre-configured which clones Tasks JAX-RS application source code from GitHub, builds, deploys and promotes the result through the deployment pipeline. Click on tasks-cd-pipeline and Configure and explore the pipeline definition.

  2. If using Gogs, modify the git repository url in the pipeline definition and set it to http://gogs:3000/gogs/openshift-tasks.git.

  3. Run an instance of the pipeline by starting the tasks-cd-pipeline job.

  4. During pipeline execution, verify a new Jenkins slave pod is created withing CI/CD project to execute the pipeline.

  5. After pipeline completion, demonstrate the following:

  • Explore the snapshots repository in Nexus and verify openshift-tasks is pushed to the repository
  • Explore SonarQube and verify a project is created with 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
  1. Add a webhook in GitHub or Gogs to trigger the pipeline whenever a change is pushed to the git repository. Use pipeline job's Build Now url as the webhook url.

If using Gogs, webhooks configuration is in repository's Settings > Webhooks and the tasks-cd-pipeline webhook url is http://jenkins:8080/job/tasks-cd-pipeline/build?delay=0sec.

Note: if GitHub is used and Jenkins route is not accessible from the Internet, use SCM Polling instead of webhooks to trigger builds.

  1. Clone 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.

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

  3. Check out the failed unit and test src/test/java/org/jboss/as/quickstarts/tasksrs/service/UserResourceTest.java and run it in the IDE.

  4. Fix the test by modifying src/main/java/org/jboss/as/quickstarts/tasksrs/service/UserResource.java and uncommenting the sort function in getUsers method.

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

openshift-cd-demo's People

Contributors

siamaksade avatar thoraxe avatar tqvarnst avatar

Watchers

James Cloos avatar sree avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.