Automation of Git-Jenkins-Docker
Problem Statement :
1. Create a container image that’s has Jenkins installed using Dockerfile.
2. When we launch this image, it should automatically start the Jenkins service in the container.
3. Create a job chain of job1, job2, job3, and job4 using the build pipeline plugin in Jenkins.
4. Job1: Pull the GitHub repo automatically when some developers push the repo to GitHub.
5. Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
6. Job3: Test your app if it is working or not.
7. Job4: If the container where the app is running. fails due to any reason then this job should automatically start the container again
✨Let's start with the workflow for this task:
So we will start by creating a Dockerfile using centos: latest image pulled from docker hub.
FROM: Used for the image to be used for container
RUN: Use this RUN commands to be executed while building the modified container
CMD: the CMD used here will keep the Jenkins live till the container is on and will start on container boot.
After this Build your own image:
docker build -t jenkin:latest
On successful build, you will get this screen:-
All the steps are done of building the images , after this, we have to use this image to make a container,
docker run -it --name os3 --privileged -p 8765:8080 -v /root/workspace:/root/workspace jenos:v1
This cmd will make your container running,
After is use you IP and 8765 to launch Jenkins:-
Paste the password in this and your Jenkins is ready to use:-
Now we will be moving on to our jobs.
Jobs are created in this container and the necessary plugins like Build pipeline, Git, GitHub are installed.
This is the dashboard of Jenkins
- JOB 1
Pull the GitHub repo automatically when some developers push the repo to GitHub.
2. JOB 2:
By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
3. JOB 3
Test your app if it is working or not.
4. JOB 4:
If the container where the app is running. fails due to any reason then this job should automatically start the container again.
After this install BUILD PIPELINE to look your all jobs systematic:
Our task of automation of Docker-Jenkins-Git is complete and whenever there are failures or shortcomings, Jenkins jobs will notify us and the necessary action can be taken. It also monitors the container for whether its running or not!
Future Scope:
- Deploying a suitable environment based on the code pushed by the developer. Here we would have to pull the suitable image from Dockerhub based on the interested file's extension.
- All the work is done with Jenkins no manual work is to be done.
Well done
Very well written Arshit 👌 Keep doing the great work