Day 80: Streamlining CI/CD Pipelines for Dockerized Apps on AWS EC2 Instances with Jenkins
Are you looking to automate your deployment process for Docker applications hosted on AWS EC2 instances? In this guide, we'll walk through the steps to set up a seamless CI/CD pipeline using Jenkins, integrating GitHub webhooks, and ensuring your application updates go live effortlessly.
Let's dive in:
AWS Setup:
Head to the AWS portal and create a new EC2 instance:
Name: jenkins-server
AMI: Ubuntu
Instance type: t2.micro
Key pair login: Create > docker.pem
Allow HTTP and HTTPS access
SSH Connection:
- Connect to your EC2 instance via SSH using the generated key pair.
Jenkins Installation:
Install Jenkins and Java. Follow the official Jenkins documentation for Linux installation.
Docker Installation:
Install Docker on the EC2 instance using:
sudo apt install docker.io
Security Group Configuration:
Allow inbound traffic on ports 8080 and 8001 in the EC2 instance's security group.
Access Jenkins:
Access Jenkins by navigating to the EC2 instance's public IP address followed by port 8080 in your browser
Initial Setup:
Retrieve the initial admin password from the Jenkins server.
Install suggested plugins and set up the admin user.
CI/CD Pipeline Setup:
Create a new item in Jenkins for your project (e.g., todo-app).
Configure source code management to connect to your GitHub repository.
Add build steps to build Docker images and run containers.
GitHub Integration:
Install the Git Integration plugin in Jenkins.
Add an SSH key to your GitHub account for authentication.
Configure a webhook in your GitHub repository settings, pointing to your Jenkins server's webhook URL.
Automated Deployment:
Enable GitHub webhook trigger for GitScm polling in your Jenkins project settings.
Test Deployment:
Make changes to your code, commit, and push to GitHub.
GitHub webhook triggers Jenkins to run the pipeline automatically.
Your updated application is deployed seamlessly to your EC2 instance.
By following these steps, you can establish a robust CI/CD pipeline for deploying Docker applications on AWS EC2 instances using Jenkins. This automation ensures that every code change you make is swiftly reflected in your live web application, streamlining your development and deployment workflow.
Subscribe to my newsletter
Read articles from Vedant Thavkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vedant Thavkar
Vedant Thavkar
"DevOps enthusiast and aspiring engineer. Currently honing skills in streamlining development workflows and automating infrastructure. Learning AWS, Docker, Kubernetes, Python, and Ansible. Eager to contribute and grow within the DevOps community."