Task 2: DevOps Assembly Line
Hello guys here is my task 2 assignment of DevOps assembly line training.
Tools Used :- Jenkins, Git, Github, Docker
Task:-
1. Create container image that’s has Jenkins installed using dockerfile
2. When we launch this image, it should automatically starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push 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 app is not working , then send email to developer with error messages.
8. Create One extra job job5 for monitor : If container where app is running. fails due to any reson then this job should automatically start the container again.
Steps 1:to create Jenkins docker container image
create Dockerfile file same as below
after this build Docker container image using below command
docker build -t jenkins:v1 .
Note :- Before run above command goto directory where Dockerfile is placed.
2) Steps to setup Jenkins
step 1) launch docker container image
docker run -it -p 8080:80 --name jenkins jenkins:v1
step 2) check your jenkins image IP using
docker inspect jenkins | grep IP
copy IPAddress and paste it to browser url
http://{IPAddress}:port
after this copy Administrator password from terminal from where you launch docker image and paste it.
To change password goto: ManageJenkins -> Manage Users -> press setting icon -> goto password section and set new password
Steps to download some plugins required in this task
Download below plugins from Manage Jenkins -> Manage Plugins -> Available tab -> search below plugins and tick mark -> Install Without restart -> After this click on restart after install checkbox.
Build Pipeline Plugin, Email Extension Plugin, Git plugin, GitHub plugin,
Publish Over SSH, SSH Agent Plugin, SSH Build Agents plugin, SSH Pipeline Steps, SSH plugin, SSH2 Easy Plugin
To configure SSH service in Jenkins goto Manage Jenkins -> Configuration system -> SSH remote hosts -> set hostname(IP address of your base os) and ssh port(22) of your base OS.
To configure E-mail Notification goto Manage Jenkins -> Configuration system -> E-mail Notification ->
SMTP server : smtp.gmail.com
Use SMTP Authentication: allow
User Name: Email address
Password: email password
Use SSL: allow
SMTP Port: 465
Publish over SSH configuration
Steps to implement Job 1
Create new Job named as Job1 from New Item section and select Free style project and press OK to confirm
In Job1 we are going to configure SSH to connect with our base system to perform various tasks and configuring git/Github to clone project automatically when some new commit is done on repository and then whole project will be copy to base OS at /data1 directory.
After this click on job1 and goto Configure section and setup everything same as below
Now Apply changes and press Save.
Steps to implement Job2
In Job2 we are checking /data1 directory which is copy of our repository contents. Here we checking extension of files and match with according to requirements
For example :- ls /data | grep .php -> if this output is matched then we will launch new container image which helps to depoly php page.
Create Job2 same as Job1 but configuration will be same as below :
Now press save to apply new changes.
Steps to implement Job3 & Job4
According to Job3 we are testing our App by checking its status using
status=$(curl -o /dev/null -s -w "%{http_code}" 172.17.0.3:80)
here 172.17.0.3:80 is IP and Port of my PHP container image.
Email will notify if Build is failed.
Follow below steps to configure Job3.
Steps to implement Job5
Here we check deploy container image is running or not if container image is down then this job will restart container image.
Steps to configure Job5
This build periodically will check in every 5 min container is running or not.
Steps to implement Build Pipeline plugin
Click on + icon
Enter Project name and tick Build Pipeline View then apply and save
Build pipeline View will look same as below