OpenShift can be a useful aide in creating a Continuous Integration (CI) / Continuous Delivery (CD) pipeline. CI/CD is all about creating a streamlined process to move from a developer's code change to delivered operations-ready software (i.e. ready to deploy to production). And a key part of CI/CD is the automation to make the process predicatable, repeatable, and easy.
This git repo contains an intentionally simple example of a software pipeline to deploy a webapp. And it showcases the tight intergration between Jenkins and OpenShift. Namely the multiple plugins that enable shared auth, preform synchronization between Jenkins and OpenShift, and allow for steps to be written in a readable and comprehensive syntax.
When you kickoff this example, the flow is as follows: perform pre-build -> do an app source code build + containerization -> do some automated testing -> deploy the app to the dev environment -> tag an image so that external image stream triggers can pull the image into a staging environment.
Here's what it looks like:
The most obvious benefits of CI/CD pipelines are:
First off, you need access to an OpenShift cluster. Don't have an OpenShift cluster? That's OK, download the CDK for free here: https://developers.redhat.com/products/cdk/overview/
Once you have been able to login into your cluster, clone this git repo locally and cd
into the folder. There is a script you can use for creating all the projects and required components for this example.
pipeline_setup.sh
Because no other Jenkins server is already configured for use, OpenShift will actually create one for you. And before starting the pipeline, wait until that jenkins server is ready. You can see status in the webconsole or with oc get pods
.
But we need to do one more thing because of a current limitation with the sync plugin. We have to give Jenkins a list of OpenShift namespaces to stay in sync with.
Open the Jenkins webconsole
Goto: Manage Jenkins -> Configure System -> OpenShift Jenkins Sync -> Namespace
Add 'pipeline-app pipeline-app-staging' to the list"
OK, now we can kick off a new pipeline build via the the web console or with the CLI:
oc start-build -F openshiftexamples-cicdpipeline
It will create the app in our pipeline-app project. And once that succeeds and rollsout it will prompt us for input to determine if everything looks good to move to staging. Yes = rollout to staging, No = fail the pipeline.
The parts in action here are:
The Jenkins integration can come in a varitey of different flavors. See below for some disucssion on things to consider when doing this for your projects.
Let me know in the github issues if you'd be interested in another example of advanced pipelines covering topics below. And feel free to comment or suggest something else.
Under the terms of the MIT.