MVSR Engineering College (A) · Department of Information Technology · U21PC683IT
| git init | Initializes a new empty Git repository in the current directory. |
| git clone <url> | Clones an existing remote repository to the local machine. |
| git add . | Stages all modified and new files for the next commit. |
| git commit -m "msg" | Records staged changes to the repository with a descriptive message. |
| git push origin main | Pushes local commits to the remote repository branch named main. |
| docker build -t <name> . | Builds a Docker image from the Dockerfile in the current directory and tags it. |
| docker run -d -p 8080:80 <img> | Runs a container in detached mode, mapping host port 8080 to container port 80. |
| docker ps | Lists all currently running containers with their IDs, names, and status. |
| docker images | Shows all locally available Docker images with their tags and sizes. |
| docker push <user/img:tag> | Pushes a tagged image to Docker Hub (or another registry). |
| kubectl get pods | Lists all pods in the default namespace with their status. |
| kubectl apply -f file.yaml | Creates or updates resources described in a YAML manifest file. |
| kubectl describe pod <name> | Shows detailed information about a specific pod (events, IP, containers). |
| kubectl delete deployment <n> | Deletes a named deployment and all its associated pods. |
| kubectl expose deploy <n> --port=80 | Creates a Service to expose a deployment on the specified port. |
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello from Java Docker Container!"); } }
FROM openjdk:17-jdk-slim WORKDIR /app COPY HelloWorld.java . RUN javac HelloWorld.java CMD ["java", "HelloWorld"]
# Push code to GitHub git init git add . git commit -m "Add Java HelloWorld" git remote add origin https://github.com/<username>/java-docker.git git push -u origin main # Build and run Docker image locally docker build -t java-hello . docker run java-hello # Push image to DockerHub docker login docker tag java-hello <dockerhub-username>/java-hello:latest docker push <dockerhub-username>/java-hello:latest
#include <stdio.h> int main() { printf("Hello from C in Docker!\n"); return 0; }
FROM gcc:latest WORKDIR /app COPY hello.c . RUN gcc -o hello hello.c CMD ["./hello"]
# Push code to GitHub git init && git add . && git commit -m "C Docker app" git remote add origin https://github.com/<username>/c-docker.git git push -u origin main # Build, run, push to DockerHub docker build -t c-hello . docker run c-hello docker tag c-hello <dockerhub-username>/c-hello:latest docker push <dockerhub-username>/c-hello:latest
<!DOCTYPE html> <html><head><title>DevOps HTML App</title></head> <body> <h1>Hello from HTML in Docker!</h1> <p>Deployed via nginx container.</p> </body></html>
FROM nginx:alpine COPY index.html /usr/share/nginx/html/index.html EXPOSE 80
docker build -t html-app .
docker run -d -p 8080:80 html-app
# Visit http://localhost:8080
docker tag html-app <user>/html-app:latest
docker push <user>/html-app:latestprint("Hello from Python in Docker!") name = "DevOps" print(f"Welcome to {name} Lab")
FROM python:3.11-slim WORKDIR /app COPY app.py . CMD ["python", "app.py"]
docker build -t python-app . docker run python-app docker tag python-app <user>/python-app:latest docker push <user>/python-app:latest
const http = require('http'); const server = http.createServer((req, res) => { res.end('Hello from Node.js Docker Container!\n'); }); server.listen(3000, () => console.log('Server running on port 3000'));
FROM node:18-alpine WORKDIR /app COPY app.js . EXPOSE 3000 CMD ["node", "app.js"]
docker build -t node-app . docker run -d -p 3000:3000 node-app docker push <user>/node-app:latest
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return '<h1>Hello from Flask in Docker!</h1>' if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
flask
FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY app.py . EXPOSE 5000 CMD ["python", "app.py"]
docker build -t flask-app .
docker run -d -p 5000:5000 flask-app
# Visit http://localhost:5000
docker push <user>/flask-app:latest#include <stdio.h> int main() { printf("Hello from C!\n"); return 0; }
# Push to GitHub git init && git add . && git commit -m "C program" git remote add origin https://github.com/<user>/c-jenkins.git git push -u origin main
C-Job → Select Freestyle project → OKgcc -o hello hello.c ./hello
a, b = 10, 3 print(f"ADD: {a} + {b} = {a+b}") print(f"SUB: {a} - {b} = {a-b}") print(f"MUL: {a} * {b} = {a*b}") print(f"DIV: {a} / {b} = {a/b:.2f}")
python3 calc.py
public class ReverseNumber { public static void main(String[] args) { int num = 12345, rev = 0; while (num != 0) { rev = rev * 10 + num % 10; num /= 10; } System.out.println("Reverse: " + rev); } }
javac ReverseNumber.java java ReverseNumber
# Pull and run hello-world image docker pull hello-world docker run hello-world # List all containers including stopped docker ps -a
echo "Hello from Jenkins Shell" and date# Build every 5 minutes: H/5 * * * * # Build daily at midnight: 0 0 * * * # Build every hour: H * * * *
<!DOCTYPE html> <html><head><title>Registration</title></head> <body> <h2>Student Registration Form</h2> <form> <label>Name: <input type="text" name="name"></label><br><br> <label>Email: <input type="email" name="email"></label><br><br> <label>Phone: <input type="tel" name="phone"></label><br><br> <input type="submit" value="Register"> </form> </body></html>
., Index: registration.htmlpipeline {
agent any
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Build') {
steps { echo 'Building the application...' }
}
stage('Test') {
steps { echo 'Running tests...' }
}
stage('Deploy') {
steps { echo 'Deploying...' }
}
}
post {
always { echo 'Pipeline complete!' }
}
}Jenkinsfile → Save → Build Nowpublic class Pattern { public static void main(String[] args) { int n = 5; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) System.out.print("* "); System.out.println(); } } }
n = 5 for i in range(1, n+1): print('* ' * i)
script_file# Detect and run based on uploaded file extension
if [ -f "script_file" ]; then
if python3 -c "import py_compile; py_compile.compile('script_file')" 2>/dev/null; then
python3 script_file
else
javac script_file && java $(basename script_file .java)
fi
fi# Pull Ubuntu image docker pull ubuntu # Run named container interactively docker run -it --name MyContainer ubuntu /bin/bash # Inside container — execute shell commands: ls pwd echo "Hello from MyContainer" cat /etc/os-release exit # From host — see all containers docker ps -a
pipeline {
agent any
stages {
stage('Stage 1: Checkout') {
steps { echo 'Checking out source code' }
}
stage('Stage 2: Build') {
steps { echo 'Building the project' }
}
stage('Stage 3: Test') {
steps { echo 'Running unit tests' }
}
stage('Stage 4: Package') {
steps { echo 'Packaging the application' }
}
stage('Stage 5: Deploy') {
steps { echo 'Deploying to server' }
}
}
}# Pull and run Python image interactively docker pull python:3.11-slim docker run -it python:3.11-slim /bin/sh # Inside container: python3 --version python3 -c "print('Hello from Python Container')" python3 -c "import sys; print(sys.version)" exit
# Create nginx deployment kubectl create deployment nginx-deploy --image=nginx # Scale to 3 replicas kubectl scale deployment nginx-deploy --replicas=3 # Expose as a service kubectl expose deployment nginx-deploy --port=80 --type=NodePort # Run kubectl commands kubectl get deployments kubectl get pods kubectl get services kubectl describe deployment nginx-deploy
docker pull node:18-alpine docker run -it node:18-alpine /bin/sh # Inside container: node --version node -e "console.log('Hello from Node Container')" node -e "console.log(2+3)" exit
kubectl create deployment python-deploy --image=python:3.11-slim \
-- python3 -c "import time; [print('running',i) or time.sleep(5) for i in range(100)]"
kubectl scale deployment python-deploy --replicas=2
kubectl get pods
kubectl get deployments
kubectl describe deployment python-deploy
kubectl logs <pod-name>docker pull nginx
docker run -d --name mynginx -p 8080:80 nginx
docker exec -it mynginx /bin/bash
# Inside container:
nginx -v
ls /usr/share/nginx/html
cat /etc/nginx/nginx.conf
exit
docker stop mynginx
docker rm mynginxkubectl create deployment mongo-deploy --image=mongo:latest kubectl expose deployment mongo-deploy --port=27017 kubectl get deployments kubectl get pods kubectl get services kubectl describe deployment mongo-deploy kubectl logs <mongo-pod-name>
# File structure:
registration-app/
├── index.html (registration form)
└── DockerfileFROM nginx:alpine COPY index.html /usr/share/nginx/html/index.html EXPOSE 80
# Push code to GitHub git init && git add . && git commit -m "HTML registration app" git remote add origin https://github.com/<user>/registration-app.git git push -u origin main # Build, run, push to DockerHub docker build -t registration-app . docker run -d -p 8080:80 registration-app docker login docker tag registration-app <user>/registration-app:latest docker push <user>/registration-app:latest
version: '3' services: bbConA: image: busybox container_name: bbConA command: sh -c "sleep 3600" networks: - mynet bbConB: image: busybox container_name: bbConB command: sh -c "sleep 3600" networks: - mynet networks: mynet: driver: bridge
# Start both containers docker-compose up -d # Verify both are running docker ps # Ping bbConB from bbConA docker exec bbConA ping -c 4 bbConB # Stop containers docker-compose down
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort# Apply manifests kubectl apply -f nginx-deployment.yaml kubectl apply -f nginx-service.yaml # Verify kubectl get deployments kubectl get pods kubectl get services kubectl describe deployment nginx-deployment
kubectl create deployment node-deploy --image=node:18-alpine \
-- node -e "setInterval(()=>console.log('Node running'),5000)"
kubectl get deployments
kubectl get pods
kubectl expose deployment node-deploy --port=3000
kubectl logs <pod-name>npm install selenium-webdriver. Download ChromeDriver matching your Chrome version.const { Builder } = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); (async function main() { let driver = await new Builder() .forBrowser('chrome') .build(); try { await driver.get('https://www.google.com'); console.log('Title:', await driver.getTitle()); await driver.sleep(3000); } finally { await driver.quit(); } })();
node openGoogle.js
<!DOCTYPE html><html><body> <form id="loginForm"> <input type="text" id="username" placeholder="Username"> <input type="password" id="password" placeholder="Password"> <button type="button" onclick="validate()">Login</button> </form> <p id="msg"></p> <script> function validate() { var u = document.getElementById('username').value; var p = document.getElementById('password').value; document.getElementById('msg').innerText = (u==='admin' && p==='1234') ? 'Login Successful!' : 'Invalid Credentials'; } </script></body></html>
const { Builder, By } = require('selenium-webdriver'); const path = require('path'); (async function () { let driver = await new Builder().forBrowser('chrome').build(); try { await driver.get('file://' + path.resolve('login.html')); // Test 1: Valid login await driver.findElement(By.id('username')).sendKeys('admin'); await driver.findElement(By.id('password')).sendKeys('1234'); await driver.findElement(By.css('button')).click(); let msg = await driver.findElement(By.id('msg')).getText(); console.log('Test 1:', msg); // Test 2: Invalid login await driver.findElement(By.id('username')).clear(); await driver.findElement(By.id('password')).clear(); await driver.findElement(By.id('username')).sendKeys('wrong'); await driver.findElement(By.id('password')).sendKeys('bad'); await driver.findElement(By.css('button')).click(); msg = await driver.findElement(By.id('msg')).getText(); console.log('Test 2:', msg); } finally { await driver.quit(); } })();
const { Builder, By, until } = require('selenium-webdriver'); (async function () { let driver = await new Builder().forBrowser('chrome').build(); try { // Open college result website await driver.get('https://matrusri.skolo.in/'); // Wait for page to load await driver.wait(until.titleContains(''), 10000); // Print page title let title = await driver.getTitle(); console.log('Page Title:', title); // Get current URL let url = await driver.getCurrentUrl(); console.log('Current URL:', url); // Take screenshot let img = await driver.takeScreenshot(); require('fs').writeFileSync('result.png', img, 'base64'); console.log('Screenshot saved as result.png'); await driver.sleep(3000); } finally { await driver.quit(); } })();
node examResult.js
<!DOCTYPE html><html><head><title>Calculator</title></head><body> <h2>Calculator</h2> <input type="number" id="a" placeholder="Number 1"> <input type="number" id="b" placeholder="Number 2"><br><br> <button onclick="calc('add')">ADD</button> <button onclick="calc('sub')">SUB</button> <button onclick="calc('mul')">MUL</button> <button onclick="calc('div')">DIV</button> <p id="result"></p> <script> function calc(op){ var a=+document.getElementById('a').value, b=+document.getElementById('b').value, r; if(op==='add') r=a+b; else if(op==='sub') r=a-b; else if(op==='mul') r=a*b; else r = b?a/b:'Error'; document.getElementById('result').innerText='Result: '+r; } </script></body></html>
const { Builder, By } = require('selenium-webdriver'); const path = require('path'); (async function () { let driver = await new Builder().forBrowser('chrome').build(); try { await driver.get('file://' + path.resolve('calculator.html')); async function test(btnText, a, b, expected) { let inA = driver.findElement(By.id('a')); let inB = driver.findElement(By.id('b')); await inA.clear(); await inA.sendKeys(String(a)); await inB.clear(); await inB.sendKeys(String(b)); await driver.findElement(By.xpath(`//button[text()='${btnText}']`)).click(); let res = await driver.findElement(By.id('result')).getText(); console.log(`${btnText}(${a},${b}) → ${res} | Expected: Result: ${expected}`); } await test('ADD', 10, 5, 15); await test('SUB', 10, 5, 5); await test('MUL', 10, 5, 50); await test('DIV', 10, 5, 2); } finally { await driver.quit(); } })();
# Push Java program (use HelloWorld.java or ReverseNumber.java) to GitHub first
git push -u origin mainmytoken123javac HelloWorld.java java HelloWorld
# Trigger from curl (remote build URL): curl http://<jenkins-url>/job/Java-Remote-Job/build?token=mytoken123 # With auth if Jenkins security enabled: curl -u username:api-token \ http://<jenkins-url>/job/Java-Remote-Job/build?token=mytoken123
calc.py file from Program 8. Push it to GitHub. Configure Jenkins to poll GitHub and auto-build on changes.# Poll every minute (checks GitHub for new commits) * * * * * # Poll every 5 minutes H/5 * * * *
python3 calc.pypublic class Calculator { public static void main(String[] args) { int a = 20, b = 4; System.out.println("ADD: " + (a+b)); System.out.println("SUB: " + (a-b)); System.out.println("MUL: " + (a*b)); System.out.println("DIV: " + (a/b)); } }
a, b = 20, 4 print(f"ADD: {a+b}"); print(f"SUB: {a-b}") print(f"MUL: {a*b}"); print(f"DIV: {a/b}")
LANG, Choices = Java and Pythonuploaded_script# Use the LANG variable to decide which runner to use if [ "$LANG" = "Python" ]; then python3 uploaded_script else # Java: rename and compile cp uploaded_script Calculator.java javac Calculator.java java Calculator fi