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 them development-UserName and 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 eap6-basic-sti
template. 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 --template=eap64-basic-s2i -p APPLICATION_NAME=myapp -p SOURCE_REPOSITORY_URL=https://github.com/VeerMuchandi/kitchensink.git -p SOURCE_REPOSITORY_REF="" -p CONTEXT_DIR="" -l name=myapp
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
myapp 172.30.47.239:5000/development-UserName/myapp latest 12 seconds ago
Now describe this image stream to get the full image id:
$ oc describe is myapp
Name: myapp
Created: 13 minutes ago
Labels: application=myapp,name=myapp,template=eap64-basic-s2i,xpaas=1.1.0
Annotations: openshift.io/generated-by=OpenShiftNewApp
openshift.io/image.dockerRepositoryCheck=tag "latest" has not been set on repository "development-UserName/myapp"
Docker Pull Spec: 172.30.226.0:5000/development-UserName/myapp
Tag Spec Created PullSpec Image
latest <pushed> 9 minutes ago 172.30.226.0:5000/development-UserName/myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4
In this case, the full image Id is development-UserName/myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4
Note: Leave the repository off the Image name if present e.g. 172.30.226.0:5000/
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 as your needs:
oc tag development-UserName/myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4 development-UserName/myapp:promote-qa
oc describe is myapp
Name: myapp
Created: 16 minutes ago
Labels: application=myapp,name=myapp,template=eap64-basic-s2i,xpaas=1.1.0
Annotations: openshift.io/generated-by=OpenShiftNewApp
openshift.io/image.dockerRepositoryCheck=tag "latest" has not been set on repository "development-UserName/myapp"
Docker Pull Spec: 172.30.226.0:5000/development-UserName/myapp
Tag Spec Created PullSpec Image
latest <pushed> 12 minutes ago 172.30.226.0:5000/development-UserName/myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4
promote-qa myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4 58 seconds ago 172.30.226.0:5000/development-UserName/myapp@sha256:7d0a5e0bbb0be497db86e2cac4f3ba47b5a6fa0d1a4e1529724ec1b21042e1f4
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/myapp:promote-qa
oc expose service myapp
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 src/main/webapp/index.xhtml
) 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.