0% found this document useful (0 votes)
5 views

devopsfile practicals file

The document is a practical guide for a Bachelor of Technology course in Information Technology, detailing steps for various DevOps practices including installation of Git, Docker, and Jenkins, as well as creating and managing repositories and containers. It covers topics such as deploying web servers, creating custom images, using persistent storage, and integrating Jenkins with GitHub. Each section provides step-by-step instructions accompanied by figures to illustrate the processes involved.

Uploaded by

nextstep013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

devopsfile practicals file

The document is a practical guide for a Bachelor of Technology course in Information Technology, detailing steps for various DevOps practices including installation of Git, Docker, and Jenkins, as well as creating and managing repositories and containers. It covers topics such as deploying web servers, creating custom images, using persistent storage, and integrating Jenkins with GitHub. Each section provides step-by-step instructions accompanied by figures to illustrate the processes involved.

Uploaded by

nextstep013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

DEVOPS: SOFTWARE ARCHITECTURE

Practical File

BACHELOR OF TECHNOLOGY
Information Technology

Submitted By: Submitted To:


Harsh Mishra Pf. Harjot Kaur
Class: D3 IT A2
University Roll no. 2004924

GURU NANAK DEV ENGINEERING COLLEGE


LUDHIANA-141006, INDIA
Contents
1 Install Git 1

2 Create Account on GITHUB 3

3 Create Repository on GIT/GITHUB 4

4 Create, Merge and Delete Branch 7

5 Install Docker 9

6 Deploy Nginx Web Server Image 0n Docker 11

7 Deploy Apache Web Server Image 0n Docker 13

8 Create Custom Page Using Web Server 15

9 Create Custom Image 17

10 Push Custom Image to Docker hub 19

11 Use Persistent Storage with Docker 20

12 Install Jenkins 21

13 Create Job on Jenkins 26

14 Integrate Jenkins With Git/Github 32


1 Install Git
Step 1: Go to https://git-scm.com/downloads.

Step 2: Click the download link for Windows and allow the download to complete.

Figure 1.1: Download GIT

Figure 1.2: Installation

1
Figure 1.3: Installation in progress

Figure 1.4: GIT installed

2
2 Create Account on GITHUB
Step 1: Go to github.com.

Step 2: Go to sign up or register and make your account.

Figure 2.1: github

Figure 2.2: Sign up

Step 3: Sign up is complete, you can start working on your account.

3
3 Create Repository on GIT/GITHUB
Step 4: Go to github.com and login your account.

Figure 3.1: Login github

Step 5: Go to your profile and click repository > New.

Figure 3.2: New repository


Step 6: Give a repository name and select if you want it public or provide.Also you can add some de-
scription if you want.

Figure 3.3: Naming Repository

Step 7: Now click on the CREATE REPOSITORY button.

Figure 3.4: Create Repository

5
Step 8: You have successfully created a repository.

Figure 3.5: Your Repository

6
4 Create, Merge and Delete Branch
CREATE BRANCH:

Go to main branch on your repository and create a sub-branch.

Figure 4.1: Create branch

MERGE BRANCH:

Step 1: Go to the branch on your repository .

Figure 4.2: Branch

7
DELETE BRANCH:

Step 1: Go to branches.

Figure 4.6: Branches

8
5 Install Docker
Docker is an open-source project for automating the deployment of applications as portable, self
sufficient containers that can run on the cloud or on-premises. Following are the steps to install
docker:

Step 9: Double-click Docker Desktop Installer.exe to run the installer. If you haven’t already downloaded
the installer (Docker Desktop Installer.exe), you can get it from Docker Hub. It typically down-
loads to your Downloads folder, or you can run it from the recent downloads bar at the bottom
of your web browser.

Figure 5.1: Install Docker

Step 10: When prompted, ensure the Use WSL 2 instead of Hyper-V option on the Configuration page is
selected or not depending on your choice of backend.

Step 11: Follow the instructions on the installation wizard to authorize the installer and proceed with the
install.

Figure 5.2: Unpacking files

9
Step 12: When the installation is successful, click Close to complete the installation process.

Figure 5.3: Complete Installation

