0% found this document useful (0 votes)
22 views89 pages

Devops

The document is a lab manual for a DevOps course, detailing exercises on creating a user registration form using HTML and JavaScript, exploring Git and GitHub commands, and practicing source code management. It includes instructions for branching, merging, cloning repositories, forking, and setting up Jenkins for continuous integration and development. Each section provides step-by-step commands and code snippets to facilitate learning and practical application of DevOps concepts.
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)
22 views89 pages

Devops

The document is a lab manual for a DevOps course, detailing exercises on creating a user registration form using HTML and JavaScript, exploring Git and GitHub commands, and practicing source code management. It includes instructions for branching, merging, cloning repositories, forking, and setting up Jenkins for continuous integration and development. Each section provides step-by-step commands and code snippets to facilitate learning and practical application of DevOps concepts.
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

CMRCET DEVOPS LAB MANUAL R22 CSE

a1. Write code for a simple user registration form for an event.
HTML CODE WITH INLINE CSS FOR REGISTRTION FORM ->
<!DOCTYPE html>
<head>
<title>Event Registration</title>
</head>
<body style="display: flex; justify-content: center; align-items: center;
height: 750px; background-color: #f0f8ff;">
<form style="border: 1px solid gray; padding: 20px; border-radius:
5px; width: 300px; background-color: white;">
<h3 style="text-align: center; font-size: 24px;">Register</h3>
<input id="name" type="text" placeholder="Name" style="width:
90%; padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<input type="email" placeholder="Email" required style="width:
90%; padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<input type="tel" placeholder="Phone" required style="width: 90%;
padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<button id="button" type="submit" style="width: 100%; padding:
10px; background-color: #28a745; color: white; border-radius: 3px; font-
size: 18px;">Submit</button>
</form>
<script src="[Link]"></script>
</body>
</html>

JAVASCRIPT CODE (TO HANDLE THE CASE WHEN MORE THAN 25 CHARACTERS ARE ENTERED IN
NAME FIELD AND GET AN ALERT WHEN SUBMIT BUTTON IS CLICKED) ->

[Link]("button").addEventListener('click',()=>{
str = [Link]("name").value;
if([Link]>25)alert("Name cannot be more than 25 characters");
alert("You have successfully registered");
})

1|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

2|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

2. Explore Git and GitHub commands.


VERSION CONTROL SYSTEM ->
A Version Control System (VCS) is a tool that helps manage changes to
files, particularly source code, over time. It tracks modifications, allows
multiple
people to collaborate on the same project, and ensures that a complete
history of changes is maintained. VCS is essential for software development,
but it can also be used for other types of documents or files.
GIT ->
Git is a distributed version control system (VCS) designed to manage and track
changes in source code during software development. Created by Linus
Torvalds in 2005, Git is widely used by developers to collaborate on projects,
keep track of changes, and manage multiple versions of their codebase.
GITHUB ->
GitHub is a web-based platform and service that provides hosting for software
development and version control using Git. It offers a collaborative
environment where developers can manage and share their projects, track
issues, and work together on code. GitHub is widely used in the software
development community for both open-source and private projects.

Git Commands to push files to remote repo


git init : creates a new repository. The files are in working directory and are
untracked
git status: Show current repository status. ( whether untracked or tracked)
git add <file>: adds the file to staging area .(The file is now tracked)
git config –global [Link] “cherry”: to set a username
git config –global [Link] “cherry@[Link]”: to set an email
git commit -M “commited by 22h51a05b1: Save changes.(now the file will be
in local repo)

3|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

git remote add origin ‘your repo link’: To establish a connection between
local and remote rep
git branch: To know you current branch
git branch -m master: To rename branch to master
git push -u origin master: To upload file to remote repo (now the file will be In
remote repo)

4|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

5|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

6|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

3. Practice Source code management on GitHub. Experiment with the


source code written in exercise 1.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Event Registration</title>
</head>
<body style="display: flex; justify-content: center; align-items: center;
height: 750px; background-color: #f0f8ff;">
<form style="border: 1px solid gray; padding: 20px; border-radius: 5px;
width: 300px; background-color: white;">
<h3 style="text-align: center; font-size: 24px;">Register</h3>
<input id="name" type="text" placeholder="Name" style="width: 90%;
padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<input type="email" placeholder="Email" required style="width: 90%;
padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<input type="tel" placeholder="Phone" required style="width: 90%;
padding: 10px; margin-bottom: 15px; font-size: 18px;"/>
<button id="button" type="submit" style="width: 100%; padding:
10px; background-color: #28a745; color: white; border-radius: 3px; font-
size: 18px;">Submit</button>
<button id="button" type="submit" style="width: 100%; padding:
10px; background-color: #14142d; color: white;margin-top:15px; border-
radius: 3px; font-size: 18px;">Clear form</button>
</form>
<script src="[Link]"></script>
</body>
</html>

