The project aims to automate the building, testing, and deployment process of a web application using Jenkins and GitHub. The pipeline will include stages such as building, testing, and deploying the application.
Prerequisites
Minimum hardware requirements:
256 MB of RAM
1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)
Software requirements:
Linux OS
Web browser
Java should be installed.
Install Java
sudo apt update
sudo apt install openjdk-17-jre
java --version
Install Jenkins
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
systemctl status jenkins
Install Docker
sudo apt install docker
systemctl status docker
Note
Create a CI/CD Pipeline
Go to the link- localhost:8080.
If you are accessing Jenkins on EC2 instance then don't forget to change security settings by allowing IP access to port 8080.
Access the password using the cat command on the Shel terminal of the local machine or EC2 instance.
Install suggested Plugins
The installation will start.
Complete installation by filling the basic personal information.
A Welcome page will open.
Click on New Item
Enter the item name, select --> Pipeline & Click OK
Enter the description if any & project link to GitHub where the project is stored.
Enter the rest of the details and set the cron job in "Build periodically"
Scroll down and define Groovy scripts to create a pipeline.
pipeline {
agent any
stages{
stage("code"){
steps{
git branch: 'main', url:'https://github.com/AminChivilkar/react_django_demo_app.git'
}
}
stage("build & test"){
steps{
echo "Testing"
script{
sh "docker build --no-cache -t react_django_app ."
}
}
}
stage("deploy"){
steps{
echo "Run Docker Container"
script{
sh "docker run -p 8001:8001 -d react_django_app"
}
}
}
}
}
Once the changes are saved, click on "Build Now"
During the build, we encountered an error
Error - "permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "
This means that Jenkins has no access to docker. To solve the problem, we will add Jenkins to the docker.sock
sudo chown jenkins /var/run/docker.sock
Once done, we can then run the pipeline.
The pipeline has been created successfully.
You can check the app on the browser with the port- 8001
Go to- localhost:8001
We have successfully coded, built and deployed an application using pipeline.
Conclusion:
In this blog, we have covered the setup of a Jenkins pipeline for CI/CD. It began with prerequisites, installation, and plugin configuration. A Groovy script defined the pipeline along with an encountered Docker permissions error which was later resolved.
The result is a functional Jenkins pipeline for automated software development and deployment. Streamlining the development process is now at your fingertips.
Hope you like my post. Don't forget to like, comment, and share.