DevOps Automation

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 

No alt text provided for this image
  • Then I pushed the complete repo containing two branches on Github
git push --set-upstream origin master
git push --set-upstream origin dev

No alt text provided for this image
  • 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.
No alt text provided for this image
  • 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
No alt text provided for this image
  •  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

No alt text provided for this image
No alt text provided for this image
  • 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".
No alt text provided for this image
  • Next, I generated a taken to trigger the build remotely using curl command
No alt text provided for this image
  • 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
No alt text provided for this image
  • After this I used "post-build" option to build other project i.e, master_docker.
No alt text provided for this image
No alt text provided for this image
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.
Gaurav Tikam

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 )

Kapil Meena

Software Engineer @ Rapyuta Robotics || NIT-B'2023

4 年

Great ??????

Atul Yadav

Android Developer | 4+ Years | Kotlin, Java, Jetpack, MVVM, Firebase, REST APIs | Open to Work

4 年

That's very nice

要查看或添加评论,请登录

Gaurav Yadav的更多文章

  • Hosting Wordpress on AWS with maximum Security

    Hosting Wordpress on AWS with maximum Security

    Task Write a Infrastructure as code using terraform, which automatically create a VPC. In that VPC we have to create 2…

    2 条评论
  • Jenkins Automation Using Groovy

    Jenkins Automation Using Groovy

    In this tutorial I tried to Show how to use Groovy script to build a Jenkins pipeline. Groovy is suitable for beginners…

    1 条评论
  • Deploying Prometheus and Grafana over Kubernetes

    Deploying Prometheus and Grafana over Kubernetes

    Task: Creating Docker images for Prometheus & Grafana. Deploying Prometheus & Grafana as pods on top of Kubernetes by…

  • Setting Up WordPress On AWS Using Amazon EKS

    Setting Up WordPress On AWS Using Amazon EKS

    Tasks: Kubernetes Cluster using AWS EKS. Integrate EKS with EC2,EBS,LB,EFS.

  • Deploying Openstack on AWS

    Deploying Openstack on AWS

    Probably everyone with OpenStack hands-on experience would agree that sometimes it could be hard and frustrating to…

    3 条评论
  • Kubernetes deployment and Monitoring using Jenkins

    Kubernetes deployment and Monitoring using Jenkins

    Task: Using Jenkins Server on Rhel, Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in…

    1 条评论
  • Number Plate Detection With Supervise.ly

    Number Plate Detection With Supervise.ly

    What is Supervisely? There are many open-sourced implementations of state of the art neural network architectures. But…

    8 条评论
  • Infrastructure as Code with AWS and Terraform

    Infrastructure as Code with AWS and Terraform

    For This Task, I first created an Amazon Machine Image(AMI) from an instance in which I configured Jenkins and Apache…

    20 条评论
  • CI/CD Pipeline Using Kubernetes

    CI/CD Pipeline Using Kubernetes

    Task Description 1. Create container image that’s has Linux and other basic configuration required to run Slave for…

    4 条评论
  • Hyperparameter Tuning using MLOps

    Hyperparameter Tuning using MLOps

    The percentage of AI models created but never put into production in large enterprises has been estimated to be as much…

    2 条评论

社区洞察

其他会员也浏览了