11 Code Promotion

Introduction

In this lab we will learn how an application image binary can be promoted across the environments. As an example we will use development and QA environments as promotion to pre-prod and production will be very similar.

In this example we are using projects as means of separation of environments (development, qa, production).

Create and Setup Environments for Code Promotion

  • Create two projects (Development and Testing)

Using the knowledge you gained from the past create two projects. Name the first project workshop-development-YourName

$ oc new-project workshop-development-YourName

Name the second workshop-testing-YourName.

$ oc new-project testing-UserName

Remember to substitute the YourName!

  • Provide ImagePuller Access to the QA Project from Development Project

The following command will allow the QA project to be able to pull the container images from the Development project.

$ oc policy add-role-to-group system:image-puller system:serviceaccounts:workshop-testing-YourName -n workshop-development-YourName

Deploy application

  • Create an application in the development project

Switch over to the workshop-development-YourName project and deploy an application using the php s2i builder. You can use web console or command line. The command line option is shown below.

Bonus points: Clone this application to your own github account and deploy it so that you can redeploy with changes later.

oc project workshop-development-YourName
oc new-app openshift/php~https://github.com/RedHatWorkshops/welcome-php
  • Fix the buildConfig resources

## Select the project
$ oc project workshop-development-YourName

## Now we need to find the builds
$ oc get builds

NAME              TYPE     FROM   STATUS    STARTED         DURATION
welcome-php-1     Source   Git    Running   5 seconds ago

## If the build is still running, cancel it first:
$ oc cancel-build welcome-php

## Afterwards, we need to patch the BuildConfig, which is the name of the build without the "-1"
$ oc patch bc/welcome-php --patch '{"spec":{"resources":{"limits":{"memory":"1Gi","cpu":"1000m"}}}}'

## Now, start a new build
$ oc start-build welcome-php

## You can check it's status again by running oc get builds
$ oc get builds
NAME              TYPE     FROM          STATUS                       STARTED          DURATION
welcome-php-1     Source   Git@9d448d1   Cancelled (CancelledBuild)   49 seconds ago   18s
welcome-php-2     Source   Git@9d448d1   Running                      4 seconds ago
  • Tag the Container Image

Wait until the application gets built and deployed. Now if you check the imagestreams you will find the container image for this application.

Note You can find the imagestream name using the following command. is is the short form for imageStream.

$ oc get is
NAME          IMAGE REPOSITORY                                                                     TAGS   UPDATED
welcome-php   openshift-image-registry.apps.cluster.chp4.io/workshop-development-tim/welcome-php

Run the command again after the application is deployed. It will show you full image id and the current tags assigned to that image. You’ll notice that only latest is assigned right now.

$ oc describe is welcome-php
Name:			        welcome-php
Namespace:		    workshop-development-tim
Created:		      9 minutes ago
Labels:			      app=welcome-php
			            app.kubernetes.io/component=welcome-php
			            app.kubernetes.io/instance=welcome-php
Annotations:		  openshift.io/generated-by=OpenShiftNewApp
Image Repository:	openshift-image-registry.apps.cluster.chp4.io/workshop-development-tim/welcome-php
Image Lookup:		  local=false
Unique Images:		1
Tags:			        1

latest
  no spec tag

  * image-registry.openshift-image-registry.svc:5000/workshop-development-tim/welcome-php@sha256:ff153f20f4d653ab40f42af483a6174359b4b53a8aaf87b4d6e2fb6b0edc92e1
      2 minutes ago

In general, when you are in development, you may be building your application multiple times,and test it. When a particular image passes your tests it will be promoted to QA.

Now let us assume that this container image is good and is ready to promote to QA. Let us tag this image using the oc tag command. We will pick up the latest image built and tested and add a tag to it as promote-qa as shown below:

Remember to substitute your YourName.

Now describe the imagestream again to notice that a new tag promote-qa is applied now.

$ oc describe is welcome-php
Name:			        welcome-php
Namespace:		    workshop-development-tim
Created:		      13 minutes ago
Labels:			      app=welcome-php
			            app.kubernetes.io/component=welcome-php
			            app.kubernetes.io/instance=welcome-php
Annotations:		  openshift.io/generated-by=OpenShiftNewApp
Image Repository:	openshift-image-registry.apps.cluster.chp4.io/workshop-development-tim/welcome-php
Image Lookup:		  local=false
Unique Images:		1
Tags:			        2

latest
  no spec tag

  * image-registry.openshift-image-registry.svc:5000/workshop-development-tim/welcome-php@sha256:ff153f20f4d653ab40f42af483a6174359b4b53a8aaf87b4d6e2fb6b0edc92e1
      6 minutes ago

promote-qa
  tagged from welcome-php@sha256:ff153f20f4d653ab40f42af483a6174359b4b53a8aaf87b4d6e2fb6b0edc92e1

  * image-registry.openshift-image-registry.svc:5000/workshop-development-tim/welcome-php@sha256:ff153f20f4d653ab40f42af483a6174359b4b53a8aaf87b4d6e2fb6b0edc92e1
      About a minute ago

Step 5: Deploy the application to QA

Now you can switch over to the QA project and deploy the container image that we tagged as promote-qa. Note that the image is still in the development project. You are able to deploy that into testing project, because we gave necessary permissions for the testing project to be able to pull an image from development project.

Also expose service to create route for this project and remember to substitute YourName.

oc project testing-YourName
oc new-app workshop-development-YourName/welcome-php:promote-qa
oc expose service welcome-php

Watch this video for complete understanding.

Cleanup

Delete the Projects:

oc delete project workshop-testing-YourName
oc delete project workshop-development-YourName

== Summary

You now know how to promote your application across environments in OpenShift.