Automated Deployment Of CI/CD
Tags: programming, devops, automation, discuss
Published: 2022-06-13 04:41:51

**Introduction**

Automated Deployment enables an organization to deploy software releases with a single command or simply by clicking on a control panel. Automation is essential to streamline the deployments in the production environment and reduce the associated risks. Web application deployment needs some well-defined steps to be followed so that the software changes are shipped from the development environment to the staging/ production environment. It is done so that the updated software (which includes new features and corrections) is available for the end-users.

Automated deployment reduces the human effort and avoids any manual intervention required to deploy code to the various environments like DEV(Development), QA ([Quality Assurance](https://hsc.com/Services/Testing-Services)), UAT(User Acceptance Testing), and PROD(Production). Automated deployment is closely linked to CI/CD (Continuous Integration & Continuous Delivery).
CI/CD is one of the current industry best practices to deliver applications to customers more frequently and reliably by introducing automation into the stages of application development.
_(Read: [What is CI/CD](https://www.redhat.com/en/topics/devops/what-is-ci-cd))_
_(Read:[Why DevOps Is Crucial For Your Business](https://hsc.com/Resources/Blog/Why-DevOps-Is-Crucial-For-Your-Business))_

## Automated Deployment Characteristics
Some of the salient features of automated deployment are:

- Deployment can be triggered by clicking on a button or running a single command from CLI
- There is little or no human intervention from the start to the end
- Better visibility, i.e. it shows the deployment progress as it happens
- It should be atomic, which means either all the steps are completed, or nothing happens
- Uninstallation of previous release or rollback of failed deployment should be easy and quick
- Smoke testing should be done after automated deployment to ensure nothing is broken
- It consists of pre-defined steps and a series of workflows. The next step should not be initiated until the previous steps successful
- It should be transparent with clear indications/notifications to the team about the success or failure of each step

_(Read:[CI/CD Enabler Framework for Google Cloud Platform](https://hsc.com/Resources/Blog/CICD-Enabler-Framework-for-Google-Cloud-Platform))_

##The Problem To be Solved
As part of the deployment of a new software release, the following tasks are routinely followed:

- Manually download software build from the build server to the target platform.
- Manually deploy build in the appropriate location/ container (on staging or production server).
- Manual smoke test to verify the key functionalities are working fine.

After providing so much manual effort if smoke testing fails then a new build is required and the complete cycle should be repeated. This requires a lot of manual effort again, which can be avoided.

**The key shortcomings of the current process are the lack of the following:**

- Automation deployment
- Automation sanity testing
- Automation smoke testing

Software development teams should not worry about how code is going into production. They should only focus on the business requirements, design, implementation, unit tests, integration tests, and regression tests. So, by excluding manual tasks and including automated tasks we can reduce a lot of additional efforts.

## Solution: Automated Deployment
To achieve [automated deployment](https://hsc.com/Services/Product-Engineering-Services/DevOps-Practices-and-Offerings), use Ansible which is an automation configuration tool. Keep Ansible as a controller entity that is used to interact with the required servers and executes the required shell script on managed nodes to achieve the desired result.

The framework which helps in executing the workflow is as shown below:
![HSC Automated-Deployment-Flow-Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1sfh0ancr3u0d4ynv7t7.png)
 
 


Write plays in such a way that Ansible can support N>0 number of servers at any tier.

1. Ansible verifies the reachability and memory usage of each server before continuing with deployment.
2. Ansible integration with collaboration tools helps to notify the team about continuous progress.
3. For each environment inventory files are there i.e. DEV, QA, UAT, and PROD.
4. In automation deployment, Ansible uses to run smoke testing before deployment of the build.
5. Ansible uses FTP so that release can be downloaded and deployed to DEV and QA env.
6. Ansible interacts with Artifactory to download/ deploy release on UAT and PROD env.
7. To ensure the integrity of the build, Ansible uses to evaluate some of the builds.
8. Ansible interacts with a load balancer to stop traffic.
9. Ansible interacts with the database server via the application server to upgrade the database.
10. Ansible interacts with the application server to download and deploy build.
11. Ansible does a predefined number of retries and waits for services to come up on the application server.
12. Ansible stops immediately if anything goes wrong and triggers rollback followed by verification of services.
13. Ansible interacts with selenium to trigger smoke testing after deployment of build on various environments.

## Key Components of Automated Deployment Framework
The diagram below illustrates the key components of the automated deployment:
![Automated-Deployment-Components](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6kqisiuo21wduhqxahlk.png)
 


**Deployment tool**: Ansible is used as a deployment tool and plays the role of a controller. It decides which steps to execute next, based on the outcome of the previous step. It interacts with various servers to execute predefined steps which are part of Automated deployment.

**Bash script**: Ansible interacts with various servers and runs a script on the server to accomplish various tasks.

**FTP / Artifactory**: The location from where Ansible downloads the software release. Based on our needs according to the environment, we can choose any location.
Notification: Automated Deployment framework notifies team in the various slack channel to show deployment progress.

**Pre-validation**: Framework verifies the services running on the environment before initiating deployment.

**Health check**: Framework verifies the health of the server with which it will interact. If health is not good, then it does not proceed with deployment and notifies the team about the same via a slack channel.

**Post-validation**: After upgrading services, the framework verifies services to ensure the software release has been successfully upgraded.

**Rollback**: Framework has the capability to trigger rollback and restore services if any step fails.

**Selenium**: Deployment framework verifies services in pre-validation and post-validation by initiating selenium scripts.

**Server reachability**: Before initiating deployment, it verifies if all servers are reachable to avoid any risk during deployment.

##Benefits:
The automation of the deployment has helped us achieve the following direct benefits in some of our customer's projects:

Planned downtime in production for new build deployments is reduced from 3 hours to 1 hour.
No manual testing required after software release up-gradation.
Parallel deployment can be initiated for multiple sites.
 

**References**
https://stackify.com/what-is-cicd-whats-important-and-how-to-get-it-right/
https://semaphoreci.com/cicd
https://www.digitalocean.com/community/tutorials/an-introduction-to-ci-cd-best-practices
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html
https://galaxy.ansible.com/
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html
https://docs.ansible.com/ansible-tower/