Integration of Git, Github, Jenkins and Docker for Developer
This article is more about automation which mainly must require in production. Different tools were integrated to ensure the manual efforts kept at a minimum. This project consists of four jobs, that we are going to discuss further in step-by-step.
It is assumed that the pre-requisites of this project such as Git, Jenkins, Docker are already installed in RedHat Enterprises Linux(RHEL).
Job 1 : If the Developer commits the code/file to the master branch in GitHub, Jenkins will fetch from the master branch, ask the Docker to launch the environment (OS) and deploy it on the master-Docker environment.
To fulfill this job, we have to build a trigger that automatically sends the file to GitHub when a developer commits the code/files in Git. Post-commit is used to perform this operation. The below images clearly explains about the Post-Commit.
Now, the webpage will be automatically deployed in a web server after the developer commits the file.
After it uploaded to Github, Jenkins copy the file in the master branch to a Base OS directory and further it will be copied to the master-docker environment's folder /usr/local/apache2/htdocs/, it is known that only the file in this directory can be deployed to the webpage.
These are done by creating two items in Jenkins namely "getfromgit" and "deployment". the pro file is already created in RHEL Linux in /root/pro location. "getfromgit" item is created mainly for copying the webpage from GitHub to base OS /root/pro location.
Then "deployment" item is mainly created for launching the container for a master branch in which the webpage is copied from base OS to this container's /usr/local/apache2/htdocs/ location and deployed in master container's webserver using the specified port number. This item is to be triggered by "getfromgit" item.
These processes are visualized in real-time with the necessary details by using the delivery pipeline plugin. The images given below clearly shows that the items run successfully.
Job 2: If the Developer commits the code/file to the dev1 branch in GitHub, Jenkins will fetch from the dev1 branch, ask the Docker to launch the environment (OS) and deploy it on dev1-Docker environment.
This Job2 is same as the Job1, the only change we have to make is to change the branch from master to dev1 in Jenkins. Remaining are the same as we did for Job1. The images given below will clearly show about the job2.
Job2 consists of two items namely "dev" and "devdeployment". "dev" item is mainly for copying the webpage from GitHub to dev folder in RHEL which is already created by the user. The "devdeployment" item is used to launch the container for the dev1 branch and copying the file from the dev1 folder to container's /usr/local/apache2/htdocs/ location, since the file in this location can only deploy in the webserver.
The trigger used in this item is Github hook trigger and post-build is done for the next job "merge".
Job 3: Quality Assurance team will check/test for the website which is running in a dev1-docker environment. If it is running fine then Jenkins will merge the dev1 branch to the master branch.
For achieving this, in Git publisher we approved Push only If Build Succeeds, Merge results and Force push and we entered master as a branch to push and Target remote name as an origin. Kindly refer below images for a clear understanding of this job.
Thus merging is successfully done after got approval by the Quality Assurance team automatically.
Job 4: After merging, there will be no use for the dev1-docker environment. It has to be destroyed to save RAM/CPU resources. It will be triggered by job 3 that is after merging, it will be destroyed.
Thus the whole processes are visualized by delivery pipeline plugin and it is attached below for a clear understanding of these processes.
This project is done under the guidance Mr.Vimal Daga Sir as an outcome of my DevOps Assembly Lines Training under him. This is one of the tasks given by Vimal Sir in this training. It was a great experience, I learned a lot by doing this project.
I realized that "When we have interest, knowledge, perseverence and not afraid of any problems, we can do any wonder". These are the words from our former President Dr.A.P.G. Abdul kalam.
Software Engineer at Capgemini | Javascript | React JS | 73k+ @LinkedIn | Typescript | Angular | Frontend Developer | Generative AI | Machine Learning | Artificial Intelligence
4yGaurav Patel
SDE 1 @ Amazon || Morgan Stanley || TrustBook || IASc || NESAC (ISRO)
4yWell done Sri Vishnuvardhan 😄