From aceffd3e988d66c20b6a1f25239120313d32766b Mon Sep 17 00:00:00 2001 From: Rajadurai Date: Tue, 5 Nov 2024 15:33:31 +0530 Subject: [PATCH] Added docker configuration --- .dockerignore | 4 ++++ docker-compose.yaml | 28 ++++++++++++++++++++++++++++ dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 .dockerignore create mode 100644 docker-compose.yaml create mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..37a8d01 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.git +logs +.vscode diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..2f613e2 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,28 @@ + +services: + playwright-cucumber: + build: . + container_name: playwright_cucumber_js + environment: + HEADLESS: "true" # Headless mode for Playwright + NODE_ENV: "production" # Optional: Add more environment variables here + volumes: + - .:/repo # Mounts the local project directory to the container + command: npm run test -- --device "Desktop Chrome" --env "qa" --tags "@reg" --report "local" --rerun --headless + # Replace this with your customized execution command + ports: + - "3000:3000" # Expose ports if necessary (e.g., for web applications) + networks: + - playwright-network + +networks: + playwright-network: + driver: bridge + + +# docker-compose up -d for start a container + +#docker-compose ps to verify the container running + + + diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..5287aaa --- /dev/null +++ b/dockerfile @@ -0,0 +1,44 @@ +#This Line specifies the base image of the docker container. +#This one will get keep on updated in playwright website gtheyr you can see the latest version +FROM mcr.microsoft.com/playwright:v1.48.1-noble + + +# This step specifies the working directory inside the container +WORKDIR /repo + +# This steps ensure copy the package-lock json from local to /repodirectory in the container. +COPY ["package-lock.json","./"] + +#This sets the ENV Headless variable to true. So, The Automated test will get executed in Headless +ENV HEADLESS=true + +# Manually installing the playwright package in order to install the system dependencies which playwright needs +#First command will make sure same dependency which are mentioned in package-lock.json is getting downloaded and +#not creating new package.-lock.json file. + +#--no-save ->>> makes sure that newly installed dependency not getting saved into package.json/package-lock.jspon file. + +#playwright@$() makes sure that same version of dependency getting installed + +#node -pe >>>>>>>>>>>>> runs a Node.js command in a quick,one-liner format. + +#"require('./package-lock.json').dependencies.playwright.version" >>> this is a JS expression that require the package-lock.json file +#and get the dependecies and playwright object and Retreived the version of the Playwright dependency. + +# general command to execute the all mandatory dependency for playwright. +RUN npm install --no-package-lock --no-save playwright@$(node -pe "require('./package-lock.json').dependencies.playwright.version") && \ + npx playwright install-deps + + +# Install remaining node packages +COPY ["package.json", "./"] +RUN npm install && rm -rf /var/lib/apt/lists/* + +COPY . . + + +# Docker command to build image- "docker build -t playwright_cucumber_js ." +#You should be in root directory + +#docker run -it playwright_cucumber_js to start a container +#then you will get into the container shell thetre you can use the regular execution command. \ No newline at end of file