So this is the week one html code in which I added an additional button ‘clear
form ‘ now lets commit these changes

Commands to commit changes in an existing repository->


git add .
git commit -m “changes
made” git push origin master

7|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

8|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

BRANCHING -
Branching ->Branching is like making a copy of your code so you can try new
things without changing the original. If your new changes work, you can
combine them back with the original; if not, the original stays safe.
->So you can create a new branch and work on a different feature and then
merge it back to the main branch
-> creating a new branch
Command: git branch
branchName
9|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE
Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->switching to another branch


Command: git switch
branchName
->Viewing all branches
Command: git branch
Now lets understand branching more clearly -
->create a folder and inside it create a text file and write some text inside it

->Now initialize git using the command : git init


->then add it to the staging area using the command :git add .
->then commit the changes using commit -m ‘commit msg’

->Now create a new branch using the command : git branch newBranch
->then switch to the new branch using the command: git switch newBranch

10 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now in this branch create a new file and write some text

->Now execute the following command to add it to staging area and then
commit stages just like we did for feature1 file in main branch
->Now switch back to main branch using the command : git switch main
->Now here you will not see the feature2 file since it was created in another
branch so if you want to have that here you can merge it
-> to merge the branch execute the command : git merge newBranch

->After merging feature 2 will be available in the main branch also so this is
have we do branching.

11 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

PERFORMING BRANCHING DIRECTLY THROUGH GIT HUB –


->first go to your repository where you want to create a new branch
->Now on the top left you will find the current branch, select it

->Now write the branch name that you want to create in the search bar . If it
does not exit then you will see an option saying Create branch newBranch
from main.

12 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->After clicking on Create branch , the newBranch will be created and you will
automatically get switched to the new branch and all the files in the main
branch will be available as a copy in this newBranch

->Create a new file in this branch write something in it and commit changes

13 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now to merge the changes in this newBranch to the main branch , click on
compare & pull request

->Now add a commit message and click on create pull request

->Then click on Merge pull request inorder to reflect the changes made in
newBranch to main branch

14 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Then click on confirm merge

->After this if you go to main branch you will see that the changes made in
newBranch will be reflected in the main branch
So this is how branching can be done in git hub

CLONING A REPOSITORY-
15 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Inorder to clone a repository we the git clone command.


->Go ahead and copy the repository of the project that you want to clone
->Now create a new folder and open it in vs code
->Now open terminal in vs code and execute the command : git clone
repository_url
FORKING-
Forking in GitHub is the process of cloning a repository of someone else’s to
your own GitHub account where you can modify it freely.
Steps to Fork and then make changes in you local repo-
->Go to the repository: Visit the GitHub page of the repository you want to
fork.
->Click "Fork": On the top-right corner of the repository page, you will see a
"Fork" button. Click on it.

->Then you can clone it using git clone and make changes locally and add it
back to the remote repository

16 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

[Link] installation and setup, explore the environment


localhost8080 Steps to install jdk
->search for jdk download
->go to the first link of oracle and click jdk 21 and download x64 installer
->give the permissions and install it
->go to command prompt and click java –version to know the version of java

Steps to install and setup Jenkins


->search for Jenkins download
->go to the first link (Download and deploy ([Link]))

17 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->now click on java generic package and download it

->Now to run Jenkins go to command prompt and navigate to the folder


where generic java [Link] ([Link])is downloaded
->Now run this command
java -jar [Link]
->Now a password will be generated ,Copy that password

->Now open localhost:8080 and past the password that was generated

18 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now click on install plug ins and install them

Now you can use Jenkins


5. Demonstrate continuous integration and development using
Jenkins. Creating a new Job and running it-
->create a new folder and then open note pad and write a java program in
it and save it in the new folder with .java extension. Now copy the new
folder path where this java program is saved

19 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->open Jenkins and go to Dashboards and click on New item

->name the job and select freestyle project and click ok

->Now in General section click on advanced and select use custom workspace
and past the path that you copied

20 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now in build steps section click on add build step and select Execute
Windows batch command. Now write
javac [Link]
java Main (to run the java program)

