DevOps Automation 2

→WHAT IS THE PROJECT?
TOOLS USED — GIT, JENKINS, DOCKER
Problem Statement-
- JOB1: Pull the GitHub repo automatically when some developer commits.
- JOB2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed)
- JOB3: Test your application if it is working or not.
- JOB4: If the application is not working, then send an email to the developer with an error message and if it is running file send a success message.
- JOB5: To monitor the container where the application is hosted, fails due to any reason then this job will automatically start the container again.

First Create DockerFiles for 3 different image requirements-
- Dockerfile for Jenkins image

~Here, CentOs image is taken and git, python, sudo, net-tools, and similar essential tools are to be downloaded.
~Also, install Jenkins and grant Sudo powers to Jenkins user. Also, add the command to start Jenkins services automatically as soon as the container is launched.
2.Dockerfile for Html image

~Here also, CentOs image is taken and important packages are downloaded and HTTPS service will start after the container is launched.
3.Dockerfile for PHP image

~Same piece of image and packages from the HTML image and PHP package is also added.
- I’ve passed -y option in every command to ignore user prompt while downloading.
- The final output of all images after build —


JOB1-
→This job will pul the code from the GitHub and store it in the Host system in the specified folder.




Poll SCM will always monitor the Git repository and pull the code instantly after code is pushed in GitHub.

JOB2-
→This job will detect the code and will launch a docker container accordingly.
->If HTML code is pulled from Git then html_img image and if PHP code is copied then php_img image will be used




- >This job is chained to job1. So, it’ll automatically run just after a successful build of job1.



JOB3-
→This is the main job!! This is a chained job with upstream job-2 and will trigger after a successful build of job2.
→Here, the HTTP status code of the webserver is used and passed in the condition.
->The status code is to be stored in a variable through the output of the curl command.




- >Also, Jenkins mail plugin can be used to send customized mail notification.

-Jenkins is a third party application and will be considered as a third-party application for a google account. Create a 16 digit password and provide it to Jenkins.
- Add POST BUILD ACTION and select MAIL NOTIFICATION and add the recipient mail address.



JOB4-
→This is an independent job that will continuously monitor the Jenkins container and launch one new container if the running one is failed due to any reason!!


THAT’S IT !! AUTOMATIC JENKINS PIPELINE SET UP IS DONE.
FUTURE SCOPE — INTEGRATING THIS PIPELINE WITH MULTIPLE DOCKERFILES AND LAUNCH DIFFERENT OS ACCORDING TO REQUIREMENT ON THE FLY!

GitHub URL for reference — https://github.com/poojan182/jenkins-pipeline
THANKS A LOT FOR YOUR ATTENTION FOR SO LONG!!