/CICD-in-RedHat-OpenShift

Continuous Integration & Delivery in RedHat OpenShift

Primary LanguageEJSMIT LicenseMIT

archi

Red Hat® OpenShift® is an enterprise-ready Kubernetes container platform with full-stack automated operations to manage hybrid cloud and multicloud deployments. Red Hat OpenShift is optimized to improve developer productivity and promote innovation

CI/CD is one of the popular use-cases for OpenShift Container Platform. OpenShift scales the pipeline execution through on-demand provisioning in containers. OpenShift provides an end-to-end solution for building complete deployment pipelines and removes the wait time for running builds in large projects

Steps

  1. Important Terminologies
  2. Understand CICD Workflow in RedHat OpenShift
  3. Fork the GitHub repository
  4. Get RedHat OpenShift CodeLab
  5. Deploy an application using S2I Method
  6. Update some code to check continuous Integration and Delivery

Step 1. Important Terminologies

Source-to-Image: Developers do not need to be experts in Dockerfiles or either operating system commands. S2I is responsible to create resources for developers, we only need to pass our central repository URL.

Build Config: The build config is responsible to fetch the code from central repo and build an image in OpenShift and push them in the internal Docker registry.

Deploy Config: Once the image is successfully built then deploy config is responsible for deploying the application in pods into OpenShift.

Step 2. Understand CICD Workflow in RedHat OpenShift

workflow

  1. First, when we pass oc new-app it will create a Build Configuration.
  2. It will create a Builder pod that clones the application from the central repo.
  3. Once the source code successfully cloned it will create an image
  4. Builder pod pushes the image to the external and internal registry.
  5. Check if the image is created from the available images in OpenShift or need to create a fresh image layer.
  6. S2I image stream will check if there are any changes in the image.
  7. The change will be notified to Build Config
  8. Once the complete process of Build is done then comes the responsibility of Deployment Configuration to create the pods in OpenShift depending on the image specifications.

Step 3. Fork the GitHub repository

  1. Create IBM Account (optional)
  2. Open this repo
  3. And then click on Fork on the top right.

fork

NOTE : This is a important step because in lab you will provide your fork repo or else change in the code will not trigger.

Step 4. Get RedHat OpenShift CodeLab

  1. Get a free lab from here
  2. Click on Access the OpenShift Lab and you will be redirected to the lab page (wait it will take some time to provision the lab resources)
  3. Once it is done you can see the below page.

lab

Step 5. Deploy an application using S2I Method

  1. Click on Terminal on top.
  2. Run command oc status to check cluster is provisioned successfully, the current project as sn-labs-mahsankhan .(in your case it will be different)
  3. Run command oc new-app --name=bankapplication https://github.com/mahsankhaan/CICD-in-RedHat-OpenShift.git to deploy the application (Please note GitHub URL will be your fork URL done in Step 3)
  4. Build will start and you can see the logs by oc logs -f bc/bankapplication
  5. Run command oc get pods -w and can verify build and deploy stages are successfully complete and one pod is running bankapplication-1-n6ddx (in your case it will be different)
  6. Pass command oc expose svc/bankapplication to expose the application to the world.
  7. Now get the route of the application oc get routes. Open the host (bankapplication-sn-labs-mahsankhan.labs-user-sandbox-...) in the browser and check bank application is up and running.

admin

Step 6. Update some code to check continuous Integration and Delivery

  1. Open the repo (in your case kindly open your Fork repo) this is important because you can't make a change in this repo directly.
  2. Open Folder views -> admin_login.ejs (Open File at line 141 make it WELCOME ADMIN LOGIN), Click commit changes.
  3. Now again open the terminal and pass command oc start-build bankapplication now complete workflow will take place as discussed in Step 2 .
  4. Again run the command oc get pods and now can check a new build-2 is running. A newly updated pod would be created bankapplication-2-vb8rg and the previous one would be deleted.
  5. Open the same URL again and can verify the update.