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

Devops Practical

1. The document describes setting up a Git repository on GitHub for a DevOps software architecture lab project. 2. It includes instructions for creating a GitHub account, creating a new repository, uploading files to the repository, and checking that the files are committed. 3. The document also covers creating, checking out, and merging branches in the Git repository, including instructions for checking the existing branches, creating a new branch, and checking out or merging to other branches.

Uploaded by

Ranbhir Kapoor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Devops Practical

1. The document describes setting up a Git repository on GitHub for a DevOps software architecture lab project. 2. It includes instructions for creating a GitHub account, creating a new repository, uploading files to the repository, and checking that the files are committed. 3. The document also covers creating, checking out, and merging branches in the Git repository, including instructions for checking the existing branches, creating a new branch, and checking out or merging to other branches.

Uploaded by

Ranbhir Kapoor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

GURU NANAK DEV ENGG COLLEGE

PRACTICAL FILE

Bachelor’s of Information Technology

DevOps :Software Architecture Lab


(LPCIT-115)
G

C
Submitted by: Submitted to :
Aditya Kumar 2021007 ; 2004882 Pf .Kamaljit Kaur

Aditya Sehgal 2021133 ; 2004883

Ajit Kumar 2021008 ; 2004884

Aman Bijalwan 2021009 ; 2004885

Index
S.N PRACTICAL NAME DATE SIG P A
O N GE
NO
1 Install GIT 4-6

2 Create account on GITHUB 7-9

3 Create Repository using GIT/GITHUB 10-12

4 Create/Delete/Merge Branches 13-15

5 Install Jenkins 15-25


6 Create Jobs on Jenkins 26-31

7 Integrate Jenkins with GIT/GITHUB 32-35


8 Install Docker 36-37

9 Deploy Nginx Web Server Image on 38-39


Docker
10 Deploy Apache Web Server Image on 40-41
Docker
11 Create Custom page using Web server 42-43
12 Create Custom image 44-45

13 Push Custom Image to Docker Hub 46


14 Use persistent storage with Docker 47

Practical 1

● Install Git

Installing Git on your computer can be done in a few simple steps:

1.Visit the official Git website at https://git-scm.com/downloads and


download the appropriate version of Git for your operating system. Git is
available for Windows, Mac, and Linux.

2.Once the download is complete, run the installer and follow the on-screen
instructions. The installer will guide you through the installation process and
allow you to customize certain options. Allow the app to make changes to
your device by clicking Yes on the User Account Control dialog that opens.

3. The installer will ask you for an installation location. Leave the default, unless you
have reason to change it, and click Next.

4.During the installation, you will be prompted to choose the default editor
for Git. You can choose your preferred text editor, such as Sublime Text,
Atom, or Visual Studio Code, or you can use the default editor provided by
Git.

3. Once the installation is complete, you can open a terminal or command


prompt and verify that Git has been installed by typing git --version. This
command should output the current version of Git that you have installed.

PRACTICAL2

● Create account on GITHUB

Creating an account on GitHub is a straightforward process that can be


completed in a few easy steps:

1. Open your web browser and navigate to the GitHub website at https://
github.com/.

2. Click the "Sign up" button in the top-right corner of the page.

3. Enter your preferred username, email address, and a strong password.


Alternatively, you can sign up with your existing Google account by clicking

4. Choose your plan. GitHub offers both free and paid plans, depending
on your needs. If you're just getting started, the free plan should be
sufficient.

5. Complete the security verification process by solving the CAPTCHA

puzzle.

6. Click the "Create account" button to create your account.

7. Verify your email address by clicking the link in the confirmation email
that GitHub sends to the email address you provided during the signup
process.

8. Once your email address has been verified, you can log in to your
GitHub account and start using it to host and manage your code
repositories.

That's it! You've now successfully created an account on GitHub and can
start exploring all of its features and functionality.

PRACTICAL 3
● Create Repository using GIT/ GITHUB
1. After successfully setting up GitHub account login to your account.
You will see the screen as below.

2. Click on the new repository option.

3. After clicking new repository option, we will have to initialize some


things like, naming our project, choosing the visibility etc. After
performing these steps click Create Repository button.

4. After clicking the button, we will be directed to below page. Right now
the only file we have is a readme file.

5. Now click on the “Upload files” button.


6. Follow the steps mentioned in the Picture below and click “commit
changes”

7. Now you will see that all of our files uploaded in our github

Practical No 4

● Create/Delete/Merge Branches

A branch represents an independent line of development. Branches serve as an


abstraction for the edit/stage/commit process. You can think of them as a way to
request abrand new working directory, staging area, and project history. New
commits are recorded in the history for the current branch, which results in a fork
in the history of the project.

Branching means you diverge from the main line of development and continue to do
work without messing with that main line. In many VCS tools, this is a somewhat
expensive process, often requiring you to create a new copy of your source code
directory, which can take a long time for large projects.

