🔥DevOps Project : Automating Web Application Deployment with Jenkins and GitHub
Table of contents
- Project Description
- Step1: Create an EC2 instance.
- Step 2: Install jenkins on AWS EC2 Ubuntu instance.
- Step 3: Install Docker on the EC2 instance
- Step 4:
- Step 5:Browse to instance-public-IP/8080 to open the Jenkins dashboard.
- Step 6: Create a freestyle project
- Task 2:
- Step 1: Configuring GitHub
- Step 2: For GitHub-Webhook
- Step 3: For Installing GitHub Integration plugin in Jenkins
- Step 4: Configuring Jenkins
Project Description
The project aims to automate the building, testing, and deployment process of a web application using Jenkins and GitHub. The Jenkins pipeline will be triggered automatically by GitHub webhook integration when changes are made to the code repository. The pipeline will include stages such as building, testing, and deploying the application.
Step1: Create an EC2 instance.
Use an SSH client to connect to the EC2 instance.
Step 2: Install jenkins on AWS EC2 Ubuntu instance.
Install Java
Jenkins requires the Java Runtime Environment (JRE).
To install OpenJDK 11, run:
sudo apt install openjdk-11-jdk -y
Add Jenkins Repository
Start by importing the GPG key. The GPG key verifies package integrity but there is no output.
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Add the Jenkins software repository to the source list and provide the authentication 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
Install Jenkins
Update the system repository
sudo apt update
Install Jenkins by running
sudo apt install jenkins
Run the following command to see if Jenkins is set up and operating
sudo systemctl status jenkins
Step 3: Install Docker on the EC2 instance
Install docker using the below command
sudo apt-get install docker.io
check docker is installed and running using the command
sudo systemctl status docker
also check version of docker using command:
docker --version
Add your user to the docker group:
sudo usermod -a -G docker $USER
This command adds your current user to the docker group, which grants permission to access the Docker socket.
Add the Jenkins user to the docker group:
sudo usermod -a -G docker jenkins
This command adds the Jenkins user to the docker group, which grants permission to access the Docker socket
Step 4:
Generate the SSH keys for integrating your Jenkins project with your git repository. Use ssh-keygen command to create public and private key.
For jenkins, port 8080 is used
To add port 8080 to an instance, you must enable port 8080 traffic in the instance's security group and configure the instance's firewall to allow port 8080 traffic.
Step 5:Browse to instance-public-IP/8080 to open the Jenkins dashboard.
To access this, we'll need an Administrator Password. Enter the password in the terminal using the command below.
cat /var/lib/jenkins/secrets/initialAdminPassword
Copy and paste the above password into Administrator Password and click Continue.
Install suggested plugins
All of the plugins that have been installed
Create the first administrator user
Jenkins installation is complete, and Jenkins is ready for use
Step 6: Create a freestyle project
Click the 'New Item' button on the left sidebar of the Jenkins dashboard
Name your project and choose "Freestyle project" as the project type.
In Configure, Add a description
When it comes to source code management, Enter the URL of your GitHub repository
Add credentials for jenkins
Add the private key that we generated with the ssh-keygen command.
Choose 'Execute shell' from the Build stages
Run the application using Docker commands in the Execute shell
Clicking 'Save' will generate a Jenkins job
Click the "Build Now" button
Build is successful
Check 'Console Output'
Jenkins job creates a Github project repository in an EC2 instance
Jenkins pipeline is used to produce a Docker image and container
Search public IP addresses using port 8000
Task 2:
The Jenkins pipeline will be triggered automatically by GitHub webhook integration when changes are made to the code repository.
Step 1: Configuring GitHub
Go to your GitHub account settings
Navigate to SSH and GPG keys. Add the public key that we generated with ssh-keygen and choose the key type Authentication key.
Step 2: For GitHub-Webhook
Go to your GitHub repository and click on Settings.
Click on Webhooks and then click on Add webhook
In the ‘Payload URL’ field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/. In the ‘Content type’ select: ‘application/json’.
Webhook is Added
Step 3: For Installing GitHub Integration plugin in Jenkins
Open your jenkins dashboard
Click on the Manage Jenkins button on your Jenkins dashboard
Click on Manage Plugins
Install GitHub Integration plugin
Step 4: Configuring Jenkins
In build Triggers, select 'Github hook trigger for GITScm polling'
Do some modifications in the code
Making modifications to the file's content activates the pipeline, which builds a pipeline automatically.
Browse public IP address with port no.8000
ThankYou 🔥❤️
GitHub: https://github.com/Trushid
LinkedIn: www.linkedin.com/in/trushid-hatmode