0% found this document useful (0 votes)
24 views27 pages

Basic CI CD Setup Guide 1726141961

Uploaded by

Zeeshan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views27 pages

Basic CI CD Setup Guide 1726141961

Uploaded by

Zeeshan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

CI/CD Pipeline Setup with AWS Services

By Tushar Gupta

Objective:
The goal is to set up a CI/CD pipeline that automates the deployment of a simple web
application to a server. The pipeline should trigger on code pushes to a repository and deploy
the application in a scalable manner. When load increases, the number of servers should
automatically scale up or down, ensuring that new servers have the latest code.

Github Repo : https://github.com/cstushar/ci_cd_repo.git

Tools Used:

1. AWS CodeDeploy
2. AWS Auto Scaling
3. AWS Load Balancing
4. AWS CodePipeline
5. AWS EC2
6. Git/Bitbucket
Step-by-Step Process

1. Create a Launch Instance Template in EC2

● Operating System: Ubuntu (Free tier)


● Instance Type: T2 Micro
● Key Pair: Enabled
● Security Group:
○ Allow SSH and HTTP access from anywhere.
2. Create an IAM Role for EC2

● IAM Role Type: EC2


● Permissions: AmazonEC2RoleforAWSCodeDeploy
● Assign the Role: Select this IAM role when creating the EC2 launch template.
3. User Data for EC2 Instance

● In the User Data section, provide a script that automatically installs the CodeDeploy
agent when the instance is launched. This ensures that the CodeDeploy agent is set up
without manual intervention.

#!/bin/bash
sudo su
apt update
apt upgrade -y
apt install nginx -y
sudo apt update
sudo apt install ruby-full -y
sudo apt install wget
cd /home/ubuntu
wget https://aws-codedeploy-ap-south-1.s3.ap-south-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

4. Create the Launch Template

● After configuring the above settings, create the EC2 launch template.

Auto Scaling Configuration


1. Create an Auto Scaling Group

● Name: CICDApp (or another preferred name)


● Launch Template: Select the template created earlier.
● Availability Zones: Choose all available zones for your region.
2. Load Balancer Setup

● Type: Network Load Balancer


● Visibility: Internet-facing
● Listeners: Create a target group and assign it a name.
Note: Initially set the desired capacity to 0, as you don’t need to start instances yet.

3. Verify the Load Balancer

● Check the Load Balancer dashboard to ensure the Load Balancer is created and is in
the provisioning state. It will eventually transition to an active state.
CodeDeploy Setup

1. Create a CodeDeploy Application

● Application Name: Choose a name.


● Compute Platform: EC2/on-premises
2. Create an IAM Role for CodeDeploy

● Service: CodeDeploy
● Permissions: AWSCodeDeployRole
3. Create a Deployment Group

● Deployment Group Name: Choose a name.


● Service Role: CodeDeploy role with the necessary permissions.
● Amazon EC2 Auto Scaling Group: Select the group created earlier.
● Deployment Settings: Use the CodeDeployDefault.OneAtATime deployment
configuration to ensure that instances remain healthy.
● Load Balancer: Enable load balancing and select the appropriate Load Balancer target
group.
CodePipeline Setup

1. Create a Pipeline

● Pipeline Name: Choose a name.


● Source Provider: GitHub (Version 2)
○ Connect to GitHub by logging in with your credentials and selecting the repository
and branch to trigger the pipeline.
2. Skip the Build Stage (if not needed)

● If your project does not require a build step (e.g., if it's just an HTML page), skip this
stage.

3. Deploy Using CodeDeploy


● Region: Select your AWS region (e.g., US East).
● Application Name: Choose the application created in CodeDeploy.
● Deployment Group: Select the deployment group created earlier.

4. Verify Pipeline Creation

● Once the pipeline is set up, it will attempt to deploy the code. However, it will fail initially
if no EC2 instances are available. This is expected behavior.
Deploying the Application

1. Edit Auto Scaling Group Size:


Increase the desired capacity to 1 to initiate the creation of an EC2 instance. The
instance will automatically install the CodeDeploy agent and be prepared for
deployment.
2. Monitor Deployment Events:
Check CodeDeploy for event logs. The deployment process may get stuck at the "Block
Traffic" event for around 5 minutes. This happens as the Load Balancer registers and
deregisters the instance to verify its health status.
3. Access the Deployed Application:
Once the deployment is complete and the instance is healthy, copy the DNS from the
Load Balancer dashboard and paste it into a web browser. The application should now
be live.
4. Test Auto Scaling:
Increase the number of instances in the Auto Scaling group to test automatic scaling. As
load increases, more instances will be created, and the application will be replicated
across these instances.
Clean-Up:

● Terminate Instances: After testing, make sure to either terminate the instances
manually or reduce the Auto Scaling group size to 0. This will prevent unnecessary
charges.
Conclusion: By following the above steps, you can successfully set up a CI/CD pipeline that
deploys a web application to AWS. The pipeline is designed to scale automatically with load,
ensuring high availability and consistency in deployment.

You might also like