Skip to content

Latest commit

 

History

History
208 lines (145 loc) · 5.14 KB

10_SCM_Web_Hooks.adoc

File metadata and controls

208 lines (145 loc) · 5.14 KB

SCM Web Hooks

OpenShift offers several mechanisms to trigger the automatic deployment of applications. In this Lab, we will demonstrate the deployment of a very simple application via a GitHub Web Hook trigger.

Part I

In Part I of the Lab we will:

  • Create a new project.

  • Deploy an application using a source to image strategy.

  • Create a route to expose the newly deployed application.

Step 1: Create new project

Remember to substitute the UserName

$ oc new-project scm-web-hooks-UserName --display-name="Test WebHooks"

Step 2: Create new application

  • In the previous lab we used a github repository containing the bluegreen application. For this lab we’ll want to first "fork" that repository so we can make changes to the code.

From a web browser, navigate to https://github.com/RedHatWorkshops/bluegreen

In the upper right corner of the page, click on the "Fork" icon to fork the repository. This will give you a copy of the code that you can manage and modify. Your will use this repository in the next step when you create a new application in your project.

$ oc new-app --image-stream=php --code=https://github.com/your_github_username/bluegreen.git --name=scm-web-hooks

Step 3: Look at some of the created resources

  • Build configuration

$ oc get bc
  • Deployment configuration

$ oc get dc
  • Show created service

$ oc get service
  • Show replication controller

$ oc get rc
  • Show route

$ oc get route

Notice that there is no route created yet for this application.

  • Show the builds in progress (Running)

$ oc get builds
NAME              TYPE      STATUS    POD
scm-web-hooks-1   Source    Running   scm-web-hooks-1-build
  • Monitor the build

$ oc logs -f build/scm-web-hooks-1

The build should finish similar to:

Pushing image 172.30.89.28:5000/scm-web-hooks-admin/scm-web-hooks:latest ...
Pushed 0/5 layers, 2% complete
Pushed 1/5 layers, 22% complete
Pushed 2/5 layers, 44% complete
Pushed 3/5 layers, 70% complete
Pushed 3/5 layers, 100% complete
Pushed 4/5 layers, 100% complete
Pushed 5/5 layers, 100% complete
Push successful

Step 4: Create a route

$ oc get service

NAME            CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
scm-web-hooks   172.30.71.191   <none>        8080/TCP   4m

Remember to substitute the UserName.

$ oc expose service scm-web-hooks
route "scm-web-hooks" exposed

Step 5: Test the application

image

Part II

At this point you have an application with one single replica running inside a docker container in OpenShift. We used the source retrieved from the git repository and layered it using a builder or image stream strategy; in this particular case, the php image stream.

In this part of the Lab we will:

  • Create a web hook for the recently deployed application.

  • Make a small change to the application.

  • Test to make sure the application was re-deployed.

Step 1: Retrieve the OpenShift Web Hook URL

  • From inside a web browser, navigate to your project and then click Builds and then Build Configs.

  • Click onto the build name from the list. You should have just one in this case.

  • Scroll to the bottom and you should see two entries in the Webhooks section

  • For the GitHub click on the *Copy URL with Secret" link. You will need this URL for next step.

Step 2: Configure GitHub repository Web Hook

  • Login to your GitHub account.

  • Navigate to the forked repository you used to create the application.

  • Click on Settings.

  • Click on Webhooks.

  • Click on the Add webhook button.

  • Add the recently copied Web Hook URL from OpenShift.

  • Change the Content-type as ``application/json''

  • Click on the Disable SSL Verification button.

  • Confirm by adding the Add Webhook button in green at the bottom of the page.

image

Step 3: Redeploy the application

  • In your GitHub account edit the image.php file.

  • On line 6 it defined a $deployment variable and obtains the COLOR environment variable.

  • Make a copy of this line, then comment the original line 6.

  • In the new copy of line 6 set its value to 'green', then save the file.

$deployment = 'green';

  • Commit the file.

Step 4: Monitor new deployment process

  • After saving/committing the image.php file with the small change, you’ll notice in the OpenShift Web Console that a new build process has been automatically triggered. You didn’t have to start a build yourself.

  • Monitor the build process using:

$ oc get builds

$ oc logs build/the-new-build-process-name

Summary

We have shown in this Lab how simple it is to configure automatic deployments of applications using OpenShift and GitHub Web Hook triggers. It should be noted that OpenShift also supports Generic Web Hooks.