->Now click on apply and then save


->Now click on Build Now

->If you get a tick mark then your job was finished successfully

21 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->click on that tick mark to see the output of the program

Creating pipe line-


->first we need to create 4 jobs – csebuild,csedeploy,csetest,cserelease
->click on New item and name it as csebuild and select freestyle project
and click [Link] add any path just click on add build step and write echo
‘Build successful’ and click and apply and then [Link] click on Build Now
.
->follow the same process and create separate jobs for csedeploy ,csetest
and cserelease

22 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now select csedeploy and click on config

->Now select build after other projects are build and write csebuild,then
apply and save

23 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now go back and select csetest and click on config and then select Build
after other projects are built and write csedeploy then apply and save.
-> Now go back and select cserelease and click on config and then select Build
after other projects are built and write csetest then apply and save.
Now lets build a pipeline view
->click on new view

->Give a name and select Build pipeline view and then click on create
->Then select csebuild as initial job

->Now click apply and then save

24 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Output-

Now lets implement continues integration –


->go to jenkins and click on new item and then select free style project and
click ok

->create a java file and write a simple program in it and then create a
repository and add this java file to the repository and copy the repository

25 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->now in the source code management section select git and past your
repository url

26 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now in build steps section select execute windows batch


command and to compile java write the command

->now in the build triggers section select build periodically


and in the schedule past * * * * *.
This will execute the file every 1 minute

1|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->Now apply and save it


->Now click on build now
->Now every minute jenkins will build the file enabling
continues integration

2|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

DevOps node js project


-> first install all the dependencies
-jdk,git,docker,Jenkins

->make sure all the dependencies are installed and working properly.

->login your github account in the browser.

3|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->click on new tab, in the new tab paste [Link]

->after pasting the link fork the repository

->copy the repository HTTPS url from the code

Jenkins Project:
->open the Jenkins in new tab and type “localhost:8080” or “localhost:8085”which you have kept
the port number while installing the Jenkins.

->after opening Jenkins, click on new item which is appearing in the leftside

4|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->after selecting new item you are able to see like this

->now in the box enter any name for your Jenkins project and select pipeline project, click ok.

->after clicking ok you will get like this

5|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->Select Pipeline in the configure

->click on Pipeline script

->select “pipeline script from SCM”

->in the SCM select git

->after selecting the git paste your repository link which is previously forked and saved

6|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->specify your branch like “*/master” or “*/main” which is showing in your github repository

->specify here

->after that clock on Save

7|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->after that you will able to see this on your screen

8|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->Note:Before clicking build you should make sure that docker desktop application is opened and
running in the background

->click on BuildNow

->after build you will get success mark and build number in the bottom

->click on that #1

9|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->on the left side you will able to see console outpot, click on it

-> in the bottom you should get success like

->you can see the docker iamge in the docker desktop application

10 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

Devops Maven project


Prerequisites:
- Eclipse IDE,GitHub,Jenkins,Docker,Maven

->open eclipse and go to File > New > project

->Select Maven project from the wizard,then clicl next.

->Ensure Create a simple project(skip archetype selection) is checked,then click Next.

->

->Enter the following:

1. Group Id: [Link]

2. Artifact Id: hello-world

3. Version: 1.0-SNAPSHOT

4. Packaging: jar

Click Finish.

->Now,a Maven project will be created in Eclipse

1|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

Step 2:Write a Hello world program.

->navigate to src/main/java folder inside your project in eclipse.

->create a new package [Link] inside src/main/java.

->

- create a new java class [Link] inside the [Link] package:

Code:

package [Link];
public class App {
public static void main(String[] args) {
[Link]("Hello, World!");
}}

Step 3: Update [Link]

->open [Link] file in the root of your maven project.

2|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->ensure it contains the following dependencies


<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.12</version>

<scope>test</scope>

</dependency>

</dependencies>

->add the required plugins

<project xmlns="[Link]

xmlns:xsi="[Link]

xsi:schemaLocation="[Link]
[Link]

<modelVersion>4.0.0</modelVersion>

<groupId>[Link]</groupId>

<artifactId>helloworld-maven</artifactId>

<version>0.0.1-SNAPSHOT</version>

<properties>

<[Link]>1.8</[Link]>

<[Link]>1.8</[Link]>

</properties>

3|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

<build>

<plugins>

<!-- Maven Compiler Plugin -->

<plugin>

<groupId>[Link]</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.8.1</version>

<configuration>

