Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Latest commit

 

History

History
168 lines (121 loc) · 5.33 KB

12-Code-Promotion-Across-Environments.adoc

File metadata and controls

168 lines (121 loc) · 5.33 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 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).

Step 1: Create two projects

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

Name the first project development-UserName

$ oc new-project development-UserName

Name the second testing-UserName.

$ oc new-project testing-UserName

Also remember to substitute the username!

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

The following command will allow the QA 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

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

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

The format is

oc tag FullImageId development-UserName/myapp:promote-qa

Check the following commands and replace the values where needed:

$ oc tag \
docker-registry.default.svc:5000/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 QA

Now you can switch over to the QA 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 QA 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 QA 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.