Devops Lab Manual Programs
Devops Lab Manual Programs
(UGC-Autonomous)
(Approved by AICTE, New Delhi, and Permanent Affiliation to JNTUH, Accredited by NAAC-A)
Bogaram (V), Keesara (M), Medchal (Dist), Hyderabad, Telangana State
EXPERIMENTNO:
1. Write code for a simple user registration form for an event.
Aim: Write code for a simple user registration form for an event.
DESCRIPTION:
FROM python:3.8
WORKDIR /app
COPY . .
EXPOSE 5000
CMD["python","app.py"]
• Create a requirements.txt file with the following content to list the
dependencies of your Flask application: Flask==1.1.2
• Create a app.py file with the following code for a simple user
registration form in Flask:
From flask import Flask,request,render_template
app = Flask(name)
@app.route('/register',methods=['GET','POST'])
def register():
If request.method == 'POST':
name=request.form['name']
email =request.form['email']
password =request.form['password']
#Storetheuserdatainadatabaseorfile return
render_template('success.html')
HITS- CSE 1
III-I- B.TECH CSE
DEVOPS LAB
return render_template('register.html')
if name =='main':
app.run(host='0.0.0.0')
• Create a templates folder and add the following two files:
register.html and success.html.
register.html
<form method="post">
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<input type="password "name="password" placeholder="Password">
<input type="submit" value="Submit">
</form>success.ht
ml
<h2>Registration Successful</h2>
• Build the Docker image for your Flask application using the
following command: docker build -t simple-flask-app .
• Run a Docker container from the image using the following
command: docker run -p 5000:5000 simple-flask-app
• Open a web browser and access the registration form at
http://localhost:5000/register.
This example demonstrates how to build a simple user registration form in
Flask and run it in a Docker container in DevOps. Note that this code is only
meant to demonstrate the basic structure of a user registration form and does
not include any security measures or proper error handling. It is highly
recommended to add security measures such as password hashing and
validation before using it in a production environment.
VIVAQUESTIONS
Define Flask in devops
HITS-CSE 2
III-I- B.TECH CSE
DEVOPS LAB
EXPERIMENT NO: 2.Explore Git and Git Hub commands
Aim:Explore Git and GitHub commands
DESCRIPTION:
Git and GitHub are two of the most popular tools used for version control
and collaboration in software development.
Here are some common Git andGitHub commands:
• Initializing a Git repository:$gitinit
• Checking the status of your repository:$git status
• Adding files to the stage:$gitadd<file-name>
• Committing changes:$gitcommit-m" commit message"
• Checking the commit history:$gitlog
• Undoing changes:$gitcheckout<file-name>
• Creating a new branch:$gitbranch<branch-name>
• Switching to a different branch:$gitcheckout<branch-name>
• Merging two branches:$gitmerge <branch-name>
• Pushing changes to a remote repository:$gitpushorigin<branch-
name>
• Cloning a repository from GitHub:$gitclone<repository-url>
• Creating a pull request on GitHub: Go to the repository on GitHub,
select the branch you want to merge and click the "New pull request
"button.
These are just a few of the many Git and GitHub commands available. There
are many other Git commands and functionalities that you can explore to suit
your needs.
VIVAQUESTIONS
1.Define Git
2.What is
3.GitHub
4.Difference between Git & GitHub
HITS-CSE 3
III-I- B.TECH CSE
DEVOPS LAB
Description:
To practice source code management on GitHub, you can follow these steps:
• Create a GitHub account if you don't already have one.
• Create a new repository on GitHub.
• Clone the repository to your local machine:$gitclone<repository-
url>
• Move to the repository directory: $cd<repository-name>
• Create a new file in the repository and add the source code written in
exercise 1.
• Stage the changes:$gitadd <file-name>
• Commit the changes:$gitcommit-m"Added source code for a simple
user registration form"
• Push the changes to the remote repository:$gitpush origin master
• Verify that the changes are reflected in the repository on GitHub.
These steps demonstrate how to use GitHub for source code management.
You can use the same steps to manage any source code projects on GitHub.
Additionally, you can also explore GitHub features such as pull requests,
code review, and branch management to enhance your source code
management workflow.
VIVAQUESTIONS
HITS-CSE 4
III-I- B.TECH CSE
DEVOPS LAB
EXPERIMENTNO: 4.Jenkins installation and setup, explore the
environment
Aim: Jenkins installation and setup, explore the environment
DESCRIPTION
HITS-CSE 5
III-I- B.TECH CSE
DEVOPS LAB
integrate with other tools. However, these steps should give you a good
starting point for using Jenkins for CI/CD in your software development
projects.
VIVAQUESTIONS
Define Jenkins
HITS-CSE 6
III-I- B.TECH CSE
DEVOPS LAB
HITS-CSE 7
III-I- B.TECH CSE
DEVOPS LAB
This is a basic example of how you can use Jenkins to demonstrate CI/CD in
software development. In a real-world scenario, you would likely have more
complex requirements, such as multiple environments, different types of
tests, and a more sophisticated deployment process. However, this example
should give you a good starting point for using Jenkins for CI/CD in your
software development projects.
VIVAQUESTIONS
Define CD &CI
HITS-CSE 8
III-I- B.TECH CSE
DEVOPS LAB
DESCRIPTION
Docker is a containerization technology that is widely used for managing
application containers. Here are some commonly used Docker commands for
content management:
HITS-CSE 9
III-I- B.TECH CSE
DEVOPS LAB
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. However, these commands should give you a good starting
point for using Docker for content management.
VIVAQUESTIONS
HITS-CSE 10
III-I- B.TECH CSE
DEVOPS LAB
Docker
DESCRIPTION
Choose an application:
HITS-CSE 11
III-I- B.TECH CSE
DEVOPS LAB
VIVAQUESTIONS
HITS-CSE 12
III-I- B.TECH CSE
DEVOPS LAB
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 ahigher-level abstractions formanaging
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.
Use Docker to build a Docker image of your application. You can use a
Docker file tospecify the base image, copy the application into the container,
and specify the command to run the application.
HITS-CSE 13
III-I- B.TECH CSE
DEVOPS LAB
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.
• Continuouslyintegrateanddeploychanges:
HITS-CSE 14
III-I- B.TECH CSE
DEVOPS LAB
DESCRIPTION
To automate the process of running the containerized application developed
in exercise 7 using Kubernetes, you can follow these steps:
• Create a Kubernetes cluster:
Create a Kubernetes cluster using a cloud provider, such as Google Cloudor
Amazon Web Services, or using a local installation of Minikube.
• Push the Docker image to a registry:
Push the Docker image of your application to a container registry, such as
Docker Hub or Google Container Registry.
• Create a deployment:
Create a deployment in Kubernetes that specifies the number of replicasand
the Docker image to use. Here's an example of a deployment YAML file:
apiVersion: apps/v1
kind:Deployment
metadata:
HITS-CSE 15
III-I- B.TECH CSE
DEVOPS LAB
name:myapp
spec:
replicas:3
selector:
matchLabels:
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:
- name:http
port: 80
HITS-CSE 16
III-I- B.TECH CSE
DEVOPS LAB
targetPort:80
type: ClusterIP
• Apply the deployment and service to the cluster:
Apply the deployment and service to the cluster using the kubect l command-
line tool. For example:
$kubectl apply-fdeployment.yaml
$kubectl apply-fservice.yaml
• Verifythe deployment:
Verify the deployment by checking the status of the pods and the service.For
example:
$kubectlget pods
$kubectlget services
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.
VIVAQUESTIONS
DefineKubernetes
HITS-CSE 17
III-I- B.TECH CSE
DEVOPS LAB
DESCRIPTION:
To install and explore Selenium for automated testing, you can follow these
steps:
• To write and run Selenium tests, you'll need an IDE. Some popular
choices include Eclipse, IntelliJ IDEA, and Visual Studio Code.
HITS-CSE 18
III-I- B.TECH CSE
DEVOPS LAB
• Write a simple test:
• Once you have your IDE setup,you can write a simple test using the
Selenium WebDriver. Here's an example in Java:
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
publicclassMain{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println(driver.getTitle());
driver.quit();
}
}
• Runthe test:
Run the test using your IDE or from the command line using the following
command:
$javac Main.java
$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.
VIVA QUESTIONS
HITS-CSE 19
III-I- B.TECH CSE
DEVOPS LAB
PROGRAM:
• SimpleJavaScriptprogramthatyoucantestusingSelenium
<!DOCTYPEhtml>
<html>
<head>
<title>SimpleJavaScriptProgram</title>
</head>
<body>
<pid="output">0</p>
<buttonid="increment-button">Increment</button>
<script>
constoutput=document.getElementById("output");
const incrementButton
=document.getElementById("increment-
button");
HITS-CSE 20
III-I- B.TECH CSE
DEVOPS LAB
letcount=0;
incrementButton.addEventListener("click",function(){
count+=1;
output.innerHTML=count;
});
</script>
</body>
</html>
publicclassMain{
privateWebDriver driver;
@Before
publicvoid setUp(){
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
driver = new ChromeDriver();
}
@Test
public void testIncrementButton() {
driver.get("file:///path/to/program.html");
driver.findElement(By.id("increment-button")).click();
Stringresult=driver.findElement(By.id("output")).getText();
assert result.equals("1");
}
HITS-CSE 21
III-I- B.TECH CSE
DEVOPS LAB
@After
Public void tear Down(){
driver.quit();
}
}
You can run the test case using the following command:
$javac Main.java
$java Main
The output of the test case should be:
.
Time:0.189
OK(1test)
This output indicates that the test case passed, and the increment button was
successfully clicked, causing the output to be incremented by 1.
VIVAQUESTIONS
HITS-CSE 22
III-I- B.TECH CSE
DEVOPS LAB
PROGRAM:
Here is an example of how you could write test cases for the containerized
application using Selenium
import org.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
import org.junit.After;
importorg.junit.Before;
import org.junit.Test;
publicclassMain {
privateWebDriver driver;
@Before
publicvoid setUp(){
System.setProperty("webdriver.chrome.driver","path/to/chromedriver");
driver = new ChromeDriver();
HITS-CSE 23
III-I- B.TECH CSE
DEVOPS LAB
@Test
publicvoidtestHomePageLoads()
{
driver.get("http://localhost:8080");
String title = driver.getTitle();
asserttitle.equals("MyContainerizedApplication");
}
@Test
public void test SubmitForm() {
driver.get("http://localhost:8080");
driver.findElement(By.name("name")).send Keys("JohnDoe");
driver.findElement(By.name("email")).sendKeys("[email protected]
m");
driver.findElement(By.name("submit")).click();
String result=driver.find Element(By.id("result")).getText();
assert result.equals("Form submitted successfully!");
}
@After
Public void tear Down(){
driver.quit();
}
}
You can run the test cases using the following command:
$javac Main.java
$java Main
The output of the test cases should be:
Time:1.135
OK(2tests)
This output indicates that both test cases passed, and the containerized
application is functioning as expected.
VIVAQUESTIONS
1. Define selenium
2. Name the test cases used in selenium
HITS-CSE 24
III-I- B.TECH CSE
DEVOPS LAB