DevOps Lab: Experiments Overview
DevOps Lab: Experiments Overview
Page No.
DEVOPS LAB
List of Experiments
3. Practice Source code management on GitHub. Experiment with the source code in exercise 1.
9. Automate the process of running containerized application for exercise 7 using Kubernetes.
11. Write a simple program in JavaScript and perform testing using Selenium.
12. Develop test cases for the above containerized application using selenium.
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.container {
max-width: 400px;
margin: 40px auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
}
button[type="submit"] {
width: 100%;
height: 40px;
background-color: #4CAF50;
color: #fff;
BVRIT CSE DEVOPS LAB
Roll No: Date:
Page No.
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="container">
<h2>Registration Form</h2>
<form>
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" required>
</div>
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="confirmpassword">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" required>
</div>
<button type="submit">Register</button>
</form>
</div>
</body>
Objective:
The objective of this experiment is to familiarise participants with essential Git concepts and
commands, enabling them to effectively use Git for version control and collaboration.
Git is a distributed version control system (VCS) that helps developers track changes in their codebase,
collaborate with others, and manage different versions of their projects efficiently. It was created by
Linus Torvalds in 2005 to address the shortcomings of existing version control systems.
Unlike traditional centralised VCS, where all changes are stored on a central server, Git follows a
distributed model. Each developer has a complete copy of the repository on their local machine,
including the entire history of the project. This decentralisation offers numerous advantages, such as
offline work, faster operations, and enhanced collaboration.
Git is a widely used version control system that allows developers to collaborate on projects, track
changes, and manage codebase history efficiently. This experiment aims to provide a hands-on
introduction to Git and explore various fundamental Git commands. Participants will learn how to set
BVRIT CSE DEVOPS LAB
Roll No: Date:
Page No.
up a Git repository, commit changes, manage branches, and collaborate with others using Git.
Working Directory:
The place where your project resides in your local disk. This project may or may not be tracked by git
In either case, the directory is called the working directory
The project can be tracked by git, by using the command git init. By doing git init, it automatically
creates a hidden .git folder
Staging Area:
Once we are in the working directory, we have to specify which files are to be tracked by git. We do not
specify all files to be tracked in git, because some files could be temporary data which is being generated
while execution. To add files in the staging area, we use the command git add.
Commit:
Once the files are selected and are ready in the staging area, they can now be saved in repository.
Saving a file in the repository of git is known as doing a commit When we commit a repository in git,
the commit is identified by a commit id.
Key Concepts:
● Repository: A Git repository is a collection of files, folders, and their historical versions. It contains
all the information about the project's history, branches, and commits.
● Commit: A commit is a snapshot of the changes made to the files in the repository at a specific point
in time. It includes a unique identifier (SHA-1 hash), a message describing the changes, and a
reference to its parent commit(s).
BVRIT CSE DEVOPS LAB
Roll No: Date:
Page No.
● Branch: A branch is a separate line of development within a repository. It allows developers to work
on new features or bug fixes without affecting the main codebase. Branches can be merged back
into the main branch when the changes are ready.
● Merge: Merging is the process of combining changes from one branch into another. It integrates the
changes made in a feature branch into the main branch or any other target branch.
● Pull Request: In Git hosting platforms like GitHub, a pull request is a feature that allows developers
to propose changes from one branch to another. It provides a platform for code review and
collaboration before merging
● Remote Repository: A remote repository is a copy of the Git repository stored on a server, enabling
collaboration among multiple developers. It can be hosted on platforms like GitHub, GitLab, or
Bitbucket
● git add: Stages changes for commit, preparing them to be included in the next commit.
● git commit: Creates a new commit with the staged changes and a descriptive message.
$ git commit -m "commit message"
● git status: Shows the current status of the working directory, including tracked and untracked files.
$ git status
● git log: Displays a chronological list of commits in the repository, showing their commit
messages, authors, and timestamps.
$ git log
● git merge: Combines changes from different branches, integrating them into the current branch.
$ git merge <branch-name>
● git pull: Fetches changes from a remote repository and merges them into the current branch.
Go to the repository on GitHub, select the branch you want to merge and click the "New pull
request" button.
● git push: Sends local commits to a remote repository, updating it with the latest changes.
$ git push origin <branch- name>
Materials:
$git --version
To push a repository
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.container {
max-width: 400px;
margin: 40px auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 20px;
}
button[type="submit"] {
width: 100%;
height: 40px;
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="container">
<h2>Registration Form</h2>
<form>
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" required>
</div>
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Register</button>
</form>
</div>
</body>
</html>
Step 4: Save the file
Go to file location
Now use the following commands to push file into git repository
Initialize git
$ git init
bash:
bash:
$ git status
$ git remote -v
Installing Jenkins
Jenkins is typically run as a standalone application in its own process. The Jenkins WAR file bundles
Winstone, a Jetty servlet container wrapper, and can be started on any operating system or platform with
a version of Java supported by Jenkins.
Windows
The simplest way to install Jenkins on Windows is to use the Jenkins Windows installer. That program
will install Jenkins as a service using a 64 bit JVM chosen by the user. Keep in mind that to run Jenkins
as a service, the account that runs Jenkins must have permission to login as a service.
Prerequisites
Minimum hardware requirements:
256 MB of RAM
1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a
Docker container)
4 GB+ of RAM
50 GB+ of drive space
Software requirements:
Java:
Web browser:
Windows operating system
Java Support Policy
Supported Java versions Long term support (LTS) release Weekly release
The Jenkins project produces two release lines: Stable (LTS) and weekly. Depending on your
organization's needs, one may be preferred over the other.
Stable (LTS)
Long-Term Support (LTS) release baselines are chosen every 12 weeks from the stream of regular
releases.
Jenkins is distributed as WAR files, native packages, installers, and Docker images.
After the download completes, open the Windows installer and follow the steps below to install
Jenkins.
On opening the Windows Installer, an Installation Setup Wizard appears, Click Next on the
Setup Wizard to start your installation.
When Installing Jenkins, it is recommended to install and run Jenkins as an independent windows
service using a local or domain user as it is much safer than running Jenkins using Local
System(Windows equivalent of root) which will grant Jenkins full access to your machine and
services.
To run Jenkins service using a local or domain user, specify the domain user name and password with
which you want to run Jenkins, click on Test Credentials to test your domain credentials and click on
Next.
Once your Java home directory has been selected, click on Next to continue.
Additionally, clicking on the Install button will show the progress bar of installation, as shown below:
Docker Architecture:
Docker architecture consists of Docker client, Docker Daemon running on Docker Host and
DockerHub repository.
Components of Docker
The main components of Docker include–Docker clients and servers, Docker images, Docker file,
Docker Registries, and Docker containers.
Docker run:
Run a command in a new container.
For example: $ sudo docker run --name mycontainer -it ubuntu:16.04 /bin/bash
This command runs a new container based on the Ubuntu 16.04 image and starts a shell session in
the container.
Docker start:
Start one or more stopped containers.
Docker stop:
Stop one or more running containers.
Docker rm:
Remove one or more containers.
Docker ps:
List containers.
Docker images:
List images.
Docker pull:
Pull an image or a repository from a registry.
Docker push:
Push an image or a repository to a registry.
This command pushes the image named "myimage" to the Docker Hub registry.
These are some of the basic Docker commands for managing containers and images. There are many
other Docker commands and options that you can use for more advanced use cases, such as
managing networks, volumes, and configuration.
Solution :
Create a sub folder with expt 7, in your working directory & store all the below files in subfolder.
STEP 1:
STEP 2:
Create a Docker file with the following content to create a Docker image for your Flask application:
Dockerfile
FROM python:3.13
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r [Link]
EXPOSE 5000
CMD ["python", "[Link]"]
STEP 3:
Create a [Link] file with the following content to list the dependencies of your Flask
application:
[Link] :
Flask==2.3.2
Jinja2>=3.1
itsdangerous>=2.1
Werkzeug>=2.3
[Link] :
from flask import Flask, request, render_template
app = Flask( name )
@[Link]('/register',methods=['GET', 'POST'])
def register():
if [Link] == 'POST':
name = [Link]['name']
email = [Link]['email']
password = [Link]['password']
# Store the user data in a database or file
return render_template('[Link]',name=name)
return render_template('[Link]')
if name == ' main ' :
[Link](host='[Link]')
STEP 5:
Create a templates folder and add the following two files: [Link] and [Link].
[Link] :
[Link] :
STEP 6:
Build the Docker image for your Flask application using the following command:
STEP 7:
Run a Docker container from the image using the following command in any browser:
STEP 8:
Open a web browser and access the registration form at
[Link]
This example demonstrates how to build a simple user registration form in Flask and run it in a Docker
container in DevOps.
Source Code:
Make sure Docker is installed on your machine. Follow the instructions for your operating system at
Docker's installation page.
For this example, we’ll use a basic [Link] application. Create a folder for your project, then create the
following files inside it.
[Link]
[Link]
{
"name": "docker-node-app",
"version": "1.0.0",
"description": "A simple [Link] app to demonstrate Docker containerization",
"main": "[Link]",
"scripts": {
"start": "node [Link]"
},
"dependencies": {}
}
In the same directory, create a Dockerfile. This file defines the environment for the app and how
Docker should build it.
# Step 1: Use the official [Link] image from the Docker Hub
FROM node:14
In your terminal, navigate to the project directory (where the Dockerfile is located), and run:
This command maps port 3000 in the container to port 3000 on your local machine. Now, if you go to
[Link] you should see "Hello, Docker World!" displayed.
To stop the container, you can use Ctrl + C in the terminal where it’s running or use Docker
commands:
docker login
DESCRIPTION:
Kubernetes and Docker are both popular technologies for managing containers, but they are used for
different purposes. Kubernetes is an orchestration platform that provides higher-level abstractions for
managing containers, while Docker is a containerization technology that provides a lower-level runtime
for containers.
To integrate Kubernetes and Docker, you need to use Docker to build and package your
application as a container image, and then use Kubernetes to manage and orchestrate the containers.
Here's a high-level overview of the steps to integrate Kubernetes and Docker:
Use Docker to build a Docker image of your application. You can use a Dockerfile to specify the base
image, copy the application into the container, and specify the command to run the application.
Push the Docker image to a container registry, such as Docker Hub or Google Container Registry, so
that it can be easily accessed by Kubernetes.
Deploy the Docker image to a Kubernetes cluster: Use Kubernetes to deploy the Docker image to a
cluster.
This involves creating a deployment that specifies the number of replicas and the image to be used, and
creating a service that exposes the deployment to the network.
• Monitor and manage the containers: Use Kubernetes to monitor and manage the containers. This
includes scaling the number of replicas, updating the image, and rolling out updates to the containers.
By integrating Kubernetes and Docker, you can leverage the strengths of both technologies to manage
containers in a scalable, reliable, and efficient manner
AIM: Automate the process of running containerized application developed in exercise 7 using
Kubernetes
Create a Kubernetes cluster: Create a Kubernetes cluster using a local installation of Minikube.
Create a deployment:
Create a deployment in Kubernetes that specifies the number of replicas and the Docker image to use.
Here's an example of a deployment YAML file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
match Labels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myimage
ports:
- containerPort: 80
• Create a service:
Create a service in Kubernetes that exposes the deployment to the network. Here's an example of a
service YAML file:
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
• Verify the deployment: Verify the deployment by checking the status of the pods and the service.
This is a basic example of how to automate the process of running a containerized application using
Kubernetes. In a real-world scenario, you would likely have more complex requirements, such as
managing persistent data, scaling, and rolling updates, but this example should give you a good starting
point for using Kubernetes to manage your containers
DESCRIPTION: To install and explore Selenium for automated testing, you can follow these steps:
Install Java Development Kit (JDK): Selenium is written in Java, so you'll need to install JDK
in order to run it. You can download and install JDK from the official Oracle website.
Install the Selenium WebDriver: You can download the latest version of the Selenium
WebDriver from the Selenium website.
You'll also need to download the appropriate driver for your web browser of choice (e.g.
Chrome Driver for Google Chrome).
Install an Integrated Development Environment (IDE): To write and run Selenium tests,
you'll need an IDE. Some popular choices include Eclipse, IntelliJ IDEA, and Visual Studio
Code
Write a simple test:
Once you have your IDE set up, you can write a simple test using the Selenium WebDriver.
import [Link];
import [Link];
public class Main
{
public static void main(String[] args)
{
[Link]("[Link]", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
[Link]("[Link]
[Link]([Link]());
[Link]();
}
}
Run the test: Run the test using your IDE or from the command line using the following command:
$ javac [Link]
$ java Main
This is a basic example of how to get started with Selenium for automated testing. In a real-world
scenario, you would likely write more complex tests and organize your code into test suites and test
cases, but this example should give you a good starting point for exploring Selenium
PROGRAM:
<!DOCTYPE html>
<html>
<head>
<title>Simple JavaScript Program</title>
</head>
<body>
<p id="output">0</p>
<button id="increment-button">Increment</button>
<script>
const output = [Link]("output");
const incrementButton=[Link]("increment-button");
let count = 0;
[Link]("click", function() {
count += 1;
[Link] = count;
});
</script>
</body>
</html>
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Main {
private WebDriver driver;
@Before
public void setUp()
{
[Link]("[Link]",
"path/to/chromedriver");
driver = new ChromeDriver();
}
@Test
public void testIncrementButton()
{ [Link]("[Link]
[Link]([Link]("increment-button")).click();
String result = [Link]([Link]("output")).getText();
assert [Link]("1");
}
@After
BVRIT CSE DEVOPS LAB
Roll No: Date:
Page No.
public void tearDown()
{
[Link]();
}
}
You can run the test case using the following command:
$ javac [Link]
$ java Main
This output indicates that the test case passed, and the increment button was successfully clicked,
causing the output to be incremented by 1.
EXPERIMENT NO.: [Link] test cases for the above containerized application using selenium
AIM: Develop test cases for the above containerized application using selenium
PROGRAM:
Here is an example of how you could write test cases for the containerized application using Selenium
import [Link];
import [Link];
import [Link]; import [Link];
import [Link]; import [Link];
@Before
public void setUp() {
[Link]("[Link]", "path/to/chromedriver"); driver = new ChromeDriver();
}
@Test
public void testHomePageLoads() {
[Link]("[Link]
String title = [Link]();
assert [Link]("My Containerized Application");
}
@Test
public void testSubmitForm() { [Link]("[Link]
[Link]([Link]("name")).sendKeys("John Doe");
[Link]([Link]("email")).sendKeys("[Link]@[Link] m");
[Link]([Link]("submit")).click();
String result = [Link]([Link]("result")).getText(); assert [Link]("Form
submitted successfully!");
}
@After
public void tearDown() { [Link]();
}
}
You can run the test cases using the following command:
$ javac [Link]
$ java Main
The output of the test cases should be:
..
Time: 1.135
OK (2 tests)
This output indicates that both test cases passed, and the containerized application is functioning as
expected.
BVRIT CSE DEVOPS LAB