Step 13: If your admin account is different to your user account, you must add the user to the docker-users
group. Run Computer Management as an administrator and navigate to Local Users and Groups
> Groups > docker-users. Right-click to add the user to the group. Log out and log back in for
the changes to take effect.

Figure 5.4: Ready to use


6 Deploy Nginx Web Server Image 0n Docker
Step 14: Create a Base Container:
Let’s get started by creating a running container. So that we don’t get bogged down in the details
of any particular container, we can use nginx.
Here we have requested a new container named nginx base with port 80 exposed to localhost.
We are using nginx:alpine as a base image for the container.
If you don’t have the nginx:alpine image in your local docker image repository, it will download
automatically. When this happens, you will see something like this:

Figure 6.1: Creating base container

Step 15: Inspect Images:


If you look at the list of images on your system, you will now see the nginx:alpine image:

Figure 6.2: Inspecting Images

Step 16: Inspect Containers:


Note here that the container is not running, so you won’t see it in the container list unless you
use the -a flag (-a is for all).

Figure 6.3: Inspecting Containers

11
Step 17: Start the Container:
Let’s start the container and see what happens.

Figure 6.4: Starting Container

Now visit http://localhost with your browser. You will see the default “Welcome to nginx!” page.
We are now running an nginx container.

Figure 6.5: Running Container

12
7 Deploy Apache Web Server Image 0n Docker
Apache web server is popular open source http web server tool which is widely used for deployment
of webpages. It can be installed in any operating system. We can create any Apache web server
image in two ways.

Step 18: Download the Docker image, which contains Apache called httpd, by running the docker pull
command below. This command will download or pull the Apache image from the Docker
registry, as shown below.

Figure 7.1: Downloading Docker Image

Step 19: Next, confirm you’ve downloaded the image by running the docker images command below to
list all images available on your computer.

Figure 7.2: Checking images

Step 20: Invoke the docker run command to create a new container based on your downloaded Apache
Docker image.

Figure 7.3: Running Container

Step 21: Once the Apache container is running, verify if you can access the Apache web interface by
navigating to Public-Ip-address:80 using your web browser. If you can see the same message, as
you can see below, then you’ve successfully started your Apache Docker container.

13
Figure 7.4: Apache Container

Step 22: Finally, stop the container if you don’t need it running anymore by running the docker stop
command below. This command will gracefully stop the container instance.

Figure 7.5: Stopping Container

14
8 Create Custom Page Using Web Server
Step 23: Start the Container:
Let’s start the Nginx container and see what happens.

Figure 8.1: Starting Container

Now visit http://localhost with your browser. You will see the default “Welcome to nginx!” page.
We are now running an nginx container.

Figure 8.2: Running Container

Step 24: Modify the Running Container:


So if you wanted to modify this running container so that it behaves in a specific way, there are
a variety of ways to do that.
In order to keep things as simple as possible, we are just going to copy a new index.html file onto
the server. You could do practically anything you wanted here.
Let’s create a new index.html file and copy it onto the running container. Using an editor on
your machine, create an index.html file in the same directory that you have been running Docker
commands from.

Figure 8.3: Modifying Container

15
Step 25: Create an Image From a Container:
So at this point, we’ve updated the contents of a running container and as long as we keep that
container around, we don’t need to do anything.
However, we want to know how to save this container as an image so we can make other containers
based on this one. The Docker commands to do this are quite simple.
To save a Docker container, we just need to use the docker commit command like this:

Figure 8.4: Creating an Image From a Container

16
9 Create Custom Image
In order to run your application in a docker container, a customized docker image is created.
This customized docker image includes instructions that install specific packages and copy the
code into the docker container. This guide describes the basic steps to create a custom docker
image.

Step 26: First we have to create a base container. The following command will create a base container
if the nginx version is latest otherwise it will automatically pull latest version of nginx from
DockerHub:

Figure 9.1: Creating Base Image

Step 27: Now we can see that our container is running using the docker ps -a command:

Figure 9.2: Inspecting Container

Step 28: Then we have to create a commit for the running container to save it as an image.

Figure 9.3: Committing Container

Step 29: Then we see our images list. You can see there is a new image and it does not have a repository
or tag, but it exists. This is an image created from the running container.

17
Figure 9.4: Image list

