Skip to content

Latest commit

 

History

History
171 lines (123 loc) · 5.5 KB

12_Code_Promotion_Across_Environments.adoc

File metadata and controls

171 lines (123 loc) · 5.5 KB

Code Promotion across Environments

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 testing 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).

Step 1: Create two projects

Using the knowledge you gained from the past create two projects.

Name the first project development-<your_username>

$ oc new-project development-<user#>

Name the second testing-<your_username>.

$ oc new-project testing-<user#>

Also remember to substitute the username!

Step 2: Provide ImagePuller Access to the Testing Project from Development Project

The following command will allow the Testing project to be able to pull the docker images from the Development project.

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

Step 3: Create an application in the development project

Switch over to the development-UserName project and deploy an application using the php s2i builder. You can use webconsole 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 development-UserName
oc new-app openshift/php~https://github.com/RedHatWorkshops/welcome-php

Step 4: Tag the docker image

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

Now find the imagestream name using the following command. is is the short form for imageStream.

$ oc get is
NAME          DOCKER REPO                                                       TAGS      UPDATED
welcome-php   docker-registry.default.svc:5000/development-UserName/welcome-php

Now describe this image stream to get the full image id:

$ oc describe is welcome-php
Name:			welcome-php
Namespace:		development-UserName
Created:		7 minutes ago
Labels:			app=welcome-php
Annotations:		openshift.io/generated-by=OpenShiftNewApp
			openshift.io/image.dockerRepositoryCheck=2017-08-21T23:24:26Z
Docker Pull Spec:	docker-registry.default.svc:5000/development-UserName/welcome-php
Unique Images:		1
Tags:			1

latest
  pushed image

  * docker-registry.default.svc:5000/development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf
      4 minutes ago

In this case, the full image Id is:

development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf

Now let us assume that this docker image is good and is ready to promote to Testing. Let us tag this docker image using the oc tag command.

The format is

oc tag FullImageId development-UserName/welcome-php:promote-qa

Check the following commands and replace the values where needed:

$ oc tag development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf development-UserName/welcome-php:promote-qa

Tag welcome-php:promote-qa set to docker-registry.default.svc:5000/development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf.


$ oc describe is welcome-php
Name:			welcome-php
Namespace:		development-UserName
Created:		4 minutes ago
Labels:			app=welcome-php
Annotations:		openshift.io/generated-by=OpenShiftNewApp
			openshift.io/image.dockerRepositoryCheck=2017-08-21T23:24:26Z
Docker Pull Spec:	docker-registry.default.svc:5000/development-UserName/welcome-php
Unique Images:		1
Tags:			2

latest
  pushed image

  * docker-registry.default.svc:5000/development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf
      2 minutes ago

promote-qa
  tagged from docker-registry.default.svc:5000/development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf

  * docker-registry.default.svc:5000/development-UserName/welcome-php@sha256:157334d73dfc8dfdf733257b05c3fecaee236d36f69afa207395715fbe882abf

Step 5: Deploy the application to Testing

Now you can switch over to the Testing project and deploy the docker image that we tagged in development. Also expose service to create route for this project and remember to substitute username.

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

Test this application in the Testing project. Note that we deployed the docker image from the development project without rebuilding the code.

Bonus points: Make changes to your git repo (to index.php) and deploy it to development first. Notice that your changes are seen only in development project. Repeat the changes a couple of times. Now find the latest imagestream and tag it as promote-qa. Watch out that the Testing project gets redeployed when you update the new tag.

Watch this video for complete understanding.

Congratulations!! you now know how to promote your application across environments in OpenShift 3.

Let’s clean up the projects prior to continueing.

$ oc delete project development-UserName
$ oc delete project testing-UserName