Continuous Integration and Continuous Delivery (CI/CD) practices have revolutionized the software release process by automating it from build to deployment. AWS offers Managed Services that cover these processes, making them faster and more reliable.
This user guide will showcase how to create a build and deployment pipeline using AWS Managed Services such as AWS CodePipeline, AWS CodeBuild, AWS ECR, AWS CodeDeploy, and AWS CloudFormation. The guide will build upon a containerized application running on the AWS ECS Fargate platform, and the deployment will utilize the AWS ECS Service rolling deployment mode. The following diagram shows the setup that will be created.
The steps that we will take in this guide are:
- Installing prerequisites
- Constructing the Pipeline
- Test the process
- Implement your CI/CD Project with Cloudvisor
1. Installing prerequisites
1. Installing the underlying infrastructure
As a first step, clone the git repository to speed up the process—link to the repository here.
git clone https://github.com/sandor1cloudvisor/Quotes-Service.git
After Cloning the repository, the following command should be issued to setting up the underlying infrastructure.
# in linux
source ./aws-resources/provision-infra.sh
The issued command above will provide a VPC
, an ECS Cluster
, an ECR Repository
, and a Load Balancer
with a Listener
.
2. Installing the ECS Application
# in linux
source ./aws-resources/build-and-push-image.sh
The script above will run the Docker build; it logs in to the ECR and pushes the image to the Registry.
# in linux
source ./aws-resources/provision-services.sh
The script above will create the Task Definition and the ECS Service and register the Service to the Load Balancer.
At this step, the base infrastructure should be deployed. Let’s take a look at what has been provisioned so far.
- Navigate to the AWS CloudFormation page and check for the two different stacks.
Check if the ECS Service is operational.
- Find the Load Balancer called
QuotesAppLoadBalancer
. - Query the Load Balancer Endpoint, and you should see the response coming from the
Quotes
Service. Like:
// Response from the Service
{"quote":"We are an advanced-tier AWS partner helping startups across the globe get the most out of AWS. AWS is one-half of our company’s DNA. The other one is startups."}
2. Constructing the Pipeline
1. Establishing a connection with GitHub as the source repository
After Clicking on Creating an AWS CodePipeline, provide the pipeline’s name, select the create new service role, and hit the next button.
In the next step, the Source needs to be specified. GitHub (v2) can be selected as a viable option where the source repository is placed. Click on the Create Connection and specify the GitHub Connection details as below.
After the connection is defined, further details regarding the repository can be filled in, such as the name and branch.
2. Preparing AWS CodeBuild
After configuring the source repository, we must create an AWS CodeBuild project. Pay attention that the buildpec.yml
file is already created. The buildpec.yml
will control how and what the AWS CodeBuild will execute. In our case, it defines to build and tag the container image, log in to AWS ECR and push the image there, and also creates the parameters for the next step in the AWS CodePipeline.
The next step in the pipeline is the Build step. Select AWS CodeBuild as the Build provider.
After that, click on the Create project
tab to create a new AWS CodeBuild project.
Creating a new CodeBuild Project involves specifying the environment and the build image we’ll use during the build process, as seen below.
Also, creating a Build project involves specifying the Compute Size and the Timeouts possibility of using a VPC. As seen in the image below.
3. Setting up AWS CodeDeploy
As a first step, an IAM service role needs to be created; this service role will be assumed by AWS CloudFormation. The policies should cover the creation of ECS task definitions and ECS services. So attach the AmazonECS_FullAccess
, policy to the created Role; the Role can be named like CloudFormationServiceRole
.
As a next step, the deploy stage can be defined; select the appropriate provider as AWS CloudFormation, and select the Action mode as Create or Update stack. Select the existing quote-service
stack.
Also, the role created above (in this step, called as CloudFormationServiceRole) needs to be provided. Also needs to define the Parameter overrides; this has been. (In this case, the Parameter overwrites are matched to the parameters set in the CloudFormation template used by the CodeDeploy part of the pipeline.
3. Test the Build and Deployment process
After finishing the AWS CodePipeline creation, the process will kick in automatically. After the GitHub source, AWS CodeBuild built the image and pushed it to the AWS ECR Repository. AWS ECS Service also got updated by AWS CloudFormation, providing an Immutable infrastructure approach based on an Infrastructure as Code foundation.
The execution summary of the AWS CodePipeline can be selected, and it shows the details of the different steps. As seen in the image below.
Summary
Selecting AWS Managed Services to run Continuous Integration and Continuous Build is a perfect decision. AWS provides many tools to test, build, release, and deploy applications and infrastructure. These services integrate with third-party tools like GitHub and Jenkins.
Using AWS CodePipeline helps us control the flow of an integration and delivery pipeline; using an AWS Service like AWS CodeBuild makes it possible to provide compute capacity for test and build processes. AWS CodeDeploy natively integrates with many AWS Services, like AWS CloudFormation, AWS Elastic Beanstalk, or AWS ECS.
Implement your CI/CD solution to your project with Cloudvisor!
Are you ready to take your projects to the next level? Say hello to a game-changer in software release automation: Continuous Integration and Continuous Delivery (CI/CD) practices; these revolutionary approaches have transformed how software is deployed, streamlining the entire process from build to deployment. From simplifying build automation to supercharging deployment pipelines, Cloudvisor can be the perfect partner in accelerating and fortifying your AWS journey; with senior-level cloud and AWS-certified engineers, we can implement a CI/CD solution to your project, giving you high-quality solutions.
Written by Sándor Bakos
AWS Cloud Engineer/Architect at Cloudvisor