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

Devops Practical

The document outlines 8 practical assignments completed by a student. The assignments cover topics like building a user registration form, Git and GitHub commands, source code management on GitHub, Jenkins installation and setup, demonstrating continuous integration and development using Jenkins, Docker commands, developing a containerized application using Docker, and integrating Kubernetes and Docker.

Uploaded by

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

Devops Practical

The document outlines 8 practical assignments completed by a student. The assignments cover topics like building a user registration form, Git and GitHub commands, source code management on GitHub, Jenkins installation and setup, demonstrating continuous integration and development using Jenkins, Docker commands, developing a containerized application using Docker, and integrating Kubernetes and Docker.

Uploaded by

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

PRACTICAL NO.

1
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Write code for a simple user registration form for an event.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Registration</title>
<style>
body { font-family: Arial, sans-serif; margin: 50px; }
form { max-width: 400px; margin: auto; padding: 10px; border: 1px solid
#ccc; border-radius: 5px; }
label, input { display: block; width: 100%; margin-bottom: 10px; }
input[type="text"], input[type="email"] { padding: 8px; }
button { padding: 10px 15px; background-color: #4CAF50; color: white;
border: none; border-radius: 5px; cursor: pointer; }
button:hover { background-color: #45a049; }
</style>
</head>
<body>
<h1>Event Registration</h1>
<form id="registrationForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<button type="submit">Register</button>
</form>
<p id="message"></p>
<script>
document.getElementById('registrationForm').addEventListener('submit',
function(event) {
event.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
document.getElementById('message').innerText = `Thank you for
registering, ${name}! A confirmation email has been sent to ${email}.`;
});
</script>
</body>
</html
PRACTICAL NO. 2
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Explore Git and GitHub commands.
Git and GitHub are two of the most popular tools used for version control
and collaboration in software development.
Here are some common Git and GitHub commands:
1. Initializing a Git repository: $ git init
2. Checking the status of your repository: $ git status
3. Adding files to the stage: $ git add <file-name>
4. Committing changes: $ git commit -m "commit message"
5. Checking the commit history: $ git log
6. Undoing changes: $ git checkout <file-name>
7. Creating a new branch: $ git branch <branch-name>
8. Switching to a different branch: $ git checkout <branch-name>
9. Merging two branches: $ git merge <branch-name>
10.Pushing changes to a remote repository: $ git push origin <branch-
name>
11.Cloning a repository from GitHub: $ git clone <repository-url>
12.Creating a pull request on GitHub: Go to the repository on GitHub,
elect the branch you want to merge and click the "New pull request"button .
PRACTICAL NO. 3
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Practice source code management on GitHub.
Experiment with the source code written in experiment 1.
 Install Git
 Configure Git
 Create a GitHub Repository
 Initialize Local Repository
 Add Source Code
 Connect to GitHub Repository
o Add Remote Repository
o Push Changes
 Collaborate and Manage Source Code
o Create a New Branch
o Make Changes and Commit
o Push the New Branch to GitHub
 Update Local Repository
o Fetch Latest Changes
o Pull Latest Changes
PRACTICAL NO. 4
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Jenkins installation and setup, explore the environment.
Jenkins is a popular open-source tool for Continuous Integration and
Continuous Deployment (CI/CD) in software development. Here are the
steps to install and set up Jenkins:
Download and install Jenkins:
 Download the Jenkins package for your operating system from the Jenkins
website.
 Follow the installation instructions for your operating system to install
Jenkins.
Start the Jenkins service:
 On Windows, use the Windows Services Manager to start the Jenkins
service.
 On Linux, use the following command to start the Jenkins service:
 $ sudo service jenkins start
Access the Jenkins web interface:
 Open a web browser and navigate to http://localhost:8080 to access the
Jenkins web interface.
 If the Jenkins service is running, you will see the Jenkins login page.
Initialize the Jenkins environment:
 Follow the instructions on the Jenkins setup wizard to initialize the Jenkins
environment.
 This process involves installing recommended plugins, setting up security,
and creating the first admin user.
Explore the Jenkins environment:
 Once the Jenkins environment is set up, you can explore the various features
and functionalities available in the web interface.
 Jenkins has a rich user interface that provides access to features such as
build history, build statistics, and system information.
These are the basic steps to install and set up Jenkins. Depending on your use
case, you may need to customize your Jenkins environment further. For
example, you may need to configure build agents, set up build pipelines, or
integrate with other tools.
PRACTICAL NO. 5
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Demonstrate continuous integration and development
using jenkins.
Continuous Integration (CI) and Continuous Development (CD) are important
practices in software development that can be achieved using Jenkins. Here's an
example of how you can demonstrate CI/CD using
Jenkins:
Create a simple Java application:
Create a simple Java application that you want to integrate with
Jenkins.
 The application should have some basic functionality, such as printing
"Hello World" or performing simple calculations.
Commit the code to a Git repository:
 Create a Git repository for the application and commit the code to the
repository.
 Make sure that the Git repository is accessible from the Jenkins server.
Create a Jenkins job:
 Log in to the Jenkins web interface and create a new job.
 Configure the job to build the Java application from the Git repository.
 Specify the build triggers, such as building after every commit to the
repository.
Build the application:
 Trigger a build of the application using the Jenkins job.
 The build should compile the code, run any tests, and produce an executable
jar file.
Monitor the build:
 Monitor the build progress in the Jenkins web interface.
 The build should show the build log, test results, and the status of the build.
Deploy the application:
 If the build is successful, configure the Jenkins job to deploy the application
to a production environment.
 The deployment could be as simple as copying the jar file to a production
server or using a more sophisticated deployment process, such as using a
containerization technology like Docker.
Repeat the process:
 Repeat the process for subsequent changes to the application.
Jenkins should automatically build and deploy the changes to the
production environment.
PRACTICAL NO. 6
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Explore docker commands for content managment.
Docker is a containerization technology that is widely used for managing
application containers. Here are some commonly used Docker commands for
content management:
 Docker run: Run a command in a new container.
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.
This command starts the container named "mycontainer".
 Docker stop: Stop one or more running containers.
This command stops the container named "mycontainer".
 Docker rm: Remove one or more containers.
This command removes the container named "mycontainer".
 Docker ps: List containers.
This command lists all running containers.
 Docker images: List images.
This command lists all images stored locally on the host.
 Docker pull: Pull an image or a repository from a registry.
This command pulls the Ubuntu 16.04 image from the Docker Hub registry.
PRACTICAL NO. 7
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Develop a simple containerized application using docker.
Choose an application:
 Choose a simple application that you want to containerize. For example, a
Python script that prints "Hello World".
Write a Dockerfile:
 Create a file named "Dockerfile" in the same directory as the application.
In the Dockerfile, specify the base image, copy the application into the container,
and specify the command to run the application. Here's an example Dockerfile for
a Python script:
 Use the official Python image as the base image
python:3.9
 Copy the Python script into the container
COPY hello.py /app/
 Set the working directory to /app/
WORKDIR /app/
 Run the Python script when the container starts
CMD ["python", "hello.py"]
 Build the Docker image:
Run the following command to build the Docker image:
$ docker build -t myimage .
 Run the Docker container:
Run the following command to start a new container based on the image:
$ docker run --name mycontainer myimage
 Verify the output:
Run the following command to verify the output of the container:
$ docker logs mycontainer

PRACTICAL NO. 8
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Integrate Kubernetes and Docker.
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:
 Build a Docker image
 Push the Docker image to a registry
 Use Kubernetes to deploy the Docker image to a cluster
 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.
 Continuously integrate and deploy changes
Use a continuous integration and deployment (CI/CD) pipeline to automatically
build, push, and deploy changes to the Docker image and the Kubernetes cluster.
This makes it easier to make updates to the application and ensures that the latest
version is always running in the cluster.
PRACTICAL NO. 9
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question:Automate the process of running containerized application
developed in experiment 7 using Kubernates.
To automate the process of running a containerized application in Kubernetes,
follow these steps:
 Create Kubernetes Deployment:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: your-application-deployment
spec:
replicas: 3
selector:
matchLabels:
app: your-application
template:
metadata:
labels:
app: your-application
spec:
containers:
- name: your-application
image: your-dockerhub-username/your-application:latest
ports:
- containerPort: 80
 Create Kubernetes Service:
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: your-application-service
spec:
selector:
app: your-application
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
 Apply Kubernetes Configuration:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
 Verify the Deployment:
kubectl get deployments
kubectl get pods
kubectl get services
 Automate with CI/CD
Integrate these steps into a CI/CD pipeline using tools like Jenkins, GitLab CI, or
GitHub Actions to automate the deployment process whenever there is a code
change.
PRACTICAL NO. 10
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question:Install and Explore Selenium for automated testing.
To install and explore Selenium for automated testing, we can follow these steps:

 Set Up Your Development Environment

o Install Java Development Kit (JDK)


o Install an Integrated Development Environment (IDE)
 Install 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).
 Create a Simple Test Case

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SeleniumTest {
private WebDriver driver;

@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver",
"/path/to/chromedriver");
driver = new ChromeDriver();
}
@Test
public void testGoogleSearch() {
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("Selenium WebDriver");
driver.findElement(By.name("btnK")).submit();
try {
Thread.sleep(2000); // Sleep for 2 seconds to allow results to load
(not recommended for real tests)
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals("Selenium WebDriver - Google Search",
driver.getTitle());
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}

 Run Your Test


o javac Main.java
o java Main
PRACTICAL NO. 11
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Write a simple program in Javascript and perform testing
using selenium.

 Simple JavaScript program that we can test using Selenium <!DOCTYPE


html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Simple Form</title>
<script>
function displayMessage() {
const name = document.getElementById('name').value;
document.getElementById('message').innerText = `Hello, ${name}!`;
}
</script>
</head>
<body>
<h1>Simple Form</h1>
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="button" onclick="displayMessage()">Submit</button>
</form>
<p id="message"></p>
</body>
</html>

 Create a Test Script


const { Builder, By, until } = require('selenium-webdriver');
const assert = require('assert');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
try {
await driver.get('file://' + __dirname + '/index.html');
await driver.findElement(By.id('name')).sendKeys('John Doe');
await driver.findElement(By.css('button')).click();
let message = await driver.wait(until.elementLocated(By.id('message')),
10000);
let messageText = await message.getText()
assert.strictEqual(messageText, 'Hello, John Doe!');
console.log('Test passed');
} catch (error) {
console.error('Test failed', error);
} finally {
await driver.quit();
}
})();

