End to End INTEGRATION Of Docker, Jenkins, Github, Git, Redhat

End to End INTEGRATION Of Docker, Jenkins, Github, Git, Redhat

DevOps task2 

Let us first understand what we are going to do in this task.

Task description

1. Create container image that’s has Jenkins installed using docker file

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 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 app is not working, then send an email to the developer with error messages.

8. Create One extra job job5 for monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again.

Let us begin our journey

Create a container image that’s has Jenkins installed using a Dockerfile.

Before we start our job we have to create a Jenkins image using Dockerfile. As we launch the image your Jenkins server start. This means as we launch the docker image, your Jenkins service starts.

All the codes related to the creation of the docker images are present in this screenshot.

No alt text provided for this image

Now once your docker image is ready we start to perform our task.

Set Jenkins after launch

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

Job1

Pull the Github repo automatically when some developers push the repo to Github. The job says that as you some developer share the code/push the code to the GitHub, then Jenkins will go and download the code. This is possible due to the remote trigger we use in the job1. Due to the remote Jenkins will know that some things change in your particular Github repository. 

Once the Jenkins will pull the code, then we execute some code in the shell.

This code tells that, go and remove the folder(folder name = task2) if present, and create one folder and after the folder has been created, copy the code that we pull from the Github.

But we have to configure ssh because we want to create a copy of the folder that should present in the base operating system.

For ssh configuration, we have to install ssh plugins. After plugin install got to the manage credentials and set a credential for your base operating system, go to the manager Jenkins>set ssh.

No alt text provided for this image

Then configure job1

No alt text provided for this image


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

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)


The job tells that by looking to the code or program file, Jenkins will automatically launch the respective interpreter inside the docker.

Now the main, concepts start, our Jenkins is launched inside the docker and again we launch the docker where our interpreter is launch by looking to the code or program file. 

Means docker inside docker. Now, this messy, because as we launch the docker inside docker, it could not able to launch and fail.

But before we understand why it fails to launch docker inside docker, let’s check some understand some basic concepts od docker.

Whenever we launch the docker, it shares the resources(Ram, CPU, Hardisk, etc) of the base operating system where it launches. This sharing is possible because the base operating system has a socket, which has capabilities to share its own resources to the docker. 

But if we look into the docker this socket is not present. And this is the main cause of the failure of the docker inside docker.

When we try to launch docker inside docker, and due to the unavailability of the socket in docker, it is not able to launch docker inside docker. 


But according to the requirement, we have to launch a docker inside the docker. So to solve this socket problem we mount the socket of the base operating system to the inside docker container at the time of launching the container.


So what we did basically is, we mount the socket of the base operating system to the docker and your problem of launching docker inside docker will shout out.


Now,

We can perform task2 quite easily with no error.

The required code for performing the job2 is given in the screenshot

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

the code is totally based on the conditional & loops.

No alt text provided for this image


JOB3

Test your app if it is working or not.

Once our code is deployed to the website, Jenkins will check either the deploy code is working properly or not.

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


Job4: if the app is not working, then send an email to the developer with error messages.

We enable the email notification from then Jenkins so that when either of the jobs fails it will send you an email and tell your job is failed.

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

 But I would like to tell you one more thing before configuring email, the password column that is visible in the screenshot, you have to put the app password of the email, not your email password.

How to create an app password for the email?

Create & use App Passwords

Note: If you use 2-Step-Verification and are seeing a "password incorrect" error when trying to access your Google Account, an App Password may solve the problem.

Go to your Google Account.

On the left navigation panel, choose Security.

On the "Signing into Google" panel, choose App Passwords. If you don’t see this option:

2-Step Verification is not set up for your account.

2-Step Verification is set up for security keys only.

Your account is through work, school, or other organization.

You’ve turned on Advanced Protection for your account.

At the bottom, choose the Select app and choose the app you’re using.

Choose Select device and choose the device you’re using.

Choose Generate.

Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device.

Choose Done.

Once the password is created put the password created in the password column.

Job 5: Create One extra job job5 for monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again.

The job will monitor our launched container and due to any reason, if the container will fail, it will launch the container.

No alt text provided for this image

Your task is completed.

Dashboard view


No alt text provided for this image

OUTPUT

No alt text provided for this image

All the plugins installed

  • build pipeline
  • email extension
  • ssh
  • Github

This task is the integration of the docker, Jenkins, Github, git, Redhat.

Github Link: https://github.com/ankiiitt/DEVOPS-TASK2

Thank You for reading & Viewing the article.



Ajay Kumar

DevOps Engineer at SquareOps | AWS Certified Solution Architect

4 年

Great work

回复

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

Ankit Kumar的更多文章

  • How Kubernetes Is Changing The Business ????

    How Kubernetes Is Changing The Business ????

    What is Kubernetes?? ???? Kubernetes is an open-source platform for managing containers. The product is created by…

    1 条评论
  • Create CloudFront Architecture with AWS CLI

    Create CloudFront Architecture with AWS CLI

    What is AWS ? AWS is a Public-Cloud platform providing world-wide service and offer over 170 fully-featured services…

    1 条评论
  • AWS Customer Success Story

    AWS Customer Success Story

    What is Cloud Computing? The company that provides their resources over the internet and charges according to the…

  • Big Data

    Big Data

    Today is the world of data and most of the big companies like Facebook, Google, Microsoft, Netflix, Amazon, etc are…

  • Flutter Music Player

    Flutter Music Player

    This article refers to the creation of a Music App with the use of one great Platform know as Flutter. There are many…

  • Integration of Ansible with Docker

    Integration of Ansible with Docker

    This is the first task of Ansible under Mr. Vimal Daga Sir.

    1 条评论
  • FLUTTER ENVIRONMENT SETUP

    FLUTTER ENVIRONMENT SETUP

    What is Flutter? Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web,…

  • AWS + KUBERNATES = AMAZON E

    AWS + KUBERNATES = AMAZON E

    Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service. Amazon EKS automatically detects…

  • TASK 1 COMPLETE INTEGRATION OF JENKINS WITH GITHUB

    TASK 1 COMPLETE INTEGRATION OF JENKINS WITH GITHUB

    Task Description TASK 1 JOB#1 If Developer push to dev branch then Jenkins will fetch from dev and deploy on the…

  • FACE RECOGNITION USING TRANSFER LEARNING

    FACE RECOGNITION USING TRANSFER LEARNING

    Task4 Create a project using transfer learning solving various problems like Face Recognition, Image Classification…