Step 30: When we made the commit, it created an image without a tag or name. You’ll see an image
listed with ¡none¿ as both the ID and name.Using docker tag, we can name the image we just
created.

Figure 9.5: Tagging Image

Step 31: .Now, if you issue the command docker images, you’ll see your new image with the name my-
customimg.

Figure 9.6: Inspecting Image

18
10 Push Custom Image to Docker hub
By pushing an image to the Docker hub registry, we can create an instance of an image in which
a particular type of software and applications are pre-installed and can be pulled again whenever
you want to work on that particular type of image or applications and run that kind of virtual
machine.

Steps to push custom images to docker hub

Step 32: First login to Docker Hub using your username and password when prompted. Use following
command: docker login -u <username>

Step 33: Build your docker image.

Step 34: Push image to Docker Hub

Figure 10.1: Pushing Image

Step 35: Add Additional Tags to Your Docker Image You often want to include tags like version in addition
to the latest tag. To add a version tag you write the following commands:

Figure 10.2: Docker Image

19
11 Use Persistent Storage with Docker
In docker, the persistent storage is dealt with the volume concept. Persistent storage is means
when we are stopping or removing the container the data should be persistent. It will not delete
automatically once the docker container is not available. We can define the persistent storage
layer while launching the docker container. Once it will define, the actual data will be store
on the external storage layer which is not a part of the docker environment. The storage layer
will be on the host machine, remote machine, on the cloud, etc. Before directly going to the
docker persistent storage, we need to first understand the storage layer availability on the docker
platform. It will help to understand the storage layer concept.

We are having the list of docker images. The docker images are available on the docker hub.
If we need to create our own images then we can also build a new or own image. Please note,
while creating the new image, we need to choose the respective base image like centos, Ubuntu,
windows, etc. Once the image is ready, we can run the container in the docker. If we are normally
running the container without any storage definition then the docker data is in a volatile state. In
the docker, there are three different ways that the data will be store. 1. bind mounts 2. volumes
3. in-memory storage (tmpfs)

Bind mounts: The bind mounts are a very older method to mount the file or the directory to the
docker container. The bind mount is having limited functionality as compared to the volume.
When we are using the bind mount method, we are using the local file or the local directory to
the docker container. We need to define the complete path of the local file or the local directory
of the local machine into the docker container. While working with the bind mounts, we need to
rely on the local machine file structure. We need to follow the set of rules and regulations which
is imposed on the local system.

Volumes: The volume storage is also known as the persistent data storage layer of the docker.
The default path for the docker volume is /var/lib/docker/volumes. Whenever we are creating
or associating the volume to the docker container. The volume will by default store on the
“/var/lib/docker/volumes” path. Volume is very easier to mount or for the migration. If we are
deleting the docker container but the volume is still present on the storage layer. Then the same
volume we can use for the next or the different docker container. It will use the same data which
was previously used by the older container.

In-memory storage (temporary storage file): When we are launching the docker container without
defining the storage layer like mount or volume. The docker container will run under the in-
memory storage file system. It will store the data temporarily. Once we are deleting or stopping
the respective docker container the data will vanish. The working data is not present in it. We
need to rerun or load the data one more time if we need to work on the same docker container.
In the docker environment, we are able to add persistent storage to the docker image.

Figure 11.1: Persistent Storage With Docker

20
12 Install Jenkins
Jenkins is an open-source automation server developers can use to automate building, testing,
and deploying applications. It is available on a variety of systems, including Windows, Linux,
Unix, and macOS. Steps to install Jenkins:

Step 36: Browse to the official Jenkins download page. Under the Downloading Jenkins section is a list of
installers for the long-term support (LTS) version of Jenkins. Click the Windows link to begin
the download.

Figure 12.1: Downloading Jenkins

Step 37: Once the download is complete, run the jenkins.msi installation file.

Step 38: The setup wizard starts. Click Next to proceed.

Figure 12.2: Downloading Complete

21
Step 39: Select the install destination folder and click Next to continue.

Figure 12.3: Install Folder

Step 40: Under the Run service as a local or domain user option, enter the domain username and password
for the user account you want to run Jenkins with or go for the localsystem option. Then click
Next to proceed.

Figure 12.4: Run services