<source>1.8</source>

<target>1.8</target>

</configuration>

</plugin>

<!-- Maven Assembly Plugin -->

<plugin>

<groupId>[Link]</groupId>

<artifactId>maven-assembly-plugin</artifactId>

<version>3.3.0</version>

<configuration>

<descriptorRefs>

<descriptorRef>jar-with-dependencies</descriptorRef>

</descriptorRefs>

<archive>

<manifest>

<mainClass>[Link]</mainClass>

</manifest>

</archive>

</configuration>

<executions>

<execution>

<id>make-assembly</id>
4|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE
Students
CMRCET DEVOPS LAB MANUAL R22 CSE

<phase>package</phase>

<goals>

<goal>single</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

</project>

Step 4 :Build the Maven project Locally

->right-click on the project in eclipse

->select runs as > Maven Build……

5|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->In the Goals fiels,type clean package .

->click run.

6|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

-> this will build the project and create a JAR file in the target folder.

Step 5: Push the Maven Project to Github.

->Goto github and click new repository.

->name it hello-world-mavin

->copy the remote url for the repository

->Initialize Git in your project folder using terminal

->navigate to the
directory. git init
git remote add origin [Link] git push -u origin
master
git add .
git commit -m “initial commit”
git push -u origin master

Step 6:Set up Jenkins

->open jenkins in your web browser and log in.

->Install the necessary Jenkins plugins:

1. Go to Manage Jenkins > Manage Plugins.

2. Install Git, Maven, and Docker Pipeline plugins.

->Go back to the Jenkins dashboard and click on New Item.

->Select Freestyle Project, name it hello-world-maven, and click OK.

7|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->In the Source Code Management section:

1. Select Git.

2. Add the GitHub URL of your repository.

8|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

3.
4. If necessary, add your GitHub credentials.

->In the Build section:

1. Click on Add Build Step and select Invoke Top-Level Maven Targets.

2. Set the Goals to clean package.

->save the configuration.

Step 7:Configure Docker in Jenkins

->Install Docker on the machine where Jenkins is running if it's not installed yet.

1. To verify Docker is running, use docker --version and docker ps in your terminal.

->In Jenkins, navigate to Manage Jenkins > Configure System.

->Scroll to the Docker section and ensure the Docker configuration is correct.

->In your Jenkins project (hello-world-maven), add a Post-build Action to create a Docker image

->Go to the Post-build Actions section.

->Add a build step Execute shell and add the following commands to build and run your Docker
image:
docker build -t hello-world-maven-app .

docker run -d -p 8080:8080 hello-world-maven-app

->Save the Jenkins configuration.

Step 8 Create a Dockerfile in Your Project

9|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->In the root of your project, create a file named Dockerfile.

->in that file add

FROM maven:3.6.3-jdk-8 AS build

WORKDIR /app

COPY . .

RUN mvn clean package

FROM openjdk:8-jre

WORKDIR /app

COPY --from=build /app/target/[Link] /app/[Link]

# Run the application

ENTRYPOINT ["java", "-jar", "/app/[Link]"]

->push the Dockerfile to github.

->in Jenkins in the item,click on build now this will create a docker [Link] while building
always start the docker desktop.

->You can verify that the Docker image has been created by running the following command on the
Jenkins server:
docker images

-> To check if the application is running in a


container: docker ps

->The application should be running on port 8080.


->you can also see the images in the docker desktop.

10 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

DevOps java project


-> first install all the dependencies
-jdk,jvm,docker,Jenkins,eclipse
->create a folder which will have the code
->open that folder in the vs code
->then create a new java file in that and write a piece of code.

->now in the same folder create a Dockerfile .

->in that docker file write the command to run the java file.

->

->save it , And push all the file in to github

-> pushing files to git hub.


->first create a repository in the git hub and after creating the repository copy the
git remote

1|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->open the terminal ,navigate to the folder and write the commands to push files.
git init
git remote add origin [Link]
git add .
git commit -m “initial commit”
git push -u origin master

->after successfully pushing all the files into github ,verify in the github whether all the files have
been added or not

->now open Jenkins in localhost:8080


->click on the new item

2|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->enter the item name and select the freestyle project and click on ok.
->

->after clicking ok,a configure page will be opened

->click on the source code management

->select git and give all the required details like your repository(which we have created earlier) link
and branch .

3|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->if you have the file not in the master branch then add new branch

->*/<your_branch>

->now click on the build steps

->click on the add build step and select Execute Windows batch command

