Hey folks! ๐ Iโm super excited to share an end-to-end DevOps project I recently completed. This project ties together AWS EC2, Docker, GitHub, and Jenkins into a seamless CI/CD workflow. If you're looking for a hands-on guide with a real-world use case, buckle up. I'll walk you through every step I took, from setting up infrastructure to deploying a containerized app with Jenkins. Letโs dive in! ๐คฟ
Table of Contents
- The Idea
- Setting Up AWS EC2 Instances
- Installing Docker on the Ubuntu EC2 Instance
- Building the Ecommerce App
- Creating Repo locally and initializing on GitHub
- Pulling Jenkins and Installing Plugins
- Setting Up Jenkins with GitHub
- Creating a Jenkins Freestyle Pipeline
- Resolving Docker Issues
- Application Deployment
- Visualizing the Workflow
- Code and Resources
- Closing Thoughts
The Idea:
The goal was to build and deploy an ecommerce application using modern DevOps tools and practices. The process included application development, containerization, and setting up a pipeline for automated deployment.
Setting Up AWS EC2 Instances
I created two EC2 instances on AWS:
Ubuntu Instance: For running Docker and hosting the application.
Windows Instance: For developing the ecommerce app.
Both instances were provisioned with security groups to allow SSH/RDP and HTTP access.
Installing Docker on the Ubuntu EC2 Instance
To containerize and run our app, I installed Docker on the Ubuntu EC2 server. Here's the magic command I used:
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
Building the Ecommerce App
The Windows EC2 instance served as my dev environment. I developed a simple ecommerce app using Flask python. Once I was happy with the app, I pushed the code to GitHub.
Creating Repo locally and initializing on GitHub
Essentially, it is just as if you were creating your development project locally and then uploading it to Git
- Create any Repo/Project locally in VS code
- It wonโt be a part of GitHub Repo as for now
- After adding files your project and updating them we need to initialize our Repo so Git can recognize it
echo "# terraform01" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Yusra310/terraform01.git
git push -u origin main
This made my workflow a little cleaner and portable.
Pulling Jenkins and Installing Plugins
To automate the build and deployment process, I pulled the official Jenkins Docker image on the Ubuntu instance:
docker run -d --name jenkins \
-p 8080:8080 -p 50000:50000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
I accessed Jenkins through the browser
http://54.159.138.147:8080
unlocked it using the initial password, and installed the necessary plugins:
GitHub Plugin for GitHub integration.
Docker Plugin to enable Docker commands within Jenkins.
Setting Up Jenkins with GitHub
To securely integrate GitHub with Jenkins, I created a GitHub Personal Access Token. This token was added as a credential in Jenkins, allowing the CI/CD pipeline to pull code from the GitHub repository.
Creating a Jenkins Freestyle Pipeline
Hereโs the exciting part! ๐ I set up a Freestyle Jenkins pipeline for the CI/CD workflow. The pipeline:
Jenkins Shell Script:
Docker build -t ecommerce-app
Docker run -p 5000:5000 -d ecommerce-app
Resolving Docker Issues
The first pipeline run failed with an error: docker: command not found.
The issue? Docker wasnโt installed in the Jenkins container! ๐คฆโโ๏ธ
Solution: I installed Docker inside the Jenkins container and gave it access to the hostโs Docker socket. This allowed Jenkins to execute Docker commands seamlessly.
Application Deployment
With everything in place, I ran the Jenkins pipeline again and The ecommerce app was deployed and accessible in the browser at
http://54.159.138.147:5000
Visualizing the Workflow
To make things more digestible, I created a draw.io diagram that outlines the entire workflow, from code push to deployment. Here's a summary of the steps:
- Develop the app on the Windows instance.
- Push the code to GitHub.
- Jenkins pulls the code, builds a Docker image, and runs the container.
- The app is hosted on the Ubuntu EC2 instance.
Code and Resources
Iโve shared the source code, Jenkins configuration, and the draw.io diagram here on GitHub [https://github.com/Yusra310/ecommerce-app]. Feel free to check it out and try this workflow yourself.
Closing Thoughts
This project was a blast to work on! It taught me the power of automation and containerization in modern application development. If youโre just starting with DevOps, projects like this are a fantastic way to get hands-on experience.
Got questions or suggestions? Drop them in the comments below! Letโs keep building. ๐ช
Until next time, happy coding and deploying! ๐ค
Top comments (0)