Table of contents
- 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, with notifications and alerts for failed builds or deployments.
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, with notifications and alerts for failed builds or deployments.
Steps:
Step1:Launch an EC2 instance with below Jenkins/docker installation script.
#!/bin/bash
sudo apt-get update
sudo apt install default-jre
sudo apt install default-jdk
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
sudo sh -c '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 -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo apt-get install docker.io -y
sudo usermod -aG docker jenkins
sudo systemctl start docker
sudo systemctl enable docker
Check status of jenkins/docker if running or not.
Once done with installations open port 8080 security group
Step2:Try to access public IP 3.83.153.244:8080
Unlock Jenkins by below key
Create credentials for 1st time user
Good to go with Jenkins now!
Step3:generate keys by ssh-keygen
This will generate public and private keys in the machine.
Id_rsa – Private Key.
Id_rsa.pub – Public Key.
Step4:Navigate to manage jenkins and under available plugins search for github integration as we need this plugin for the integration with github(our code is in github)
Install without restart
Check download progress
Step5:Now move back to our problem statement for project
Select new item like below
Select project type:Freestyle project
Provide 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, with notifications and alerts for failed builds or deployments.
Step6:Code is available on github copy code url and put under project url
Step7:Build step:
Docker build: docker build -t django-notes-app (-t--tag)
Docker run: docker run -d -p 8000:8000 django-notes-app (-d=detach modei.e.runs in background,-p=port expose,8000=port number,Django-notes-app=image of the name)
Step8:Successful Build...!!!
Open port number 8000 under the security group and access public ip
Access your public IP now:54:227:159:62:8000
Finally Here is the output:
Step9:Now lets move to the CICD part
This is to autotrigger the builds if any changes in code we do not have to trigger manually.
cd .ssh -->>ssh-keygen-->>put this key ubuntu@ip-172-31-26-35:~/.ssh$ cat id_rsa.pub
Setting-->>and generate Personal access token this we can provide in jenkins under secret text
Step10:Add this secret key in jenkins under secret
Select this option to trigger the build after code change in git it will reflect
Step11:Navigate to setting-->>webhook-->>54.227.159.62:8080/github-webhook
Webhooks can be triggered whenever specific events occur on GitHub. For example, you can configure a webhook to trigger whenever: Code is pushed to a repository.
Make sure if success as it will show green arrow
Step11:Make some changes in code and see if build gets triggered or not.
Below I have changed dockerfile and commited the changes
Step12:Build triggered by its own
Step13:Final output
Django:notes app deployed successfully..!!
Code availability -github:https://github.com/gsbarure/django-notes-app.git
Linkdin:https://www.linkedin.com/in/gajanan-barure-7351a4140
***Happy Learning :)***✌✌
Keep learning,Keep growing🎇🎇
Thank you for reading!! Hope you find this helpful.
#day81#90daysofdevops#devopscommunity#