4|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->and write the docker commands to create the docker image.


->

->later while running the image in the docker desktop if a error regarding the port,try changing the
port numbers here like 8084:3000

->click apply and save.

->after clicking

->make sure that you have started the docker .


->click on build now

5|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->after a successful build you will see the tick mark

->now open the docker

6|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

->

->search the container that is newly created.

->run the container


->after the successful run.
->you will be seeing the output printing hello world.

7|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

WEEK 6
Aim: Explore Docker commands for content management.

DOCKER COMMANDS:

2. Get help regarding Docker commands: docker help

3. Docker run command: docker run <image_name>


This command is used to run a container from an
image.

4. Docker ps: docker ps


8|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE
Students
CMRCET DEVOPS LAB MANUAL R22 CSE

Lists all the running containers

9|Page Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

5. Docker Pull: docker pull <image_name>


This command allows you to pull any image which is present
in the docker hub.

6. Docker Stop: docker stop <container_ID>


This command allows you to stop a container if it has
crashed or you want to switch to another one.

7. Docker Start: docker start <container_ID>


Suppose you want to start the stopped container again, you
can do it with the help of this command.
8. Docker rm: docker rm <container_name or
ID> To delete a container.

10 | P a g Prepared by Faculty M Shiva Kumar and 22 batch CSE


e Students
CMRCET DEVOPS LAB MANUAL R22 CSE

9. Docker Images: docker images


Lists all the pulled images which are present in your system.

10. Docker exec: docker exec


<flag> Some important flags:
-d flag: for running the commands in the background.
-i flag: it will keep STDIN open even when not attached.
-e flag: sets the environment variables
This command allows us to run new commands in a running
container.

11. Docker Login: docker login


The Docker login command will help you to authenticate with
the Docker hub by which you can push and pull your images.

10 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

12. Docker Push: docker push <Image name/Image ID>


Once you build your own customized image by using
Dockerfile you need to store the image in the remote
registry which is DockerHub for that you need to push your
image by using the following command.

13. Docker Build: docker build -t image_name:tag .


In the place of image_name use the name of the image you
build with and give the tag number and . “dot” represents
the current directory.

11 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

The docker build command is used to build the docker


images with the help of Dockerfile.

14. Docker Stop: docker stop <container_name or id>


You can stop and start the docker containers where you can
do the maintenance for containers. To stop and start specific
containers you can use the following commands.

15. Stop Multiple Containers: docker stop <container1>


<container2> <container3>
Instead of stopping a single container. You can stop multiple
containers at a time by using the following commands.

12 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

16. Docker Restart:


docker restart <container_name_or_id>
While running the containers in Docker you may face some
errors and containers fails to start. You can restart the
containers.

17. Docker Commit command:


docker commit <container_name_or_id>
<new_image_name>:tag
After running the containers by using the current image you
can make the updates to the containers by interacting with
the containers from that containers you can create an image
by using the following commands.

13 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Some other useful commands:


1. docker inspect command: It will helps to debug the
docker image if any errors occurred while building
an image or pulling the image.
2. docker save command: It will save the docker image
in the form of dockerfile.
3. docker rmi command: It will remove the docker image.
4. docker cp command: To copy the file from docker
host to the docker containers.
5. docker rm: Docker rm command will remove
the containers which are in the stop condition.

14 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

WEEK-7
Develop a simple containerized application using Docker.
6. Clone the getting-started-app repository using the following command:
1. git clone [Link]
started- [Link]

7. View the contents of the cloned repository. You should see the
following files and sub-directories.
├── getting-started-app/
│ ├── .dockerignore
│ ├── [Link]
│ ├── [Link]
│ ├── spec/
│ ├── src/
│ └── [Link]

> Now create a Docker file in the same directory and add the following
code
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/[Link]"]
EXPOSE 3000

> In the terminal, make sure you're in the getting-started-app


directory. Replace /path/to/getting-started-app with
the path to your getting-started-app directory.
o cd /path/to/getting-started-app

> Build the Image


Run the following commands in the terminal
docker build -t getting-started .

15 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch CSE


Students
CMRCET DEVOPS LAB MANUAL R22 CSE

> You can verify whether the image is created or not by running the
command docker images which will list all the images and you
can find the getting-started image. Also you can check the image in the
docker desktop images section.

> Now run the image using the command


docker run -dp [Link]:3000:3000 getting-started

> Open browser and type [Link] to check the output


the image is running on port 3000.

16 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

