BCDevOps / ocp-cd-pipeline

Apache License 2.0
4 stars 5 forks source link

ocp-cd-pipeline

This is a groovy library/utility (provided as jar file) for helping orchestrating the creation of OpenShift objects required for building and deploying applications.

Motivation

The OpenShift Web Console is a very powerful UI, however it leads to undocumented and manual (click, click) configurations.

The oc command-line interface is a great alternative to the UI that allows scripted manipulation of OpenShift Objects.

Developers are encouraged to create templates and use the template to create/update objects by using the oc command-line. However, we have observed that those templates are not kept up-to-date, and it is not consistently and continuously tested.

In the spirit of Infrastructue as Code, and Continuous Delivery Practices, we wanted to (1) test the template as often and as thoroughly as possible, (2) be able to spin up a new environment as quickly and easily as possible, and (3) doing so consistently as part of a deployment pipeline.

Bye Jenkins Shared Library

Out first attempt to create this library was through using Jenkins Shared Libraries. However, we have encountered a few challenges:

Hello ocp-cd-pieline library

The first question one might have is "Why Groovy/Java?", for a very simple reason that we started as a Jenkins Shared Library and we started by re-using a big chunk of code from that.

How does it works?

This Library/utility is designed to rely on OpenShift templates as input and orchestrate the processing and manipulation (Create, Update) of objects as well as applying some lessons learned, best practices, and deal with some quirks related to how templates are processed by oc command-line or OpenShift.

Features

Runtime Requirements

How to use it

Example/Starter Groovy scripts are provided in src/main/groovy/example folder

Create a config file using Groovy ConfigSlurper syntax.

Important: Make sure the current directory is the git top level directory of the config file

Build

# MY_APP_DIR
# OCP_CD_PIPELINE_DIR

cd $MY_APP_DIR
groovy -cp target/ocp-pipeline-0.0.4.jar  'jar:file:target/ocp-pipeline-0.0.4.jar!/example/build.groovy'

groovy -cp $OCP_CD_PIPELINE_DIR/src/main/groovy/ $OCP_CD_PIPELINE_DIR/src/main/groovy/example/build.groovy --config=openshift/config.groovy

Build

Prerequisites

# create setting.xml
mvn -c settings.xml deploy