DevOps Automation using Docker , Jenkins and Git/Github
This project uses DevOps tools for continuous development, continuous integration and continuous deployment.We have to configure Jenkins in such a way that whenever any code change is done and pushed on github then github will trigger it to Jenkins and Jenkins run the jobs on it's own
A step-by step process for the project is described below:
- First of all we have create a git repository locally and on the GitHub. Git and GitHub. We already have master branch created so we have to create an additional branch so in my case I have created dev1 branch.
- Now we have to create a hook which is present in the folder .git/hooks/. Now in that we have to create a file named post-commit which will automate all the operations after commit has been made so in my case I have added the git push command and the github url and token which will automatically trigger Jenkins whenever there will be a commit made. All the code in post-commit file should be written in bash script format.
NOTE: We don't have to create separate hooks for branches one hooks file will look for both my master as well as dev1 branch.
- Now create a html or txt file and make changes from dev1 branch and add this file and commit changes. As soon as you will commit changes it will automatically get pushed to the origin(remote repository).
- Now we have to create jobs in Jenkins, here in my case I have created three jobs in Jenkins:
- Job1: My job1 name is Developer. It checks the dev1 branch in the GitHub that is it will keep an eye on the dev1 branch and will report jenkins as soon as there is commit made in the git and starts a docker image (OS) which is the testing environment . It will check the changes in dev1 branch and will trigger Testing job once the testing is successful.
2. Job2: My job2 name is Production . It keeps an eye on the master branch in the GitHub and start a docker image (OS) . It will check for any changes made in master branch.In this job we are creating a production environment that will be exposed to the clients
3. Job3: My job3 name is testing . this job is created to merge the two branches (dev1 and master branch) only when the dev1 branch is completely tested then this on successful testing of this job will merge the two branches and will trigger the Production job that is job2 to display the content to the clients.
- A sample is shown below:
This is a basic website (as I am not a Web developer) before doing any changes in any branches.
As soon as I commit any changes in my txt file locally on git , the changes goes to GitHub causing Jenkins to start, making Developer job to run first then Testing job and if the previous job is successful then finally Production job.
Developer (job) -------------------> Testing(job)--------------------->Production(job)
if successful if successful
If all the jobs executes successfully then the website will have some changes such as: (in my case I have written docker github jenkins integration)
Also, when Developer job, runs if the previous container is running then first it will be destroyed and a new one will start.
Future Scope : This project can be further extended by integrating some more tools or more automation like kubernetes ,openshift and providing a better infrastructure to the setup that how can it's efficiency be increased.
Thank you Vimal Daga Sir for giving us a nice mini project on automation.
Associate @JP Morgan Chase and Co. | CIB Technology
4 年Inspiring