Continuous Delivery(CD) is a pillar of modern application development which is often combined with Continuous Integration (CI). It is a DevOps method/principle which ensures code changes by developers are automatically prepared for release to production.
This blog explains the Continuous Delivery concept for a person who is just starting with DevOps and wants to understand the need for CI/CD.
When a code/feature is written and pushed to a repository ( GitHub, CodeCommit), it is automatically built and tested to ensure changes haven't broken the app and a deployable artefact is produced ( this process is Continuous Integration CI).
Here comes our topic for the blog. Continuous Delivery comes right after CI. Now the code is tested and not broken it's time to deploy it to either the dev/testing environment or production environment.CD ensures that code is automatically deployed after the successful CI phase.
Note:- Often people use Continuous Deployment as colloquial to CD, let's not get stuck to semantics. The major difference between continuous delivery and continuous deployment is with continuous delivery, is the presence of a manual approval to update to production. With continuous deployment, production happens automatically without explicit approval.
In this blog we are going to build a pipeline with AWS CodePipeline which demonstrates the concept of continuous delivery(CD).
- Fully managed continuous delivery service that helps you create, and automate release pipelines.
- CodePipeline allows adding different stages which can be used to test, build and deploy every time there is a code change, based on the release model you define.
- You can easily integrate AWS CodePipeline with third-party services such as GitHub.
- With AWS CodePipeline, you only pay for what you use. There are no upfront fees or long-term commitments.
For this blog, I am trying to keep it as beginner-friendly as I can and focus more on the Continuous Delivery concept.
- Create a sample elastic beanstalk nodejs application refer docs
This results in a sample web page which is green in colour.
Note:- Create a separate environment for the same sample application and name it sample-app-prod-env
- Create a code commit repository and upload index.html file present in this repository
- Edit index.html and change it to blue.
- Create a pipeline using code pipeline from AWS console.
Configure the source of the pipeline as the code commit repository with the branch name and repository name.
Configure the deploy stage for the pipeline as the elastic beanstalk and the sample application created earlier.
The moment the pipeline is created, it triggers the pipeline and deploys automatically the index.html contents to the elastic beanstalk application.
Code Pipeline also allows deploying to many stages for example one for dev env, another for production stage.
Code Pipeline also allows adding manual approvals when automatic deployment for the production environment.
- Here we are adding to a sequential action group one for manual approval and another for deployment to the elastic beanstalk production environment.
Once manual approval is added, edit the code in code commit and change the colour to red.
the pipeline automatically deploys to the production environment which is verified by a change in the colour of the prod to red.
- Codepipeline orchestrates the entire CI/CD flow by allowing to add of build, test and deploy stages.
- Codepipeline stores results of each stage as artefacts in the s3 bucket, so that the next stage knows how to proceed.
- Codepipleine requires an IAM service role with appropriate IAM policies to perform the action.
- Codepipline changes can be monitored using cloud watch events which can be used to create alarm and slack notifications.