Code Promotion across Environments

In this recipe 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 two projects

Using the knowledge you gained from the past create two projects named ` development` and testing.

  • Run:

$ oc new-project development

$ oc new-project testing

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 -n development
role "system:image-puller" added: "system:serviceaccounts:testing"

Create an application in the development project

Switch over to the development project and deploy an application using eap6-basic-sti template. You can use webconsole or command line. The command line option is shown below.

$ oc new-app --template=eap70-basic-s2i -p APPLICATION_NAME=myapp -p SOURCE_REPOSITORY_URL=https://github.com/jbosschina/kitchensink.git -p SOURCE_REPOSITORY_REF="" -p CONTEXT_DIR="" -l name=myapp

--> Deploying template "openshift/eap70-basic-s2i" to project development

     eap70-basic-s2i
     ---------
     Application template for EAP 7 applications built using S2I.


     * With parameters:
        * APPLICATION_NAME=myapp
        * HOSTNAME_HTTP=
        * SOURCE_REPOSITORY_URL=https://github.com/jbosschina/kitchensink.git
        * SOURCE_REPOSITORY_REF=
        * CONTEXT_DIR=
        * MQ_QUEUES=
        * MQ_TOPICS=
        * MQ_CLUSTER_PASSWORD=Yrgls76p # generated
        * GITHUB_WEBHOOK_SECRET=rFJWjJHP # generated
        * GENERIC_WEBHOOK_SECRET=1e2YKrJn # generated
        * IMAGE_STREAM_NAMESPACE=openshift
        * JGROUPS_CLUSTER_PASSWORD=EKaC1FW1 # generated
        * AUTO_DEPLOY_EXPLODED=false

--> Creating resources with label name=myapp ...
    service "myapp" created
    route "myapp" created
    imagestream "myapp" created
    buildconfig "myapp" created
    deploymentconfig "myapp" created
--> Success
    Build scheduled, use 'oc logs -f bc/myapp' to track its progress.
    Run 'oc status' to view your app.

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
myapp     172.30.160.227:5000/development/myapp   latest    29 seconds ago

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

$ oc describe is myapp
Name:			myapp
Namespace:		development
Created:		3 minutes ago
Labels:			app=eap70-basic-s2i
			application=myapp
			name=myapp
			template=eap70-basic-s2i
			xpaas=1.3.2
Annotations:		openshift.io/generated-by=OpenShiftNewApp
Docker Pull Spec:	172.30.160.227:5000/development/myapp
Unique Images:		1
Tags:			1

latest
  pushed image

  * 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f
      54 seconds ago

In this case, the full image Id is 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f.

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 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f development/myapp:promote-qa
Tag myapp:promote-qa set to 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f.

check with the following commands

$ oc describe is myapp
Name:			myapp
Namespace:		development
Created:		8 minutes ago
Labels:			app=eap70-basic-s2i
			application=myapp
			name=myapp
			template=eap70-basic-s2i
			xpaas=1.3.2
Annotations:		openshift.io/generated-by=OpenShiftNewApp
			openshift.io/image.dockerRepositoryCheck=2017-07-16T11:21:49Z
Docker Pull Spec:	172.30.160.227:5000/development/myapp
Unique Images:		1
Tags:			2

latest
  pushed image

  * 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f
      5 minutes ago

promote-qa
  tagged from 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f

  * 172.30.160.227:5000/development/myapp@sha256:2058c31d19710a1de2bc52c3072db9f501152382b791514a8b1ffe2be8e48e5f
      About a minute ago

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:

$ oc project testing

$ oc new-app development/myapp:promote-qa
--> Found image 2b3a4c5 (8 minutes old) in image stream "development/myapp" under tag "promote-qa" for "development/myapp:promote-qa"

    development/myapp-1:f22839d2
    ----------------------------
    Platform for building and running JavaEE applications on JBoss EAP 7.0

    Tags: builder, javaee, eap, eap7

    * This image will be deployed in deployment config "myapp"
    * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "myapp"
      * Other containers can access this service through the hostname "myapp"

--> Creating resources ...
    deploymentconfig "myapp" created
    service "myapp" created
--> Success
    Run 'oc status' to view your app.

$ oc expose service myapp
route "myapp" exposed

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

results matching ""

    No results matching ""