PRACTICAL NO. 12
NAME: KUNAL BISHT
COURSE: MCA
SEMESTER:4
ROLL NO.:2298009
Question: Develop test cases for the above containerized application
using selenium.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class Main {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
driver = new ChromeDriver();
}
@Test
public void testPageTitle() {
driver.get("http://localhost:8080");
String title = driver.getTitle();
assertEquals("Simple Form", title);
}
@Test
public void testFormSubmission() {
driver.get("http://localhost:8080");
WebElement nameField = driver.findElement(By.id("name"));
WebElement submitButton = driver.findElement(By.cssSelector("button"));
nameField.sendKeys("John Doe");
submitButton.click();
WebElement message = driver.findElement(By.id("message"));
String messageText = message.getText();
assertEquals("Hello, John Doe!", messageText);
}
@Test
public void testEmptyNameSubmission() {
driver.get("http://localhost:8080");
WebElement nameField = driver.findElement(By.id("name"));
WebElement submitButton = driver.findElement(By.cssSelector("button"));
nameField.clear();
submitButton.click();
WebElement message = driver.findElement(By.id("message"));
String messageText = message.getText();
assertEquals("Hello, !", messageText);
}
@Test
public void testSpecialCharactersInName() {
driver.get("http://localhost:8080");

WebElement nameField = driver.findElement(By.id("name"));


WebElement submitButton = driver.findElement(By.cssSelector("button"));
nameField.clear();
nameField.sendKeys("!@#$%^&*()");
submitButton.click();
WebElement message = driver.findElement(By.id("message"));
String messageText = message.getText();
assertEquals("Hello, !@#$%^&*()!", messageText);
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}

You might also like