Introduction
Welcome to this comprehensive guide where we'll walk through the process of creating a CI/CD pipeline for deploying a Todo List web app using AWS DevOps services. This tutorial is designed to be beginner-friendly, providing detailed steps for setting up CodeCommit, CodeBuild, CodeDeploy, and CodePipeline. We'll be installing Nginx and deploying a Todo List web app on an EC2 instance.
Code
All the required code is available at this repository.
Step 1: Setting Up CodeCommit
Create a CodeCommit Repository:
Create IAM User and Generate Credentials:
Clone Repository Locally:
Create Project Files:
git add .git commit -m "Initial commit"git push origin main
Step 2: Configuring CodeBuild
- Create a Build Project:
# buildspec.yamlversion: 0.2phases: install: commands: - echo Installing Nginx... - sudo apt-get update - sudo apt-get install nginx -y build: commands: - echo Build started on `date` - cp index.html /var/www/html/ - cp styles.css /var/www/html/ - cp app.js /var/www/html/ - cp appspec.yml /var/www/html/ post_build: commands: - echo Restarting Nginx...artifacts: files: - index.html - appspec.yml - scripts/** - app.js - styles.css
Configure Artifacts:
Run the Build:
Step 3: Implementing CodeDeploy
Create CodeDeploy Application:
Create Deployment Group:
Install CodeDeploy Agent on EC2 Instance:
#!/bin/bash # This installs the CodeDeploy agent and its prerequisites on Ubuntu 22.04. sudo apt-get update sudo apt-get install ruby-full ruby-webrick wget -y cd /tmp wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb mkdir codedeploy-agent_1.3.2-1902_ubuntu22 dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22 sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/ sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb systemctl list-units --type=service | grep codedeploy sudo service codedeploy-agent status
- Create appspec.yaml and Scripts:
appspec.yaml:
# appspec.yamlversion: 0.0os: linuxfiles: - source: / destination: /var/www/html/hooks: AfterInstall: - location: scripts/install_nginx.sh timeout: 300 runas: root ApplicationStart: - location: scripts/start_nginx.sh timeout: 300 runas: root
install_nginx.sh
# scripts/install_nginx.sh#!/bin/bashapt-get updateapt-get install nginx -y
start_nginx.sh
# scripts/start_nginx.sh#!/bin/bashservice nginx start
Build and Deploy:
Configure EC2 Role:
Restart CodeDeploy Agent:
Step 4: Setting Up CodePipeline
Conclusion
Congratulations! You've successfully set up a CI/CD pipeline for deploying a Todo List web app using AWS DevOps tools. This tutorial has covered each step in detail, providing you with a solid foundation for implementing similar projects in the future.
Follow me on LinkedIn.
Checkout my GitHub profile.
Top comments (0)