1. Checking for the existing branches : Use the command git branch . This will
fetch the list of all existing branches present in your git repository. Below we
haveonly have branch existing in the repository i,e main branch.

2. Creating a new branch : Using the command git branch , followed by the name
of the branch , we can create a new branch in a repository

3. Checking out to a new branch : The git branch option creates a new branch but
in order to start working on it, we need to checkout to that branch. This can be

achieved by using the command git checkout followed by the name of the branch
you want to checkout on to.
4.

5.Merging to existing branches : After we are done working on different aspects


of a project on individual branches , they need to be combined by git merge :

6.Deleting a branch : To delete an existing branch , we follow the command git


branch
-d followed by the name of the branch . This deletes the file from the local repository
.

Practical No 5

● Install Jenkins

Jenkins is one of the most popular open source automation server solutions for
continuous integration and continuous delivery on any platform. As a Java
application, Jenkins has many plugins for automating almost everything at the
infrastructure level.The use of Jenkins has widely increased in the developer
community due to this rich set of functionalities, which it provides in the form of
plugins.

By installing Jenkins, teams can then start using Jenkins at scale to incorporate
automation into their development cycles for improving code quality and getting
immediate feedback. This is truly the way to shift left and introduce agility in your
development lifecycle.
Install Jenkins on Windows

1. 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.

2. Once the download is complete, run the jenkins.msi installation file.


3. The setup wizard starts. Click Next to proceed.

4. Select the install destination folder and click Next to continue.

5. 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. Click Test Credentials to verify the login data, then click
Next to proceed.

6. 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.

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

8. Select the featuíes you want to install with Jenkins and click Next to
continue.

9. Click Install to start the installation process.

10. Once the installation is complete, click Ïinish to exit the install wizaíd.

UNBLOCK JENKINS

After completing the installation process, you have to unblock Jenkins before you can
customize and start using it.

1. In your web browser, navigate to the port number you selected during the
installation using the following address:

http://localhost:[port number]

2. Navigate to the location on youí system specified by the Unblock Jenkins


3. Open the initialAdminPasswoíd file using a text editoí such as


Notepad.
4. Copy the passwoíd fíom the initialAdminPasswoíd file.

5. Paste the passwoíd in the Administíatoí passwoíd field on the


Unblock Jenkins page andclick Continue to píoceed.

CUSTOMIZE JENKINS

Once you unlock Jenkins, customize and píepaíe the


Jenkins enviíonment.

1 Click the Install suggested plugins button to have Jenkins automatically install
the most fíequently used plugins.


2. Afteí Jenkins finishes installing the plugins, enteí the íequiíed


infoímation on the Cíeate Ïiíst Admin Useí page. Click Save and
Continue to píoceed.

3. On the Instance Configuíation page, confiím the poít numbeí you want
Jenkins to use and click Save and Ïinish to finish the initial customization.

4. . Click the Staít using Jenkins button to move to the


Jenkins dashboard.

Once you click on start using Jenkins, you will be redirected to the
dashboard screen as shown.

This completes the installation and setup process and we can now proceed to
create a new job on jenkins


Practical 6

● Create Job on Jenkins

Steps to create a job on Jenkins:

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

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

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

Step 4: 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

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

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

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

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

Step9: 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 6.9: Execution Of Build Step 10: Click on the Console Output link to see the
details of the build.

Practical 7

● Integrate Jenkins With Git/Github

Step 1: 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).

Step 2: 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.

Step 3: 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.

Step 4: 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:

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

Step 6: Build the Jenkins Job Manually


Step 7: 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:

Practical 8

● Install Docker

Docker is an open-source project for automating the deployment of applications as


portable, self suffi- cient containers that can run on the cloud or on-premises. Following
are the steps to install docker:

Step 1: 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.

Step 2: 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 3: Follow the instructions on the installation wizard to authorize the installer and
proceed with the install.

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

Step 5: 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.

Practical 9
Deploy Nginx Web Server Image 0n Docker

Step 1: 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:

Step 2: Inspect Images:


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

Step 3: 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).

Step 4: Start the Container:


Let’s start the container and see what happens.

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

Practical 10

Deploy Apache Web Server Image On 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 1: 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.

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

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

Step 4: 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.

Step 5: 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.

Practical 11

Create Custom Page Using Web Server


Step 1: Start the Container:
Let’s start the Nginx container and see what happens.

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

Step 2: 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 11.3: Modifying Container


Step 3: 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:

Practical 12

● 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 1: 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:

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

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

Step 4: 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.

Step 5: 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.

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

Practical 13

● 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 1: First login to Docker Hub using your username and password when prompted. Use
following command: docker login -u <username>

Step 2: Build your docker image. Step 3: Push image to Docker Hub

Step 4: 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:

Practical 14

● 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.

You might also like