CI/CD Pipeline (Integration of Jenkins, Docker and GitHub): Task2
Continuous integration (CI) is a software engineering practice where members of a team integrate their work with increasing frequency. In keeping with CI practice, teams strive to integrate at least daily and even hourly, approaching integration that occurs “continuous-ly.”
Historically, integration has been a costly engineering activity. So, to avoid thrash, CI emphasizes automation tools that drive build and test, ultimately focusing on achieving a software-defined life cycle. When CI is successful, build and integration effort drops, and teams can detect integration errors as quickly as practical.
Continuous delivery (CD) is to packaging and deployment what CI is to build and test. Teams practicing CD can build, configure, and package software and orchestrate its deployment in such a way that it can be released to production in a software-defined manner (low cost, high automation) at any time.
High-functioning CI/CD practices directly facilitate agile development because software change reaches production more frequently. As a result, customers have more opportunities to experience and provide feedback on change.
In this project, I've used integration of GitHub (SCM tool), Jenkins (management tool), and docker (container tool) to deploy the application in web server.
Dockerfile: I have first build an image using dockerfile with jenkins and git preinstalled so that as soon as we launch any docker container using this image, the jenkins services would automatically start.
FROM centos RUN yum install sudo -y RUN yum install wget -y RUN yum install curl -y RUN yum install git -y RUN sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo RUN rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key RUN yum install java -y && yum install jenkins -y RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL">> /etc/sudoers CMD ["java", "-jar", "/usr/lib/jenkins/jenkins.war"]
Now to build the image, use the command
docker build -t task2/jenkins .
Once this docker image created, we can run docker commands inside the container and launch jenkins. Here I've used 'docker.sock file' to make docker commands executable and expose the container on port 8080.
docker run -dit --name jen1 -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker task2/jenkins
Using build pipeline plugin I have created a chain of all the following jobs so that it all the jobs run after the successful completion of the previous job and hence become easy to manage.
JOB 1: Pull the GitHUb repo automatically when some developers push repo to gGitHub. Here the pulled code is copied in '/var' folder of the base container. In my case, I've used remote URL trigger to trigger the job as soon as the code is launched to GitHub.
JOB 2: Job 2 will run as soon as job 1 is successfully done. By looking at the code or program file, jenkins should automatically start the respective language interpreter (in my case PHP) and deploy the code to the web server.
JOB 3: This job triggers and test the application if it is working or not. It monitors and keeps a check on the interpreter and if due to some reason the container stops, it starts the container again.
JOB 4: This job ensures if the application is working properly on the web server. If the application is not working, then it will send an email to developer.
At last. i would like to thank Vimal Daga sir for his guidance and motivation.
Any advice and suggestions are greatly appreciated..