Cloud Architecture / DevOps / OpenShift / PaaS

Webhooks with OpenShift

Introduction

If you already have a third party CI/CD git-compliant pipeline established, you can easily integrate this with OpenShift using webhooks. This enables a clear north/south divide between build and deployment layers, if you so wish. Here’s Neo. This lab is another in the OpenShift MiniLabs series.

neo

Objectives

This post demonstrates the webhook technique by configuring an external git server to trigger a build event in OpenShift using webhooks. We can simulate this all on a single local workstation by concurrently running a local git service and OpenShift instance. A local tunnel is established to make the git location appear remote to the OpenShift pods/containers.

screen-shot-2016-10-13-at-10-24-48-pm

Setup

Initial Attempt

This tutorial assumes you have completed the OpenShift MiniLabs installation procedure. Then refresh before continuing.

Instructions

Go Git Service

Set up a local gogs instance using postgresql on your workstation by installing the following components. Note that we can run gogs within OpenShift (https://github.com/OpenShiftDemos/gogs-openshift-docker ) but this use case deliberately seeks to demonstrate an non-OpenShift instance.

Once the components are installed, make the gogs config file edit as per below. Launch the gogs service and then visit the console at http://localhost:3000 to complete standard first-time configuration settings as necessary for your postgresql database.

$ vi ~/gogs/custom/config/app.ini
[webhook]
SKIP_TLS_VERIFY = true
$ ./gogs web

Change cotd to local Git Repo

Create a git repo named “cotd” on the local Git server.  Bring the cloned cotd repo under local git server control.

$ cd ~/containersascode
$ rm -rf cotd
$ git clone https://github.com/StefanoPicozzi/cotd.git
$ cd cotd
$ git init
$ git add .
$ git commit -am "Populate repo"
$ git remote add origin http://localhost:3000/stefanopicozzi/cotd.git
$ git push -u origin master

Set up localtunnel

Containers cannot access localhost URLs, so lets set up the localhost gogs service to respond to a local tunnel URL $LOCAL-TUNNEL . Refer  https://localtunnel.github.io/www/ for details. Note that alternative techniques to accomplish this effect, but not covered here, include 1) launching a gogs container and running gogs inside a virtual machine.

$ npm install -g localtunnel
$ lt --port 3000

OpenShift webhook

Create an application and then recover the GitHub web hook URL . Add this webhook to your gogs repo using the console at: http://localhost:3000/stefanopicozzi/cotd/settings/hooks . Use the gogs webhook “Test Delivery” feature to verify success.

$ oc login -u developer -p developer
$ oc delete project webhook
$ oc new-project webhook --display-name='Webhook Example' --description='Webhook Example'
$ oc new-app --name='cats' -l name='cats' php~https://$LOCAL-TUNNEL:3000/StefanoPicozzi/cotd.git -e SELECTOR=cats
$ oc expose service cats --name=cats -l name='cats'
$ oc describe bc cats

Trigger build/deploy

Alter the ranking of the items then trigger the webhook to fire by pushing the change to the git repo.

$ cd ~/containersascode
$ cd cotd
$ vi data/cats/rank.php
// Change ranking position
$ git add .
$ git commit -am "Changed rank"
$ git push

Verify Lab Success

Verify the new version from the Console at https://127.0.0.1:8443/console .

Advertisements

One thought on “Webhooks with OpenShift

  1. Pingback: OpenShift DevOps Tutorial | emergile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s