DevOps Automation
The project I made completely automates the Continuous Integration and Continuous Deployment of a web server using Git , Jenkins and Docker. The setup uses complete Automation and runs the website on a server as soon as the developer commits it on Git.
- For this Project 1st I made a Git repo locally and added an extra branch named dev.
git checkout -b dev
- Then I pushed the complete repo containing two branches on Github
git push --set-upstream origin master git push --set-upstream origin dev
- After that I wrote a post-commit bash script to push the code after every commit to Github and trigger build remotely. I used ngrok to tunnel the Jenkins Ip through a public IP.
- If Developer push to dev branch then Jenkins will fetch from dev and deploy on dev-docker environment . If Developer push to master branch then Jenkins will fetch from master and deploy on master-docker environment.
#!/bin/bash if git branch --show-current | grep dev then git push curl --user "admin:root" https://8e99b8fe.ngrok.io/job/project/build?token=dev else git push --set-upstream origin master curl --user "admin:root" https://8e99b8fe.ngrok.io/job/project/build?token=master fi
- In Jenkins I made different jobs for Testing environment i.e. dev and Public site i.e. master.
sudo cp -rvf * /root/ws3 # copied files from jenkins to my workspace
- I used Job chaining to create and run the web server as soon as the initial job of copy is successful
# for testing environment if sudo docker ps | grep dev_docker then echo "Already Running" else sudo docker run -dit -p 8082:80 -v /root/ws3:/usr/local/apache2/htdocs/ --name dev_docker httpd fi # for public server if sudo docker ps | grep master_docker then echo "Already Running" else sudo docker run -dit -p 8081:80 -v /root/ws3:/usr/local/apache2/htdocs/ --name master_docker httpd fi
- After that I made a job so that Jenkins will check (test) for the website running in dev_docker environment. If it is running fine then Jenkins will merge the dev branch to master branch then Jenkins will fetch from master and deploy on master_docker environment.
- For this we have to first add the credentials of our github in a new job. Then , in the additional behavior panel we have to select "merge before build".
- Next, I generated a taken to trigger the build remotely using curl command
- Now, if the testing container is running, it is to be deleted and if it's not there, a message is to be printed. for this i wrote a bash script.
#!/bin/bash if sudo docker ps | grep testenv then sudo docker rm -f testenv else echo "container removed" fi
- After this I used "post-build" option to build other project i.e, master_docker.
In this project,I automated a system such that if a developer does some upgrading in a seperate branch and commits it, it will run in the test environment where it gets checked by the quality management team and if work passes all quality norms, a token will be triggered by Quality management team, that will trigger another job which merges the developer branch to master branch and update the main branch to the main environment and destroy the testing environment.
Digital Transformation Lead | Hyperscalers Practices/ Cloud Transformation /Apps Modernization /Devops Engagement /Site Reliability Engineering Practitioner
4 年Gaurav here you not created any job 3 as sir told. means in your scenario developer do all task is he push to dev branch dev environment run viceversa for master also There is no QAT role you implement means if QAT Team pass devloper code from dev branche then it goes to prod environment. (here need to use merge )
Software Engineer @ Rapyuta Robotics || NIT-B'2023
4 年Great ??????
Android Developer | 4+ Years | Kotlin, Java, Jetpack, MVVM, Firebase, REST APIs | Open to Work
4 年That's very nice