🔥DevOps Project : Automating Web Application Deployment with Jenkins and GitHub

🔥DevOps  Project : Automating Web Application Deployment with Jenkins and GitHub

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.

No alt text provided for this image

Use an SSH client to connect to the EC2 instance.

No alt text provided for this image

No alt text provided for this image

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

No alt text provided for this image

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

No alt text provided for this image

Install Jenkins

Update the system repository

sudo apt update

No alt text provided for this image

Install Jenkins by running

sudo apt install jenkins

No alt text provided for this image

Run the following command to see if Jenkins is set up and operating

sudo systemctl status jenkins

No alt text provided for this image

Step 3: Install Docker on the EC2 instance

Install docker using the below command

sudo apt-get install docker.io

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

Step 5:Browse to instance-public-IP/8080 to open the Jenkins dashboard.

No alt text provided for this image

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

No alt text provided for this image

Copy and paste the above password into Administrator Password and click Continue.

Install suggested plugins

No alt text provided for this image

All of the plugins that have been installed

No alt text provided for this image

Create the first administrator user

No alt text provided for this image

Jenkins installation is complete, and Jenkins is ready for use

No alt text provided for this image

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.

No alt text provided for this image

In Configure, Add a description

When it comes to source code management, Enter the URL of your GitHub repository

No alt text provided for this image

Add credentials for jenkins

No alt text provided for this image

Add the private key that we generated with the ssh-keygen command.

No alt text provided for this image

No alt text provided for this image

Choose 'Execute shell' from the Build stages

No alt text provided for this image

Run the application using Docker commands in the Execute shell

No alt text provided for this image

Clicking 'Save' will generate a Jenkins job

Click the "Build Now" button

Build is successful

Check 'Console Output'

No alt text provided for this image

No alt text provided for this image

Jenkins job creates a Github project repository in an EC2 instance

No alt text provided for this image

Jenkins pipeline is used to produce a Docker image and container

No alt text provided for this image

Search public IP addresses using port 8000

No alt text provided for this image

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.

No alt text provided for this image

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’.

No alt text provided for this image

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'

No alt text provided for this image

Do some modifications in the code

Making modifications to the file's content activates the pipeline, which builds a pipeline automatically.

No alt text provided for this image

No alt text provided for this image

Browse public IP address with port no.8000

No alt text provided for this image

ThankYou 🔥❤️

GitHub: https://github.com/Trushid

LinkedIn: www.linkedin.com/in/trushid-hatmode