WEEK-8
Integrate Kubernetes and Docker
Docker Desktop includes a standalone Kubernetes server and client, as well as
Docker CLI integration that runs on your machine.
The Kubernetes server runs locally within your Docker instance, is not
configurable, and is a single-node cluster. It runs within a Docker container on
your local system, and is only for local testing.
Turning on Kubernetes allows you to deploy your workloads in parallel, on
Kubernetes, Swarm, and as standalone containers. Turning on or off the
Kubernetes server does not affect your other workloads.
Install and turn on Kubernetes
> From the Docker Dashboard, select the Settings.
> Select Kubernetes from the left sidebar.
> Next to Enable Kubernetes, select the checkbox.
> Select Apply & Restart to save the settings and then select Install to
confirm. This instantiates images required to run the Kubernetes server as

17 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

containers, and installs the /usr/local/bin/kubectl command on your


machine.

The kubectl binary is not automatically packaged with Docker Desktop for Linux.
To install the kubectl command for Linux, see Kubernetes documentation

8. . It should be installed at /usr/local/bin/kubectl.

By default, Kubernetes containers are hidden from commands like docker ps,
because managing them manually is not supported. Most users do not need this
option. To see these internal containers, select Show system containers (advanced).

When Kubernetes is turned on and running, an additional status bar in the Docker
Dashboard footer and Docker menu displays.

Note

Docker Desktop does not upgrade your Kubernetes cluster automatically after a new
update. To upgrade your Kubernetes cluster to the latest version, select Reset
Kubernetes Cluster.

Use the kubectl command

Kubernetes integration provides the Kubernetes CLI command at


/usr/local/bin/kubectl on Mac and at C:\Program Files\Docker\Docker\
Resources\bin\[Link] on Windows.

If you have already installed kubectl and it is pointing to some other


environment, such as minikube or a GKE cluster, ensure you change the context so
that kubectl is pointing to docker-desktop:

kubectl config get-contexts

kubectl config use-context docker-desktop

Tip

Run the kubectl command in a CMD or PowerShell terminal, otherwise


kubectl config get-contexts may return an empty [Link] you installed
kubectl using Homebrew, or by some other method, and experience conflicts,
remove
/usr/local/bin/kubectl.

You can test the command by listing the available nodes:

18 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

kubectl get nodes

19 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

NAME STATUS ROLES AGE


VERSION
docker-desktop Ready control-plane 3h
v1.29.1
WEEK- 9
Automate the process of running containerized application developed in
exercise 7 using Kubernetes.
Step1:
9. Clone this repository to your local repository
[Link]
10. Make sure that cloned repository consist of “node-app-
[Link]”, “[Link]” files in folder.
11. Push this local repository to github (or) you can fork that repository from
[Link] /[Link]
12. After completion of pushing or forking of kube foleder into your github
repository you should able to see like this that contains all the files.

Step-2:
110 | P a g Prepared by Faculty M Shiva Kumar and 22 batch
eStudents CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

> Push your github repository to the Jenkins.


> click on new item

> Enter a name , select pipeline project and click on ok

> In the configure paste your repository url and specify your branch whether
it is main or master based on your github repository after that apply and save it.

20 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

> after creation of your Jenkins project build it, the build should be shown in
green colour

> you will get docker image for this project , like showed in the below

21 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Step-3:
> Push the docker image into dockerhub
>open command prompt and run the command “docker login”

> tag your iamge using this syntax


docker tag <local-image-name>:<tag> yourusername/yourrepo:<tag>
for example: docker tag my-kube:latest wilsonbolledula/my-kube:latest
here username is your dockerhub account username
>push the image to dockerhub
docker push yourusername/yourrepo:<tag>
example: docker push wilsonbolledula/my-kube:latest
Step-3:
> Start the Kubernetes
Syntax : minikube start

>Apply [Link] file

22 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Syntax: kubectl apply -f [Link]


> Apply [Link] file
Syntax: kubectl apply -f [Link]
>that will apply to the deployments and services
>To check that type command “kubectl get pods” and “kubectl get service”

> To open the Kubernetes dashboard type = “minikube dashboard”


That will open Kubernetes dashboard automatically on your default primary
browser

> Finally you can checkout your deployments and pods here

23 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

WEEK– 10
Install and Explore Selenium for automated testing.
13. Install Python if not already installed, from the official Python website.
14. Install Selenium using pip:
pip install selenium
15. Download the WebDriver for the specific browser you want to automate
(Chrome, Firefox, etc.).

