Automation:Integrating jenkins_Docker_Github

Automation:Integrating jenkins_Docker_Github

Jenkins is an open source automation server with an unparalleled plugin ecosystem to support practically every tool as part of your delivery pipelines. Whether your goal is continuous integrationcontinuous delivery or something else entirely, Jenkins can help automate it.jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project ,and making it easier for users to obtain a fresh build.

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

GitHub is a Git hosting repository that provides developers with tools to ship better code through command line features, issues (threaded discussions), pull requests, code review, or the use of a collection of free and for-purchase apps in the GitHub Marketplace. With collaboration layers like the GitHub flow, a community of 15 million developers, and an ecosystem with hundreds of integrations, GitHub changes the way software is built.

GitHub builds collaboration directly into the development process. Work is organized into repositories, where developers can outline requirements or direction and set expectations for team members. Then, using the GitHub flow, developers simply create a branch to work on updates, commit changes to save them, open a pull request to propose and discuss changes, and merge pull requests once everyone is on the same page.

  • In this project you will learn how to automate web page deployment and hosting using jenkins and docker.

Description About Project:

Pre-requisite for doing this project-

Jenkins and Docker are intalled in RHEL OS
Jenkins is added in sudoers file
Users has a Github profile and Git bash is intalled

Step 1: Create a local repo in Git bash .

Create a hook.for this,create a post-commit file in .git/hooks/directory,it will automatically push the code automatically to github from local repository when developer commit that file.Create post-commit as

cd .git/hooks/
vim post-commit

and write code as -
#!bin/bash
git push

Step 2: Create a repo in Github.

No alt text provided for this image

Step 3: Create a container image that has jenkins installed and some other files using Dockerfile.

No alt text provided for this image

Step 4: Build the Container image using Dockerfile-.

docker build -t 7007457627/jenkins:v1 /root/workspace

Step 5: Launch OS from this image

Now, when we launch OS from the image that we have created, it automatically creates container and starts jenkins server in the container. For launching OS, run the command and mount some directories so that the data can be persistent -

 docker run -dit --name  -P -v/root/jenkins-docker/:/root/.jenkins/ 
        -v /var/run/docker.sock:/var/run/docker.sock           
        -v   /root/task2:/root/task2 jenkins:v1

Run docker ps command to check on which port no ,container is running.

No alt text provided for this image

Step 6:Login in Jenkins WebUI in browser

when you launch the image you will get the password required for jenkins when you login and then copy the password and paste it below administrator password field to unlock jenkins.

After Sucessfully Login ,you can now automate your work

No alt text provided for this image

Step 7: job1_pull_repo:pull the github repo automatically when developers push some code.

No alt text provided for this image

Now, enable Poll SCM in this job and write the schedule as - " * * * * * " and save the job.

Poll SCM means , it goes to Github every minute & checks the new commits, whenever the developers pushes new commits from git to Github, it pulls that commits & saves that in its workspace .

No alt text provided for this image


Step 8:job2_deploy:Create second job to deploy the code and start the containers

By looking the code or program file,jenkins automatically copy the the respective html file to the required environment which is image container to deploy code sand start launching .ex-If code is php,then jkenkins should start the container that has php already installed.

No alt text provided for this image
No alt text provided for this image

Step 9: job_testing:Test your app if it is working fine move ahead if it gives error then this job failed and triggered next job (job4) to notify the developer about code.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 10: job4_notify:Create a job if app is not work ing,then send e-mail to developer with error messages.

No alt text provided for this image

Step 11:Monitor:create a fifth job to check the repective containers are running or not

if container where app is running fails due to any reason then this job should automatically start the container again.

No alt text provided for this image
No alt text provided for this image

Step 12 : create a build pipeline-

Create a Build Pipeline and select job1_pull_repo as initial job. Build Pipeline is a visualized tool for upstream and downstream jobs.

To create Build Pipeline, first install ' Build Pipeline ' plugin for it.

No alt text provided for this image
No alt text provided for this image

See in the pipeline, that first job (job1_pull_repo), second job (job2_deploy), third job (job3_test) are executed but fourth job (job notify) not. This is because the deployed code is working -

  • And the five jobs are-
No alt text provided for this image

!Thanks for reading......



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

Emad Khan的更多文章

  • MACHINE LEARNING _DEVOPS INTEGRATION

    MACHINE LEARNING _DEVOPS INTEGRATION

    End to End Automation using jenkins and Docker_Container While Training a Machine or Deep learning model it is the most…

  • End to End Automation

    End to End Automation

    One great automation using Github,Docker and jenkins which is replica of real industry production and developer…

    2 条评论

社区洞察

其他会员也浏览了