{"id":30412800,"url":"https://github.com/akarsh/devopslab","last_synced_at":"2025-08-22T02:12:24.241Z","repository":{"id":305528633,"uuid":"922238758","full_name":"akarsh/DevOpsLab","owner":"akarsh","description":"Repository is covering the experiments mentioned in DevOps Lab manual for course in JNTUH syllabus","archived":false,"fork":false,"pushed_at":"2025-07-20T15:28:27.000Z","size":7019,"stargazers_count":1,"open_issues_count":0,"forks_count":27,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-20T17:26:51.393Z","etag":null,"topics":["docker","git","github","jenkins","kubernetes","minikube","selenium"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akarsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-25T17:24:32.000Z","updated_at":"2025-07-20T15:28:30.000Z","dependencies_parsed_at":"2025-07-20T17:38:05.654Z","dependency_job_id":null,"html_url":"https://github.com/akarsh/DevOpsLab","commit_stats":null,"previous_names":["akarsh/devopslab"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/akarsh/DevOpsLab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FDevOpsLab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FDevOpsLab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FDevOpsLab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FDevOpsLab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akarsh","download_url":"https://codeload.github.com/akarsh/DevOpsLab/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akarsh%2FDevOpsLab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271574431,"owners_count":24783319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","git","github","jenkins","kubernetes","minikube","selenium"],"created_at":"2025-08-22T02:12:23.157Z","updated_at":"2025-08-22T02:12:24.233Z","avatar_url":"https://github.com/akarsh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Table of Contents\n1. [Experiment 1](#experiment-1)\n2. [Experiment 2](#experiment-2)\n3. [Experiment 3](#experiment-3)\n4. [Experiment 4](#experiment-4)\n5. [Experiment 5](#experiment-5)\n6. [Experiment 6](#experiment-6)\n7. [Experiment 7](#experiment-7)\n8. [Experiment 8](#experiment-8)\n9. [Experiment 9](#experiment-9)\n10. [Experiment 10](#experiment-10)\n11. [Experiment 11](#experiment-11)\n12. [Experiment 12](#experiment-12)\n\n# Experiment 1\n\n# Write code for a simple user registration form for an event.\n\n## Files\n\n- `app.py`: The main Flask application file that contains the routes and logic for the user registration form.\n- `Dockerfile`: The Dockerfile used to build the Docker image for the Flask application.\n- `Dockerfile.test`: The Dockerfile used to build the Docker image for running unit tests on the Flask application.\n- `requirements.txt`: A file listing the Python dependencies required to run the Flask application.\n- `templates/`: A directory containing HTML templates for the Flask application.\n  - `register.html`: The HTML template for the user registration form.\n  - `success.html`: The HTML template displayed after a successful user registration.\n\n## Build\n\nTo build the Docker image for the Flask application, run the following command:\n\n```sh\ndocker build --no-cache -t simple-flask-app .\n```\n\n## Run\n\nTo run the Docker container for the Flask application, use the following command:\n\n```sh\ndocker run -p 80:80 simple-flask-app\n```\n\nAfter running the container, open your web browser and navigate to `http://0.0.0.0:80/register` to access the user registration form.\n\n## Testing\n\nTo run the unit tests for `app.py` using Docker, follow these steps:\n\n1. Build the Docker image for testing:\n\n```sh\ndocker build -f Dockerfile.test -t simple-flask-app-test .\n```\n\n2. Run the Docker container to execute the tests:\n\n```sh\ndocker run simple-flask-app-test\n```\n\nThis command will discover and run all the unit tests in the `test_app.py` file.\n\n\n\n\n# Experiment 2\n\n# Explore Git and GitHub commands\n\n# Git\n\nGit is a distributed version control system that helps developers collaborate on projects. It allows you to track changes, revert to previous stages, and branch to create separate lines of development.\n\n# GitHub\n\nGitHub is a web-based platform that uses Git for version control. It provides a collaborative environment for developers to host and review code, manage projects, and build software together.\n\n## Git commands\n\n- `git init`: Initialize a new Git repository\n- `git clone \u003crepository\u003e`: Clone an existing repository\n- `git status`: Show the working directory status\n- `git add \u003cfile\u003e`: Add a file to the staging area\n- `git commit -m \"message\"`: Commit changes with a message\n- `git log`: Show the commit history\n- `git branch`: List, create, or delete branches\n- `git checkout \u003cbranch\u003e`: Switch to a different branch\n- `git merge \u003cbranch\u003e`: Merge a branch into the current branch\n- `git pull`: Fetch and merge changes from a remote repository\n- `git pull origin \u003cbranch\u003e`: Fetch and merge changes from a remote repository branch\n- `git push`: Push changes to a remote repository\n- `git push origin \u003cbranch\u003e`: Push changes to a remote repository branch\n\n### About gh\n\n`gh` is GitHub's official command-line tool. It brings GitHub's features to your terminal, allowing you to interact with GitHub repositories, issues, pull requests, and more directly from the command line. This tool helps streamline your workflow by integrating GitHub operations into your existing terminal commands.\n\n#### gh commands\n\n- `gh auth login`: Authenticate with your GitHub account\n- `gh repo create`: Create a new repository on GitHub\n- `gh repo clone \u003crepository\u003e`: Clone a GitHub repository\n- `gh repo fork \u003crepository\u003e`: Fork a repository on GitHub\n- `gh issue list`: List issues in a repository\n- `gh issue create`: Create a new issue in a repository\n- `gh pr list`: List pull requests in a repository\n- `gh pr create`: Create a new pull request\n- `gh pr merge \u003cpull-request\u003e`: Merge a pull request\n\n### Pull request creation in GitHub\n\nA pull request (PR) is a method of submitting contributions to a project. It allows you to notify project maintainers about changes you'd like them to consider. Here's how to create a pull request in GitHub:\n\n1. **Fork the repository**: Create a copy of the repository under your own GitHub account.\n2. **Clone the repository**: Clone the forked repository to your local machine using `git clone \u003crepository-url\u003e`.\n3. **Create a new branch**: Create a new branch for your changes using `git checkout -b \u003cbranch-name\u003e`.\n4. **Make your changes**: Make the necessary changes to the codebase.\n5. **Commit your changes**: Commit your changes with a descriptive message using `git commit -m \"Your commit message\"`.\n6. **Push your changes**: Push the changes to your forked repository using `git push origin \u003cbranch-name\u003e`.\n7. **Create the pull request**: Go to the original repository on GitHub and click on the \"New pull request\" button. Select the branch you pushed your changes to and create the pull request.\n\nOnce the pull request is created, the project maintainers will review your changes and decide whether to merge them into the main codebase.\n\n\n\n\n# Experiment 3\n\n# Practice Source code management on GitHub. Experiment with the source code in experiment 1.\n\n## Steps to Create a Repository on GitHub and Make a Git Commit\n\n1. **Create a Repository on GitHub:**\n\n   - Go to [GitHub](https://github.com) and log in to your account.\n   - Click on the `+` icon in the top right corner and select `New repository`.\n   - Enter a repository name (e.g., `Experiment1`), add a description (optional), and choose the visibility (public or private).\n   - Click on `Create repository`.\n\n2. **Initialize Git in the `Experiment1` Folder:**\n\n   - Open a terminal and navigate to the `Experiment1` folder:\n     ```sh\n     cd /path/to/Experiment1\n     ```\n   - Initialize a new Git repository:\n     ```sh\n     git init\n     ```\n\n3. **Add Remote Repository:**\n\n   - Add the GitHub repository as a remote:\n     ```sh\n     git remote add origin https://github.com/your-username/Experiment1.git\n     ```\n    **Note:** Replace `your-username` with your actual GitHub username.\n\n\n4. **Add Files and Make a Commit:**\n\n   - Add all files in the Experiment1 folder to the staging area:\n     ```sh\n     git add .\n     ```\n   - Commit the changes with a message:\n     ```sh\n     git commit -m \"Initial commit for Experiment1\"\n     ```\n\n5. **Push Changes to GitHub:**\n   - Push the commit to the GitHub repository:\n     ```sh\n     git push -u origin master\n     ```\n\nYou have now created a repository on GitHub and committed the files from the Experiment1 folder.\n\n\n\n\n# Experiment 4\n\n# Jenkins installation and setup, explore the environment.\n\n## About Jenkins\n\nJenkins is an open-source automation server that helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery (CI/CD).\n\n## How to Install Jenkins\n\n### Using Docker\n\n1. **Install Docker:**\n   If Docker is not already installed, follow the instructions on the [Docker website](https://docs.docker.com/get-docker/) to install it.\n\n2. **Run Jenkins Container:**\n   Pull the Jenkins image and run it in a container.\n   ```sh\n   docker pull jenkins/jenkins:lts\n   docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts\n   ```\n   - `docker pull jenkins/jenkins:lts`: This command pulls the latest stable (LTS) Jenkins image from the Docker repository.\n   - `docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts`: This command runs the Jenkins container with the following options:\n     - `-p 8080:8080`: Maps port 8080 on the host to port 8080 on the container, allowing access to the Jenkins web interface.\n     - `-p 50000:50000`: Maps port 50000 on the host to port 50000 on the container, used for Jenkins agent communication.\n     - `-v jenkins_home:/var/jenkins_home`: Mounts the `jenkins_home` volume to persist Jenkins data.\n\n## How to Start Jenkins\n\n1. **Access Jenkins:**\n   Open your web browser and go to `http://localhost:8080`. You will see the Jenkins setup wizard.\n\n## How to Explore Jenkins\n\n1. **Unlock Jenkins:**\n   Retrieve the initial admin password.\n\n   ```sh\n   docker exec -it \u003ccontainer_id\u003e cat /var/jenkins_home/secrets/initialAdminPassword\n   ```\n\n   Enter this password in the setup wizard to unlock Jenkins.\n\n2. **Install Suggested Plugins:**\n   Follow the setup wizard to install the suggested plugins.\n\n3. **Create Admin User:**\n   Create your first admin user as prompted by the setup wizard.\n\n4. **Start Using Jenkins:**\n   Once the setup is complete, you can start creating jobs, configuring pipelines, and exploring Jenkins features.\n\n\n\n\n# Experiment 5\n\n# Demonstrate continuous integration and development using Jenkins.\n\n## Prerequisites\n\n- Docker installed\n- Git installed\n- A GitHub repository\n\n## Setup Jenkins with Docker\n\n1. Build the Docker image:\n\n   ```sh\n   docker build -t jenkins-docker . --platform=linux/amd64\n   ```\n\n2. Run the Docker container:\n\n   ```sh\n   docker run -d -p 8080:8080 -p 50000:50000 --name jenkins-docker jenkins-docker\n   ```\n\n3. Access Jenkins at `http://localhost:8080` and complete the setup process.\n\n## Steps\n\n1. **Create a Jenkins Pipeline:**\n\n   - Open Jenkins and create a new pipeline job.\n   - In the pipeline configuration, define your pipeline script.\n\n2. **Configure Source Code Management:**\n\n   - Under the Source Code Management section, select Git.\n   - Enter the repository URL and credentials if required.\n\n3. **Define Build Steps:**\n\n   - In the pipeline script, define the stages for building, testing, and deploying your application.\n\n4. **Run the Pipeline:**\n\n   - Save the configuration and run the pipeline.\n   - Monitor the build process and ensure it completes successfully.\n\n5. **Continuous Integration:**\n\n   - Make changes to your code and push them to the repository.\n   - Observe Jenkins automatically triggering the pipeline and running the build.\n\n6. **Continuous Deployment:**\n   - Configure the pipeline to deploy the application to a server or cloud service after a successful build.\n\n## Example: Using Jenkins to create a pipeline job\n\n### Prerequisites\n\n- Jenkins installed and running\n\n### Setup\n\n1. Open Jenkins and create a new pipeline job named `Hello World Pipeline`.\n2. Add the below pipeline script\n\n### Jenkins Pipeline Script\n\n```groovy\npipeline {\n    agent any\n\n    stages {\n        stage('Hello') {\n            steps {\n                echo 'Hello World'\n            }\n        }\n    }\n}\n```\n\n### Running the Pipeline\n\n1. Save the pipeline configuration.\n2. Run the pipeline and monitor the build process.\n3. Make changes to the Experiment1 files and push them to the repository.\n4. Observe Jenkins automatically triggering the pipeline and running the build and test stages.\n\n## Conclusion\n\nBy following these steps, you have demonstrated continuous integration and development using Jenkins.\n\n\n\n\n# Experiment 6\n\n# Explore Docker commands for content management.\n\n## Introduction\n\nIn this experiment, we will explore various Docker commands used for content management. Docker is a platform that enables developers to automate the deployment of applications inside lightweight, portable containers.\n\n## Objectives\n\n- Understand the basic Docker commands for managing content.\n- Learn how to create, manage, and delete Docker images and containers.\n- Explore Docker volumes and networks.\n\n## Docker Commands for Content Management\n\n1. **docker pull**: Download an image from a Docker registry.\n\n   ```sh\n   docker pull \u003cimage_name\u003e\n   ```\n\n2. **docker images**: List all Docker images on the local machine.\n\n   ```sh\n   docker images\n   ```\n\n3. **docker rmi**: Remove one or more Docker images.\n\n   ```sh\n   docker rmi \u003cimage_name\u003e\n   ```\n\n4. **docker run**: Create and start a new container from an image.\n\n   ```sh\n   docker run \u003cimage_name\u003e\n   ```\n\n5. **docker ps**: List all running containers.\n\n   ```sh\n   docker ps\n   ```\n\n6. **docker stop**: Stop a running container.\n\n   ```sh\n   docker stop \u003ccontainer_id\u003e\n   ```\n\n7. **docker rm**: Remove one or more stopped containers.\n\n   ```sh\n   docker rm \u003ccontainer_id\u003e\n   ```\n\n8. **docker volume**: Manage Docker volumes.\n\n   ```sh\n   docker volume ls\n   docker volume create \u003cvolume_name\u003e\n   docker volume rm \u003cvolume_name\u003e\n   ```\n\n9. **docker network**: Manage Docker networks.\n   ```sh\n   docker network ls\n   docker network create \u003cnetwork_name\u003e\n   docker network rm \u003cnetwork_name\u003e\n   ```\n\n## Example: Running a Nginx Container\n\nLet's run an example to demonstrate the usage of Docker commands by running an Nginx container.\n\n1. **Pull the Nginx image**:\n\n   ```sh\n   docker pull nginx\n   ```\n\n2. **Run the Nginx container**:\n\n   ```sh\n   docker run --name mynginx -d -p 8080:80 nginx\n   ```\n\n   This command will start an Nginx container named `mynginx` and map port 8080 on the host to port 80 in the container.\n\n3. **List running containers**:\n\n   ```sh\n   docker ps\n   ```\n\n4. **Explore Nginx in the browser**:\n   Open your web browser and navigate to `http://localhost:8080`. You should see the Nginx welcome page.\n\n5. **Stop the Nginx container**:\n\n   ```sh\n   docker stop mynginx\n   ```\n\n6. **Remove the Nginx container**:\n\n   ```sh\n   docker rm mynginx\n   ```\n\n7. **Remove the Nginx image**:\n   ```sh\n   docker rmi nginx\n   ```\n\n\n\n\n# Experiment 7\n\n# Develop a simple containerized application using Docker\n\n## Dockerfile\n\nCreate a file named `Dockerfile` with the following content:\n\n```Dockerfile\n# Use an official Python runtime as a parent image\nFROM python:3.8-slim\n\n# Set the working directory in the container\nWORKDIR /app\n\n# Copy the current directory contents into the container at /app\nCOPY . /app\n\n# Run the hello.py script when the container launches\nCMD [\"python\", \"hello.py\"]\n```\n\n## Hello World Python Program\n\nCreate a file named `hello.py` with the following content:\n\n```python\nprint(\"Hello, World!\")\n```\n\n## Build the Docker Image\n\nRun the following command to build the Docker image:\n\n```sh\ndocker build -t hello-world-app .\n```\n\n## Run the Docker Container\n\nRun the following command to start a container from the image:\n\n```sh\ndocker run hello-world-app\n```\n\n\n\n\n# Experiment 8\n\n# Integrate Kubernetes and Docker.\n\n## Kubernetes and Docker Integration\n\nKubernetes and Docker are two essential tools in the world of containerization and orchestration. While Docker is a platform for developing, shipping, and running applications inside containers, Kubernetes is an orchestration system for managing containerized applications at scale.\n\n### Integration\n\n- **Docker**: Docker allows you to package your application and its dependencies into a container, ensuring that it runs consistently across different environments.\n- **Kubernetes**: Kubernetes manages these containers, providing features like automated deployment, scaling, and management of containerized applications.\n\nBy integrating Docker with Kubernetes, you can leverage the strengths of both tools to build, deploy, and manage scalable applications efficiently.\n\n### Differences\n\n- **Scope**:\n\n  - Docker focuses on the creation and management of individual containers.\n  - Kubernetes focuses on the orchestration of multiple containers across a cluster of machines.\n\n- **Components**:\n\n  - Docker includes components like Docker Engine, Docker Compose, and Docker Swarm.\n  - Kubernetes includes components like kubectl, kubelet, and kube-scheduler.\n\n- **Scaling**:\n  - Docker Swarm provides basic container orchestration and scaling.\n  - Kubernetes offers advanced orchestration, scaling, and management capabilities.\n\nUnderstanding these differences and how they complement each other is crucial for effectively using both tools in your DevOps workflow.\n\n## Steps to Integrate Kubernetes and Docker\n\n1. **Install Docker**:\n\n   - Follow the official Docker installation guide for your operating system: [Docker Installation](https://docs.docker.com/get-docker/)\n\n2. **Install Kubernetes (kubectl and minikube)**:\n\n   - Follow the official Kubernetes installation guide: [Kubernetes Installation](https://kubernetes.io/docs/tasks/tools/)\n\n3. **Start Minikube**:\n\n   ```sh\n   minikube start\n   ```\n\n4. **Build a Docker Image**:\n\n   - Create a Dockerfile for your application.\n   - Build the Docker image:\n\n   ```sh\n   docker build -t your-image-name .\n   ```\n\n5. **Push Docker Image to a Registry**:\n\n   - Tag your Docker image:\n\n   ```sh\n   docker tag your-image-name your-dockerhub-username/your-image-name\n   ```\n\n   - Push the image to Docker Hub:\n\n   ```sh\n   docker push your-dockerhub-username/your-image-name\n   ```\n\n6. **Create a Kubernetes Deployment**:\n\n   - Create a deployment YAML file (e.g., `deployment.yaml`):\n\n   ```yaml\n   apiVersion: apps/v1\n   kind: Deployment\n   metadata:\n     name: your-deployment-name\n   spec:\n     replicas: 2\n     selector:\n       matchLabels:\n         app: your-app-name\n     template:\n       metadata:\n         labels:\n           app: your-app-name\n       spec:\n         containers:\n           - name: your-container-name\n             image: your-dockerhub-username/your-image-name\n             ports:\n               - containerPort: 80\n   ```\n\n   - Apply the deployment:\n\n   ```sh\n   kubectl apply -f deployment.yaml\n   ```\n\n7. **Expose the Deployment**:\n\n   - Create a service YAML file (e.g., `service.yaml`):\n\n   ```yaml\n   apiVersion: v1\n   kind: Service\n   metadata:\n     name: your-service-name\n   spec:\n     type: LoadBalancer\n     selector:\n       app: your-app-name\n     ports:\n       - protocol: TCP\n         port: 80\n         targetPort: 80\n   ```\n\n   - Apply the service:\n\n   ```sh\n   kubectl apply -f service.yaml\n   ```\n\n8. **Access Your Application**:\n   - Get the URL of your application:\n   ```sh\n   minikube service your-service-name --url\n   ```\n   - Open the URL in your browser to access your application.\n\n\n\n\n# Experiment 9\n\n# Automate the process of running containerized application developed in experiment 7 using kubernetes\n\n## Introduction\nIn this experiment, we will automate the deployment of a containerized application using Kubernetes. This involves creating Kubernetes manifests for the application and deploying it to a Kubernetes cluster.\n\n## Prerequisites\n- Docker installed\n- Minikube installed and running\n- kubectl installed and configured\n- Ensure you have the necessary permissions to create resources in the Kubernetes cluster\n\n## Steps\n\n### 1. Start Minikube\nStart Minikube to create a local Kubernetes cluster:\n```sh\nminikube start\n```\n\n### 2. Set Minikube Context\nSet Minikube as the Kubernetes context:\n```sh\nkubectl config use-context minikube\n```\n\n### 3. Create and Expose Deployment\nCreate a sample deployment and expose it on port 8080:\n```sh\nkubectl create deployment hello-minikube --image=kicbase/echo-server:1.0\nkubectl expose deployment hello-minikube --type=NodePort --port=8080\n```\n\nIt may take a moment, but your deployment will soon show up when you run:\n```sh\nkubectl get services hello-minikube\n```\n\nThe easiest way to access this service is to let Minikube launch a web browser for you:\n```sh\nminikube service hello-minikube\n```\n\n### 4. Check Minikube Dashboard\nYou can also check the Minikube dashboard to monitor your cluster:\n```sh\nminikube dashboard\n```\n\n## Conclusion\nBy following these steps, you have automated the deployment of a containerized application using Kubernetes with Minikube.\n\n\n\n\n# Experiment 10\n\n# Install and explore selenium for automated testing\n\n## Using Python, Selenium, and Docker for Testing\n\n1. **Install Docker**: Follow the instructions on the [Docker website](https://docs.docker.com/get-docker/) to install Docker on your machine.\n\n2. **Create Docker Compose File**: Create a `docker-compose.yml` file to set up services for Python and Selenium.\n\n   ```yaml\n   version: \"3\"\n   services:\n     selenium:\n       image: selenium/standalone-firefox:latest\n       ports:\n         - \"4444:4444\"\n     test:\n       image: python:3.8-slim\n       volumes:\n         - .:/app\n       working_dir: /app\n       depends_on:\n         - selenium\n       entrypoint: [\"sh\", \"-c\", \"apt-get update \u0026\u0026 apt-get install -y netcat-openbsd \u0026\u0026 while ! nc -z selenium 4444; do sleep 1; done \u0026\u0026 pip install selenium \u0026\u0026 python ./test_script.py\"]\n   ```\n\n3. **Write a Selenium Test Script**: Create a Python script `test_script.py` with Selenium tests.\n\n   ```python\n   from selenium import webdriver\n   from selenium.webdriver.firefox.service import Service\n   from selenium.webdriver.common.by import By\n   from selenium.webdriver.firefox.options import Options\n\n   # Set up the Firefox WebDriver\n   options = Options()\n   options.headless = True\n   driver = webdriver.Remote(\n       command_executor='http://selenium:4444/wd/hub',\n       options=options\n   )\n\n   # Test: Open Selenium website and check the page title\n   driver.get(\"https://www.selenium.dev\")\n   assert \"Selenium\" in driver.title\n\n   # Print success message\n   print(\"Test passed: Selenium website title is correct.\")\n\n   driver.quit()\n   ```\n\n4. **Run the Docker Compose Services**:\n\n   ```sh\n   docker compose up --build\n   ```\n\n## Explanation of the Test and Output\n\n- The test script uses Selenium to open the Selenium website and check if the page title contains the word \"Selenium\".\n- If the test passes, a success message \"Test passed: Selenium website title is correct.\" is printed to the console.\n- When you run `docker compose up --build`, Docker will build and start the services defined in the `docker-compose.yml` file.\n- The `test` service will wait for the `selenium` service to be ready, install the necessary dependencies, and then execute the test script.\n- You will see the output of the test in the Docker console, including the success message if the test passes.\n\n\n\n\n# Experiment 11\n\n# Write a simple program in JavaScript and perform testing using Selenium\n\n## Using Docker Compose for Selenium Firefox to Test HTML, CSS, and JS\n\n1. **Install Docker**: Follow the instructions on the [Docker website](https://docs.docker.com/get-docker/) to install Docker on your machine.\n\n2. **Create Docker Compose File**: Create a `docker-compose.yml` file to set up services for Python and Selenium.\n\n   ```yaml\n   services:\n     selenium:\n       image: selenium/standalone-firefox:latest\n       ports:\n         - \"4444:4444\"\n       volumes:\n         - .:/app\n     test:\n       image: python:3.8-slim\n       volumes:\n         - .:/app\n       working_dir: /app\n       depends_on:\n         - selenium\n       entrypoint:\n         [\n           \"sh\",\n           \"-c\",\n           \"apt-get update \u0026\u0026 apt-get install -y netcat-openbsd \u0026\u0026 while ! nc -z selenium 4444; do sleep 1; done \u0026\u0026 pip install selenium \u0026\u0026 python ./test_script_docker.py\",\n         ]\n   ```\n\n3. **Create HTML, CSS, and JS Files**: Create a simple HTML file `index.html` that shows \"Hello World\" and changes the color via CSS.\n\n   ```html\n   \u003c!DOCTYPE html\u003e\n   \u003chtml lang=\"en\"\u003e\n     \u003chead\u003e\n       \u003cmeta charset=\"UTF-8\" /\u003e\n       \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n       \u003ctitle\u003eHello World\u003c/title\u003e\n       \u003clink rel=\"stylesheet\" href=\"styles.css\" /\u003e\n     \u003c/head\u003e\n     \u003cbody\u003e\n       \u003ch1 id=\"hello\"\u003eHello World\u003c/h1\u003e\n       \u003cscript src=\"script.js\"\u003e\u003c/script\u003e\n     \u003c/body\u003e\n   \u003c/html\u003e\n   ```\n\n4. **Create a CSS File**: Create a CSS file `styles.css` to style the webpage.\n\n   ```css\n   body {\n     font-family: Arial, sans-serif;\n     text-align: center;\n     margin-top: 50px;\n   }\n\n   #hello {\n     color: blue;\n   }\n   ```\n\n5. **Create a JavaScript File**: Create a JavaScript file `script.js` to add color to the webpage.\n\n   ```javascript\n   document.getElementById(\"hello\").style.color = \"blue\";\n   ```\n\n6. **Write a Selenium Test Script**: Create a Python script `test_script_docker.py` to test the HTML file.\n\n   ```python\n   from selenium import webdriver\n   from selenium.webdriver.firefox.service import Service\n   from selenium.webdriver.common.by import By\n   from selenium.webdriver.firefox.options import Options\n   import os\n   import time  # Added import for time\n\n   # Check if index.html file exists\n   file_path = \"/app/index.html\"\n   if not os.path.exists(file_path):\n       raise FileNotFoundError(f\"{file_path} does not exist\")\n   else:\n       print(f\"Found {file_path}\")\n\n   # Set up the Firefox WebDriver\n   options = Options()\n   options.headless = True\n   driver = webdriver.Remote(\n       command_executor='http://selenium:4444/wd/hub',\n       options=options\n   )\n\n   # Wait for the Selenium server to be ready\n   time.sleep(1)\n\n   try:\n       # Test: Open the local HTML file and check the content and color\n       abs_file_path = os.path.abspath(file_path)\n       print(f\"Absolute file path: {abs_file_path}\")\n       driver.get(f\"file://{abs_file_path}\")\n       element = driver.find_element(By.ID, \"hello\")\n       assert element.text == \"Hello World\"\n       assert element.value_of_css_property(\"color\") == \"rgb(0, 0, 255)\"  # blue color\n\n       # Print success message\n       print(\"Test passed: 'Hello World' is displayed correctly with blue color.\")\n   finally:\n       driver.quit()  # Ensure the WebDriver quits even if an assertion fails\n   ```\n\n7. **Run the Docker Compose Services**:\n\n   ```sh\n   docker compose up --build\n   ```\n\n## Explanation of the Test and Output\n\n- The test script uses Selenium to open the local HTML file and check if the content of the element with ID \"hello\" is \"Hello World\" and if its color is blue.\n- If the test passes, a success message \"Test passed: 'Hello World' is displayed correctly with blue color.\" is printed to the console.\n- When you run `docker compose up --build`, Docker will build and start the services defined in the `docker-compose.yml` file.\n- The `test` service will wait for the `selenium` service to be ready, install the necessary dependencies, and then execute the test script.\n- You will see the output of the test in the Docker console, including the success message if the test passes.\n\n\n\n\n# Experiment 12\n\n# Develop test cases for the above containerized application using selenium\n\n## Using Docker Compose for Selenium Firefox to Test HTML, CSS, and JS\n\n1. **Install Docker**: Follow the instructions on the [Docker website](https://docs.docker.com/get-docker/) to install Docker on your machine.\n\n2. **Create Docker Compose File**: Create a `docker-compose.yml` file to set up services for Python and Selenium.\n\n   ```yaml\n   services:\n     selenium:\n       image: selenium/standalone-firefox:latest\n       ports:\n         - \"4444:4444\"\n       volumes:\n         - .:/app\n     test:\n       image: python:3.8-slim\n       volumes:\n         - .:/app\n       working_dir: /app\n       depends_on:\n         - selenium\n       entrypoint:\n         [\n           \"sh\",\n           \"-c\",\n           \"apt-get update \u0026\u0026 apt-get install -y netcat-openbsd \u0026\u0026 while ! nc -z selenium 4444; do sleep 1; done \u0026\u0026 pip install selenium \u0026\u0026 python ./test_script_docker.py\",\n         ]\n   ```\n\n3. **Create HTML, CSS, and JS Files**: Create a simple HTML file `index.html` that shows \"Hello World\" and changes the color via CSS.\n\n   ```html\n   \u003c!DOCTYPE html\u003e\n   \u003chtml lang=\"en\"\u003e\n     \u003chead\u003e\n       \u003cmeta charset=\"UTF-8\" /\u003e\n       \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n       \u003ctitle\u003eHello World\u003c/title\u003e\n       \u003clink rel=\"stylesheet\" href=\"styles.css\" /\u003e\n     \u003c/head\u003e\n     \u003cbody\u003e\n       \u003ch1 id=\"hello\"\u003eHello World\u003c/h1\u003e\n       \u003cbutton id=\"counterButton\"\u003eClick me\u003c/button\u003e\n       \u003cp id=\"counterDisplay\"\u003e0\u003c/p\u003e\n       \u003cscript src=\"script.js\"\u003e\u003c/script\u003e\n     \u003c/body\u003e\n   \u003c/html\u003e\n   ```\n\n4. **Create a CSS File**: Create a CSS file `styles.css` to style the webpage.\n\n   ```css\n   body {\n     font-family: Arial, sans-serif;\n     text-align: center;\n     margin-top: 50px;\n   }\n\n   #hello {\n     color: blue;\n   }\n   ```\n\n5. **Create a JavaScript File**: Create a JavaScript file `script.js` to add color to the webpage and handle the counter functionality.\n\n   ```javascript\n   document.addEventListener(\"DOMContentLoaded\", function () {\n     document.getElementById(\"hello\").style.color = \"blue\";\n\n     let counter = 0;\n     const counterButton = document.getElementById(\"counterButton\");\n     const counterDisplay = document.getElementById(\"counterDisplay\");\n\n     counterButton.addEventListener(\"click\", function () {\n       counter++;\n       counterDisplay.textContent = counter;\n     });\n   });\n   ```\n\n6. **Write a Selenium Test Script**: Create a Python script `test_script_docker.py` to test the HTML file.\n\n   ```python\n   from selenium import webdriver\n   from selenium.webdriver.common.by import By\n   from selenium.webdriver.firefox.options import Options\n   import os\n   import time\n   import unittest\n\n   # Check if index.html file exists\n   file_path = \"/app/index.html\"\n   if not os.path.exists(file_path):\n       raise FileNotFoundError(f\"{file_path} does not exist\")\n   else:\n       print(f\"Found {file_path}\")\n\n   # Set up the Firefox WebDriver\n   options = Options()\n   options.headless = True\n\n   class TestWebPage(unittest.TestCase):\n       @classmethod\n       def setUpClass(cls):\n           cls.driver = webdriver.Remote(\n               command_executor='http://selenium:4444/wd/hub',\n               options=options\n           )\n           cls.driver.get(f\"file://{os.path.abspath(file_path)}\")\n           time.sleep(1)  # Wait for the page to load\n\n       @classmethod\n       def tearDownClass(cls):\n           cls.driver.quit()\n\n       def test_find_html_element(self):\n           try:\n               hello_element = self.driver.find_element(By.ID, \"hello\")\n               self.assertIsNotNone(hello_element)\n               self.assertEqual(hello_element.text, \"Hello World\")\n               self.assertEqual(hello_element.value_of_css_property(\"color\"), \"rgb(0, 0, 255)\")  # blue color\n               print(\"Test passed: 'Hello World' element found with correct text and color.\")\n           except AssertionError as e:\n               print(f\"Test failed: {e}\")\n\n       def test_counter_increment(self):\n           try:\n               counter_button = self.driver.find_element(By.ID, \"counterButton\")\n               counter_display = self.driver.find_element(By.ID, \"counterDisplay\")\n\n               initial_value = int(counter_display.text)\n               counter_button.click()\n               updated_value = int(counter_display.text)\n\n               self.assertEqual(updated_value, initial_value + 1)\n               print(\"Test passed: Counter incremented correctly.\")\n           except AssertionError as e:\n               print(f\"Test failed: {e}\")\n\n   if __name__ == \"__main__\":\n       unittest.main()\n   ```\n\n7. **Run the Docker Compose Services**:\n\n   ```sh\n   docker compose up --build\n   ```\n\n## Explanation of the Test and Output\n\n- The test script uses Selenium to open the local HTML file and check if the content of the element with ID \"hello\" is \"Hello World\" and if its color is blue.\n- It also tests if the counter increments correctly when the button is clicked.\n- If the tests pass, success messages are printed to the console.\n- When you run `docker compose up --build`, Docker will build and start the services defined in the `docker-compose.yml` file.\n- The `test` service will wait for the `selenium` service to be ready, install the necessary dependencies, and then execute the test script.\n- You will see the output of the tests in the Docker console, including the success messages if the tests pass.\n\n## New Features\n\n- Added a button that increments a counter each time it is clicked.\n- The counter value is displayed below the button.\n\n## Test Cases\n\n1. Test case to find the HTML element.\n2. Test case to update the counter and test it.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fdevopslab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakarsh%2Fdevopslab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakarsh%2Fdevopslab/lists"}