Post5

Continuous Deployment using Dockerized Application

Posted by Neeraj Virmani

Dockerized Applications

Dockerized applications are applications that are packed into a Docker image and stored on a Docker repository. These Docker images are used to provision applications along with the environment onto any of the application environment (QA/ Stage/ PROD). These Docker images are versioned and stored on Docker repository. Versioning of Dockerized applications helps in easy storage and access to multiple releases of the application.

Majorly there are two strategies for continuous deployments using dockerized application:-
a) Continuous Deployments using Environment Image
b) Continuous Deployments using Application Image
Let us understand both, one by one

Continuous Deployments using Environment Image

This approach involves building a docker image of the environment from the Dockerfile kept over the SCM along with the code. The image is then uploaded to the Docker repository from where it is used to spin up several spontaneous environments, such as test environment to execute the functional tests, staging/ pre-prod environment to deploy artifacts, and production environment to deploy products.

In case of changes in the environment specifications, a new environment image is built and corresponding Dockerfile is updated. Since the environment Dockerfile is maintained with the code on the SCM, any change to the Dockerfile results in building and uploading of new environment image to the Docker image repository.

This environment image is used to supply different environments on to which Jenkins/ CI-CD tool deploy the required application artifact (WAR/ EAR etc.) and application is deployed on the environment.

Continuous Deployments using Application Image (Recommended)

This approach involves building a docker image of the environment and then pack it with the application’s artifacts that are built leveraging the latest code pushed by the development team on to the SCM tool and then create an application Docker image using the existing image.

This application Docker image can now be used to achieve continuous deployment and set up environments such as QA, Staging, and PROD. The version of the application Docker image should be similar to the version of the build and release of the artifacts.

Creating Application’s Docker Image

Since continuous deployment using application image is the recommended method, it is important to know how to create the application’s Docker image. It is described below step-by-step.

  • Create an ‘env’ Dockerfile to build images and keep it in the master branch so that it is accessible to other branches such as develop and feature branches.

  • Check if the files have changed since the previous commit using “git diff” command.

Use the previous image if there are no changes else build the docker image from the feature/ develop branch and start a container from this image.

  • Place the build artifact (WAR/ EAR) using a CI tool such as Jenkins into the running environment’s container. Then create the new Docker image along with the environment and build artifact.

The name of this application docker image will be

project‑name>_<branch‑name>_<tag>

Where the tag is a three decimal point number  “major.minor.build_number” example: [1.0.0]  in case of a build from the feature branch.

Also, to easily identify the image, the name of the image shall be a four decimal point number major.minor.build_number.hotfix_number” example: [1.0.0.0] in case of a build from develop branch, after the feature branch is merged into it for the application release.

Do refer SCM branching and merging strategy document to understand the concept of feature branches and develop branch and the SCM strategy.

  • Add an additional tag to the latest image of the branch such as latest_feature in images created from the feature branch and latest_develop in images created from the develop branch.
  • Upload the application image to the Docker repository. 

     

    Final Words

    Continuous deployment using Dockerized application is a very interesting subject. It promotes automation as it allows us to establish a pipeline to deploy the application the moment it is completely built. The combination of Jenkins and Docker make it convenient to version and store images and at the same time deploy them nonchalantly.

    You too may employ both these awesome tools to automate the application development and deployment process. Let us know the result and your thoughts on the concept in the comments below.

    That’s it from us, until next time!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *