Created CI CD Pipeline To Build Deploy A Web Application 1729723723
Created CI CD Pipeline To Build Deploy A Web Application 1729723723
org
Build a Web
App and IDE in
AWS
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
What is an IDE?
An IDE is a general term for software that help developers write, debug, and
manage code efficiently.
Jaydeep Barot
NextWork Student NextWork.org
Once the web app was created, my IDE’s file explorer was populated with
'src/main/webapp' directory, which contains the web application's resources.
To customise this web app’s display, I updated the h2 tag in index.jsp file with
my Name.
NextWork.org
Set up a Git
Repo with
AWS
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
My first commit
I initialized a Git repo by running the command git init in Cloud9, which sets up a
new repository in the current directory, allowing me to start tracking changes in
my project.
The second command I ran was git commit -m "Initial commit. Updated
index.jsp.", which saves the changes to my local repository. The -m allows me
to add a message, explaining what the changes were, like updating the
index.jsp file in this case.
The third command I ran was git push -u origin main, which pushes my
committed changes to the remote repository. The -u sets the default branch for
future pushes, so next time I can just run git push without needing to specify
the branch or repositor
Jaydeep Barot
NextWork Student NextWork.org
Creating a Repository
Jaydeep Barot
NextWork Student NextWork.org
Git in action
Making changes in Cloud9
I wanted to see Git working in action, so I updated Index.jsp by adding a
paragraph to track changes.
Dependencies
and
CodeArtifact
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
Success!
After compiling, I checked the CodeArtifact repository and found a list of
packages. These packages were downloaded from the upstream or Maven
Central Repository and are now stored as copies within CodeArtifact, ready for
use in my project.
Jaydeep Barot
NextWork Student NextWork.org
Package an
App with
CodeBuild
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
Set up an S3 bucket
I started my project by creating an S3 bucket, which will later store an important
build artifact generated during the build process I'm setting up with CodeBuild.
This bucket will be key for managing and storing the results of the build.
The key artifact that this S3 bucket will capture is called a WAR file (Web
application Resource).
This artifact is important because it guarantees that any server hosting my web
app will have all the necessary resources and tools to run the application
smoothly, ensuring everything is in place for a successful deployment.
Jaydeep Barot
NextWork Student NextWork.org
Environment
My CodeBuild project's Environment configuration means the setup where the
build process runs. I selected an ec2 instance running Amazon Linux 2 and
Java Coretto 8 as runtime.
Artifacts
My CodeBuild project's Artifacts configuration means the output of the build
process.I selected an S3 bucket nextwork-build-artifacts-jaydeep,as the
storage location, with the build artifacts packaged into a ZIP file for easy
retrieval and deployment
Logs
My CodeBuild project's Logs configuration tracks the build's output and errors.
I selected CloudWatch logs, with logs sent to the nextwork-build-logs group
and the webapp stream, to monitor and troubleshoot the build process.
Jaydeep Barot
NextWork Student NextWork.org
The third phase in my buildspec.yml file is the build phase. In this phase, it runs
the command to compile the project using Maven, which processes the source
code and prepares it for packaging.
The fourth phase in my buildspec.yml file is the post_build phase. During this
phase, it runs the command to package the application using Maven, creating
the final artifact needed for deployment.
Jaydeep Barot
NextWork Student NextWork.org
Attaching this policy means that my CodeBuild project can now access the
necessary packages and dependencies stored in CodeArtifact, enabling it to
compile the application successfully and ensuring a smoother build process.
Jaydeep Barot
NextWork Student NextWork.org
The build process in CodeBuild took about 5 minutes to complete, during which
I monitored the logs to ensure everything was running smoothly.
Deploy an App
with
CodeDeploy
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
Bash scripts
Scripts are collections of commands stored in a file, so when you execute a
script, you're instructing the system to follow each line of code you've written.
Bash is one particular scripting language used for this purpose.
The second script I created was start_server.sh, which starts the Tomcat and
HTTPD services on my EC2 instance. This ensures that the necessary services
are running, allowing my web app to function properly every time it is deployed.
The third script I created was stop_server.sh, which stops the Tomcat and
HTTPD services on my EC2 instance. It checks if each service is running and, if
so, stops them, ensuring that the application can be safely shut down when
needed
Jaydeep Barot
NextWork Student NextWork.org
Bash scripts
Jaydeep Barot
NextWork Student NextWork.org
To set up CodeDeploy’s IAM role, I used the AWS managed policy called
AWSCodeDeployRole, which automatically grants the essential permissions
that CodeDeploy typically requires.
Jaydeep Barot
NextWork Student NextWork.org
CodeDeploy application
A CodeDeploy application refers to a saved configuration or setup template that
outlines the process for deploying my web app.
The compute platform I chose was EC2 because I have experience using EC2
as my web server. This gives me complete control over the server setup, which
is ideal for deploying my web application and learning the intricacies of server
management.
Jaydeep Barot
NextWork Student NextWork.org
Deployment group
A deployment group means a set of instances or servers targeted for a
deployment. It allows you to manage how and where updates are rolled out in
your application environment.
CodeDeploy application
To create my deployment, I had to set up a revision location, which means I
specified where CodeDeploy could find my app's artifacts, ensuring it knew
where to retrieve the files needed for the deployment.
To visit my web app, I had to visit the EC2 console to select my WebServer EC2
instance and then click on the open address link to access my application in the
browser.
NextWork.org
Automate with
Cloud
Formation
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
CloudFormation templates
A CloudFormation template is a text file that defines the AWS resources needed
for your application, allowing you to create, update, or delete them
automatically using CloudFormation.
Jaydeep Barot
NextWork Student NextWork.org
IaC generator
I created a CloudFormation template using the IaC generator, which scanned
my account’s resources and provided a list of those I could automatically add to
a template for easy deployment.
Testing my template
Before testing my template, I removed any possible resource overlaps between
the existing resources in my AWS account and those I plan to deploy with this
template.
The DependsOn line was added to four different parts of my template : the 3
IAM policies and the CodeBuild project
Jaydeep Barot
NextWork Student NextWork.org
This error indicates that two components of your CloudFormation template are
dependent on each other, creating a circular reference. This confuses
CloudFormation because it cannot determine which resource to create first.
To fix this error, I deleted references to the IAM policies off of the IAM
CodeBuild service role configuration.
Jaydeep Barot
NextWork Student NextWork.org
Not all the resources in the list had a shortcut URL, because some resources
are deployed in a specific region ,which often stops AWS from producing a
shortcut link.
NextWork.org
CI/CD with
CodePipeline
Jaydeep Barot
Jaydeep Barot
NextWork Student NextWork.org
CI/CD Pipeline
A CI/CD pipeline is a system that automates the process of building, testing,
and deploying code. It ensures that new updates are quickly and safely
delivered to users, helping developers catch errors early and release features
more efficiently.
The build stage refers to the service that handles the creation of my web app.
CodeBuild compiles the code, runs tests, and packages it for deployment. This
step ensures that the code is functioning as expected before moving to the
next stages.
The deploy stage is where the tested and built code is released to the
production environment. It ensures that the latest version of the app is available
to users, automating the process of moving the code from development to live
servers.
Jaydeep Barot
NextWork Student NextWork.org
CI/CD Pipeline
Jaydeep Barot
NextWork Student NextWork.org
Releasing a Change
My CI/CD pipeline is triggered by a commit made in my local Cloud9
environment, which then updates my CodeCommit repository
Trigger A Rollback
A rollback in a pipeline refers to reverting the code version that a specific stage
of the pipeline is currently referencing.
'I checked the source stage, and learnt that the source stage was unaffected
by the rollback and stayed using the latest version of my source code.
Jaydeep Barot
NextWork Student NextWork.org
Reverting a Rollback
After the rollback was completed, the appearance of my web app reverted to
the previous state, reflecting the original index.jsp file prior to any updates,
along with the previous set of image assets that were uploaded.
To update my Deploy stage to the latest version of the source code,I initiated a
change in my CodePipeline.This release ensures that the most recent version
of the source code is referenced throughout the source, build, and deploy
stages of the pipe