This repository provides a guide and configuration files to set up a local Continuous Integration/Continuous Deployment (CI/CD) pipeline using Git, Jenkins, and Docker on an Ubuntu EC2 instance. The pipeline is designed to automatically build and deploy a Dockerized Python web application whenever changes are pushed to the associated Git repository.
-
EC2 Instance: Create an Ubuntu EC2 instance on AWS.
-
Docker Installation: Install Docker on the Ubuntu instance using the provided script.
curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh
-
Java Installation: Install OpenJDK 17 (Java Runtime Environment).
sudo apt install openjdk-17-jre
-
Jenkins Installation: Set up Jenkins on the instance.
# Add Jenkins Repository to Sources List echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null # Update and Install Jenkins sudo apt-get update sudo apt-get install jenkins
if the above installtion doesn't work, get the recent release installation guide from jenkins documentation.
-
Firewall Configuration: Allow traffic on port 8080 for Jenkins, SSH connections, and port 8000 for container communication.
sudo ufw allow 8080 sudo ufw allow OpenSSH sudo ufw allow 8000 sudo ufw enable -
Jenkins Configuration:
- Start Jenkins service and check its status.
- Retrieve the initialAdminPassword for Jenkins setup.
sudo systemctl start jenkins.service sudo systemctl status jenkins sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Docker Hub Account: Create a Docker Hub account and login to Docker on the Ubuntu instance.
sudo docker login -u <username> -p <password>
-
Jenkins-Docker Integration: Add the Jenkins user to the docker group for Docker access.
sudo usermod -aG docker jenkins sudo systemctl restart jenkins
-
Open
<Public_IP_Address_of_EC2_Instance>:8080in a browser. -
Log in with the initialAdminPassword obtained earlier.
-
Install suggested plugins and set up a new username and password.
-
Setup credentials in Jenkins, including Docker Hub username and password.
-
Make necessary changes in the Jenkinsfile, setting credentials id and Docker username.
-
Create a pipeline in Jenkins, specifying the GitHub repository and branch.
-
Build the pipeline to execute the defined stages.
-
Open
<Public_IP_Address_of_EC2_Instance>:8000in a browser to view the application.
To see the pipeline in action, make changes to the hello.html file in the templates folder of the repository. Commit the changes, and within a minute, the updates should reflect on the end page.