22
Step 41: Enter the port number you want Jenkins to run on. Click Test Port to check if the selected port
is available, then click Next to continue.

Figure 12.5: Port Testing

Step 42: Select the directory where Java is installed on your system and click Next to proceed.

Figure 12.6: Java Directory

23
Step 43: Select the features you want to install with Jenkins and click Next to continue.

Figure 12.7: Selecting Features

Step 44: Click Install to start the installation process.

Figure 12.8: Installation Started

24
Step 45: Once the installation is complete, click Finish to exit the install wizard.

Figure 12.9: Installation Complete

25
13 Create Job on Jenkins
Steps to create a job on Jenkins:

Step 46: Go to the Jenkins dashboard and Click on New Item.

Figure 13.1: Click New Item

Step 47: In the next screen, enter the Item name, in this case we have named it Helloworld. Choose the
‘Freestyle project option’

Figure 13.2:Freestyle Project Option

26
Step 48: The following screen will come up in which you can specify the details of the job

Figure 13.3: Specify Job Details

Step 49: We need to specify the location of files which need to be built. In this example, we will assume
that a local git repository(E:) has been setup which contains a ‘HelloWorld.java’ file. Hence scroll
down and click on the Git option and enter the URL of the local git repository

Figure 13.4: Git Repository

27
Step 50: Now go to the Build section and click on Add build step → Execute Windows batch command

Figure 13.5:Build Step

Step 51: In the command window, enter the following commands and then click on the Save button. Javac
HelloWorld.java Java HelloWorld

Figure 13.6: Click Save

28
Step 52: Once saved, you can click on the Build Now option to see if you have successfully defined the job.

Figure 13.7: Click Build Now

Step 53: Once the build is scheduled, it will run. The following Build history section shows that a build
is in progress.

Figure 13.8: Build In Progress

29
Step 54: Once the build is completed, a status of the build will show if the build was successful or not. In
our case, the following build has been executed successfully. Click on the 1 in the Build history
to bring up the details of the build.

Figure 13.9: Execution Of Build

Step 55: Click on the Console Output link to see the details of the build.

Figure 13.10: Project Hello Job


Figure 13.11: Console Output

31
14 Integrate Jenkins With Git/Github
Step 56: Create a Jenkins job, You now need to create a Jenkins job. To do so, click New Item (1). Or,
if it’s a clean install, click on create new jobs (2).

Figure 14.1: Click New Item

Step 57: Use a GitHub Repository Scroll down a bit more and you’ll see the Pipeline section, where we’ll
tell Jenkins to use the GitHub repo as the source. In the Definition dropdown, choose Pipeline
script from SCM to configure the repo.

Figure 14.2: Build Triggers


Step 58: Configure the GitHub Hook Trigger In the screen you see now, scroll down a little to the Build
Triggers section. We’re going to make sure that this Jenkins job runs only when someone pushes
a change in the GitHub repo. You can configure other actions, like when someone creates a
pull request. But for simplicity’s sake, we’ll stick with the push action only. Of course, you
can always run the job manually, but that’s not ideal. So, choose the GitHub hook trigger for
GITScm polling option.

Figure 14.3: Configure Github Hook Trigger

Step 59: Add a Webhook in Github Now, go to the GitHub project because it’s time to configure the
webhook so that GitHub can trigger the Jenkins job after every push in the repo. In your
project, click on the Settings (1) tab, then click Webhooks (2) from the left panel. Now, click on
the Add webhook (3) button at the right. Here’s a screenshot for reference:

Figure 14.4: Add Webhook

33
Step 60: Now go to the Build section and click on Add build step → Execute shell

Figure 14.5: Build Step

Step 61: Build the Jenkins Job Manually

Figure 14.6: Building Job Manually

34
Step 62: Change Something in the GitHub Repo. You finished the integration with GitHub in the previous
step. But because you and I are good citizens, let’s make sure that this integration works fully.
So, go to the GitHub repository and change something, commit, and push. In my case, I added a
new stage in the Jenkins pipeline to include more tests. Wait for a few seconds, and you should
see another successful run of the job. If you go the logs for the second time the job ran, you’ll
notice something different at the beginning of the logs saying that GitHub started it, along with
the username:

Figure 14.7: Console Output

35

You might also like