16. Open the 1st link

24 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

17. Click on version selection and check your version in chrome by


chrome://settings/help

18. Click on the Chrome for Testing (CfT) availability dashboard.

25 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

19. Click on stable

20. Select according to you os and Copy and paste chromedriver link in
chrome it will download automatically
26 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

21. the file will be downloaded , extract the files and set the path
22. open VS code and create a .python file and add this
code from selenium import webdriver
from [Link] import By
from [Link] import Keys
from [Link] import Service
import time

# Specify the path to your ChromeDriver


chrome_service = Service("C:\\Program Files\\chromedriver-
win64\\[Link]")
# Make sure to include the actual '[Link]' file
# Set up the WebDriver for Chrome
driver = [Link](service=chrome_service)
try:
# Step 1: Open Google in the browser
[Link]("[Link]
27 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

# Step 2: Locate the search box using the name attribute


search_box = driver.find_element([Link], "q")

# Step 3: Enter the search term "selenium" and submit the form
search_box.send_keys("[Link]
search_box.send_keys([Link])

# Optional: Wait for a few seconds to see the search results


[Link](20)
finally:
# Step 4: Close the browser
[Link]()

23. Make sure to change the path of the driver in the code to avoid errors

24. Run the code


28 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

Output :
Cmrcet official website will open in chrome browser

WEEK – 11
Write a simple program in JavaScript and perform testing using Selenium.
1. Open VS code and create html and javascript files
2. Create html file and paste this code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sum Calculator</title>
<style>
body{
text-align: center;
29 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

}
</style>
</head>
<body>
<h1>Sum Calculator</h1>
<input type="number" id="num1" placeholder="Enter first number">
<input type="number" id="num2" placeholder="Enter second number">
<button id="add">Add</button>
<p>Result: <span id="result">0</span></p>

<script>
function calculateSum(a, b) {
return a + b;
}

[Link]('add').addEventListener('click', function() {
const num1 = parseInt([Link]('num1').value, 10);
const num2 = parseInt([Link]('num2').value, 10);
const result = calculateSum(num1, num2);
[Link]('result').textContent = result;
});
</script>
</body>
</html>

3. Create on javascript file and paste this code :

30 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

const webdriver = require('selenium-webdriver');


const assert = require('assert');

const driver = new [Link]().forBrowser('chrome').build();

async function runTest()


{ try {
// Open the HTML file in the browser
await [Link]('[Link] + dirname + '/[Link]');
// Find the input elements and enter values
const num1 = await [Link]([Link]('num1'));
await [Link]('50');

const num2 = await [Link]([Link]('num2'));


await [Link]('10');

// Click the "Add" button


const addButton = await [Link]([Link]('add'));
await [Link]();

// Get the result text and verify it


const result = await [Link]([Link]('result'));
const text = await [Link]();
[Link](text, '60', 'Sum calculation is incorrect');

[Link]('Test passed: Sum is correct');


} catch (error) {
31 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

[Link]('Test failed:', error);


} finally {
// Wait for user input to close the browser
[Link]('Press any key to exit...');
[Link](true);
[Link]();
[Link]('data', async () => {
await [Link]();
[Link](0);
});
}
}

runTest();

4. Open terminal
1. npm install selenium-webdriver
2. node [Link]

Output:

32 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

33 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

WEEK - 12
12. Develop test cases for the above containerized application using selenium.
Prerequisites :
Docker Desktop
Python (for running scripts locally if needed)
Selenium (pip install selenium)
Steps for execution:
Clone this repository to your local repository [Link]
Or follow the below
steps Step-1:
Create a directory named selenium-test and navigate to the current directory path.
tests/
├── Dockerfile
├── [Link]
├── [Link]
└── [Link]

Step 2: Create the [Link] File


This is your sample web page that Selenium will interact with.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selenium Login Example</title>
</head>
<body>
<!-- Homepage -->
<div id="homepage">
<h1>Welcome!!!!!!</h1>
<!-- Get Started Free Button -->
<a href="#loginPage" id="get-started" onclick="navigateToLogin()">Get started</a>
</div>
<!-- Login Page -->
<div id="loginPage" style="display: none;">
<h2>Login to the Page</h2>
<form onsubmit="return validateLogin()">
<label for="user_email_login">Email:</label>
<input type="email" id="user_email_login" name="user_email_login" required>
<br><br>
<label for="user_password">Password:</label>
<input type="password" id="user_password" name="user_password" required>

34 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

<br><br>
<button type="submit" name="commit">Login</button>
</form>
<p id="error-message" style="color: red; display: none;">Invalid credentials, please try
again.</p>
</div>
<!-- Dashboard Section (only shown after successful login) -->
<div id="dashboard" style="display: none;">
<h2>Welcome to Your Dashboard!</h2>
<p>This is the dashboard area you see after a successful login.</p>
</div>

<script>
// Function to navigate to the login page
function navigateToLogin() {
[Link]('homepage').[Link] = 'none';
[Link]('loginPage').[Link] = 'block';
}

// Function to validate login credentials


function validateLogin() {
const email = [Link]('user_email_login').value;
const password = [Link]('user_password').value;

if (email === "abc@[Link]" && password === "password") {


// Hide login page and display dashboard
[Link]('loginPage').[Link] = 'none';
[Link]('dashboard').[Link] = 'block';
return false; // Prevent actual form submission
} else {
// Show error message if credentials are incorrect
[Link]('error-message').[Link] =
'block'; return false; // Prevent actual form submission
}
}
</script>
</body>
</html>
Step 3: Create the Dockerfile
This Dockerfile sets up a simple HTTP server to serve your [Link] file.

# Use the official Python image as the base image


FROM python:3.9
35 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

# Set the working directory in the container


WORKDIR /app
# Copy the [Link] file to the container
COPY [Link] .

# Expose port 8000 for the HTTP server


EXPOSE 8000

# Start a simple HTTP server to serve the [Link]


file CMD ["python", "-m", "[Link]", "8000"]

Step-4: Create the Selenium Test Script


This script will automate testing of your HTML page using Selenium.

from selenium import webdriver


from [Link] import By
from [Link] import WebDriverWait
from [Link] import expected_conditions as
EC import time

print("Test Execution Started")


options =
[Link]()
options.add_argument('--ignore-ssl-errors=yes')
options.add_argument('--ignore-certificate-errors')

# Start the Selenium WebDriver


driver = [Link](
command_executor='[Link]
options=options
)

# Maximize the window size


driver.maximize_window()
[Link](10)
[Link]("[Link] # Access the local server
[Link](10)

try:
# Wait for the "Get started free" link to be
clickable link = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.LINK_TEXT, "Get started"))
)
[Link]() # Click the link
36 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

[Link](10) # Wait for any resulting page to load

37 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

WebDriverWait(driver, 10).until(
EC.presence_of_element_located(([Link], "user_email_login))
)
WebDriverWait(driver, 10).until(
EC.presence_of_element_located(([Link], "user_password"))
)

# Enter login credentials


username = driver.find_element([Link],
"user_email_login") password =
driver.find_element([Link], "user_password") login_button
= driver.find_element([Link], "commit")

username.send_keys("abc@[Link]") # Replace with actual username


password.send_keys("password") # Replace with actual password
login_button.click()

# Check for a post-login element (adjust to your page's unique element for logged-in users)
try:
error_message = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(([Link], "error-message"))
)
[Link](10)
print("Login failed: Incorrect credentials")
except:
# No error message found, proceed with checking for dashboard
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(([Link], "dashboard")) # Replace with actual post-
login element ID
)
print("Login Successful!")

except Exception as e:
print(f"An error occurred while trying to click the link: {e}")

finally:
# Ensure the browser quits after execution
[Link]()
print("Test Execution Completed!")

Step 5: Create the [Link] File


This file defines two services: your HTML server and the Selenium Chrome
container.
app:
38 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch
Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

build:

39 | P a g e Prepared by Faculty M Shiva Kumar and 22 batch


Students CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

context: .
dockerfile: Dockerfile
container_name: html-server
ports:
- "8000:8000"
selenium:
image: selenium/standalone-chrome
container_name: selenium-chrome
ports:
- "4444:4444"
depends_on:
- appp-6: Build and Run Your Docker Containers
In terminal use docker-compose up –build
This command will:
3. Build the Docker image for your HTML server.
4. Pull the Selenium standalone Chrome image.
5. Start both services.
Press v to navigate to docker.

And Click on the links.

310 | P a g Prepared by Faculty M Shiva Kumar and 22 batch


eStudents CSE
CMRCET DEVOPS LAB MANUAL R22 CSE

8000:8000

4444

Step 7: Relenium Test Script


While your containers are running, open a new terminal and run:
In terminal

311 | P a g Prepared by Faculty M Shiva Kumar and 22 batch


eStudents CSE

You might also like