Project 1 — DevOps
Project Description
The objective of this initiative is to streamline the construction, evaluation, and deployment procedures for a web application through the utilization of Jenkins and GitHub. The integration will involve automatic triggering of the Jenkins pipeline via GitHub webhook whenever modifications are made to the code repository. The pipeline will encompass key stages, including building, testing, and deploying the application, and will incorporate notifications and alerts to promptly address any unsuccessful builds or deployments.
Lets start.
Step 1:
As part of requisite we need EC2 instance who has Jenkins and docker alredy installed on it.
Go to aws console and create new EC2 instance as Jenkins server.
Step 2:
Connect to instance using SSH client and install necessary software like Java, Jenkins and docker.
Will create shell script as below and install all necessary software in one go.
Add the executte right to file and trigger the install.sh file.
Step 3:
Verify the installation and Jenkins and docker service.
Step 4:
Add our user and Jenkins user to the Docker group
Step 5: Enable port 8080 of default port of jenkins in security group.
Step 6 : Generate SSH Keys
Generate SSH keys for Jenkins-Git integration using the command
Step 7: Setup Jenkins.
Navigate the Jenkins dashboard at instance-public-IP/8080
.
Access the path /var/lib/jenkins/secrets/initialAdminPassword for initial admin password and paste here and click on continue button.
Install suggested plugins in next step.
In next stage will create first admin user.
We are all good now with Jenkins setup and ready to build CI/CD.
Step 8: Create new project (node-todo-project) as free-style project
Will create credentials by providing private key generated in step 4.
In build steps, will select 'Execute shell' and run Docker commands.
Save the configuration and build now.
We have successfully run the docker container with jenkins and able to access code using public-ip:8000
Step 9: GitHub Webhook Integration.
goto github account and navigate setting option.
Click on SSH and GPG Keys and provide public key which was generated in Jenkins server.
Post saving configuration, we could see like below.
Step 10: Set up GitHub webhook
Go to Git-Hub repository setting- > Webhooks->Add Webhook
Enter Jenkins environment URL with "/github-webhook/" at the end in payload URL.
Post all successful setting we could see green tick mark in payload link as below
Step 11: Install GitHub Integration Plugin in Jenkins.
Goto Jenkins->Dashboard->manage jenkins->Plugin.
Search for Github Integration plugin in available plugin and install it.
Step 12: Configure Jenkins for GitHub Integration.
In build triggers, select 'GitHub hook trigger for GITScm polling.'
Step 13: we are all good to test integration. Will make correction in git hub repository and check whether Jenkins start building the project automatically.
In below step i have made change in line #90 and changed background color for home-page.
Let commit the changes and check Jenkins build status.
We can see project build automatically started and successfully completed. in console output we could see build triggered by GitHub push.
Lets verify the changes.
The project deployment has been accomplished successfully, incorporating GitHub with Jenkins. This integration enables the automatic initiation of the project build and deployment processes, with the flexibility for manual intervention as needed.
I hope this article helpful for your future reference.
Thanks,
Kishor Chavan