From b23a06b28141be3f8ba29097cdea69f5a177bbd4 Mon Sep 17 00:00:00 2001 From: ItIsFabian Date: Mon, 10 Feb 2025 15:15:45 +0100 Subject: [PATCH 01/11] mod dockerfile --- Dockerfile | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6c3bf6f..64ad203 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,7 @@ -FROM mcr.microsoft.com/playwright:v1.50.0-noble +FROM node:22-alpine LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image -RUN mkdir /app && \ - mkdir /app/workdir && \ - mkdir /app/volume - -COPY ./files /app/workdir - -RUN cd /app/workdir && \ - yarn install && \ - yarn playwright install && \ - chown -R pwuser /app && \ - chmod +x /app/workdir/entrypoint.sh - -WORKDIR /app/workdir +RUN npx -y playwright@1.50.1 install --with-deps CMD ["bash", "entrypoint.sh"] From 7da047dc976ae3bdde2587710c9c6e32d5efccce Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Mon, 10 Feb 2025 17:55:25 +0100 Subject: [PATCH 02/11] containers are fun they said --- Dockerfile | 10 ++++++++-- README.md | 16 +++++++++++++++- test/local/test.spec.js | 13 +++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100755 test/local/test.spec.js diff --git a/Dockerfile b/Dockerfile index 64ad203..12cc4bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,12 @@ FROM node:22-alpine LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image -RUN npx -y playwright@1.50.1 install --with-deps +RUN npm install @playwright/test && npx -y playwright@1.50.1 install --with-deps -CMD ["bash", "entrypoint.sh"] +RUN groupadd pwuser && adduser pwuser -G pwuser + +RUN mkdir -p /app/workdir && chown pwuser:pwuser /app/workdir + +WORKDIR /app/workdir + +ENTRYPOINT ["npx", "playwright", "test", "test.spec.js"] diff --git a/README.md b/README.md index 6a4b2c2..8605046 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -# lct-playwright-image +# LCT Playwright Image + +## What we need + +- Node installed +- Playwright installed +- A directory which is mounted to the host + +## Building the Image + +`docker build . --file Dockerfile -t lct-playwright-image` + +## Testing the container + +`docker run --rm --ipc=host -v $(pwd)/test/local:/app/workdir lct-playwright-image "--project=chromium"` diff --git a/test/local/test.spec.js b/test/local/test.spec.js new file mode 100755 index 0000000..43bbee1 --- /dev/null +++ b/test/local/test.spec.js @@ -0,0 +1,13 @@ +import { expect, test } from "@playwright/test"; + +test.describe("Go to example.com", () => { + test("should open example.com", async ({ page }) => { + await page.goto("https://example.com"); + await page.screenshot({ path: "example.png" }); + }); + + test("should have header", async ({ page }) => { + await page.goto("https://example.com"); + await expect(page.locator("h1")).toHaveText("Example Domain"); + }); +}); From 3da625c94ec58e26cd64ea7956170afffcdb285f Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Mon, 10 Feb 2025 19:36:59 +0100 Subject: [PATCH 03/11] intermediate state to revert to --- Dockerfile | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 12cc4bc..5808ed7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,31 @@ -FROM node:22-alpine +FROM ubuntu:noble -LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image +ARG DEBIAN_FRONTEND=noninteractive +ARG TZ=Europe/Berlin + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 -RUN npm install @playwright/test && npx -y playwright@1.50.1 install --with-deps +LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image -RUN groupadd pwuser && adduser pwuser -G pwuser +RUN apt-get update && \ + # Install Node.js + apt-get install -y curl wget gpg ca-certificates && \ + mkdir -p /etc/apt/keyrings && \ + curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ + apt-get update && \ + apt-get install -y nodejs && \ + rm -rf /var/lib/apt/lists/* && \ + groupadd pwuser && \ + useradd -g pwuser pwuser && \ + mkdir -p /app/workdir -RUN mkdir -p /app/workdir && chown pwuser:pwuser /app/workdir +RUN cd /app/workdir && \ + npm install -y @playwright/test && \ + npx -y playwright@1.50.1 install --with-deps && \ + chown pwuser:pwuser /app/workdir && \ + chmod -R 777 /app/workdir WORKDIR /app/workdir From 953d9d6fbbc085cfcad7a9e99b176d6f03cca70d Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Tue, 11 Feb 2025 12:32:30 +0100 Subject: [PATCH 04/11] seems to work --- .gitignore | 4 +- Dockerfile | 11 +-- README.md | 11 ++- files/package.json | 2 +- test/local/lctReporter.js | 79 ++++++++++++++++++++ test/local/playwright.config.js | 108 ++++++++++++++++++++++++++++ test/local/{ => tests}/test.spec.js | 0 7 files changed, 206 insertions(+), 9 deletions(-) create mode 100755 test/local/lctReporter.js create mode 100755 test/local/playwright.config.js rename test/local/{ => tests}/test.spec.js (100%) diff --git a/.gitignore b/.gitignore index ee60177..185fd76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/test/*/lctReporter.js -/test/*/playwright.config.js /test/*/output +/test/*/results.xml +/test/*/*.png diff --git a/Dockerfile b/Dockerfile index 5808ed7..849837c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ ARG TZ=Europe/Berlin ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 +ENV NODE_PATH=/app/workdir/node_modules + LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image RUN apt-get update && \ @@ -19,13 +21,14 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* && \ groupadd pwuser && \ useradd -g pwuser pwuser && \ - mkdir -p /app/workdir + mkdir -p /app/workdir && \ + mkdir -p /app/volume -RUN cd /app/workdir && \ +RUN cd /app && \ npm install -y @playwright/test && \ npx -y playwright@1.50.1 install --with-deps && \ - chown pwuser:pwuser /app/workdir && \ - chmod -R 777 /app/workdir + chown pwuser:pwuser /app && \ + chmod -R 777 /app WORKDIR /app/workdir diff --git a/README.md b/README.md index 8605046..5f3424e 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,15 @@ ## What we need - Node installed -- Playwright installed -- A directory which is mounted to the host +- A prepared directory `/app` in the container with playwright installation +- A directory `/app/workdir` (must be subdir of above) which is mounted to the host to serve + - configs, like `playwright.config.js` + - the actual test specifications in subfolder `tests` + - as output directory for all artifacts + +## Sample folder structure for mounted folder + + ## Building the Image diff --git a/files/package.json b/files/package.json index 1b6eb67..d1a0df5 100644 --- a/files/package.json +++ b/files/package.json @@ -1,7 +1,7 @@ { "license": "MIT", "dependencies": { - "@playwright/test": "1.50.0" + "@playwright/test": "1.50.1" }, "scripts": {} } diff --git a/test/local/lctReporter.js b/test/local/lctReporter.js new file mode 100755 index 0000000..f60e82f --- /dev/null +++ b/test/local/lctReporter.js @@ -0,0 +1,79 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable no-unused-vars */ +/* eslint-disable no-console */ +/* eslint-disable class-methods-use-this */ + +function getStatusEmoji(status) { + switch (status) { + case 'passed': + return '✅'; + case 'failed': + return '❌'; + case 'timedOut': + return '⏱️'; + case 'skipped': + return '⏭️'; + default: + return '❓'; + } +} + +/** + * @typedef {import('@playwright/test/reporter').Reporter} PwReporter + */ + +/** @implements {PwReporter} */ +class MyReporter { + onBegin(config, suite) { + console.log( + `\n=====================================\n Starting LCT Worksheet with ${ + suite.allTests().length + } cases\n=====================================\n` + ); + } + + onTestBegin(test) { + console.log(`> Case "${test.title}"`); + } + + onTestEnd(test, result) { + console.log( + `> Finished Case "${test.title}" (${ + result.duration + } ms | Status ${getStatusEmoji(result.status)} ("${result.status}"))\n\n` + ); + + if (result?.error?.message) { + console.log(`Case error log:\n${result.error.message}\n\n\n`); + } + } + + onEnd(result) { + console.log( + `Finished Worksheet execution | Status ${getStatusEmoji( + result.status + )} ("${result.status}")` + ); + } + + onStepEnd(test, result, step) { + let title = step.title; + + if (title.includes('Screenshot on failure')) { + title = title.replace( + 'Screenshot on failure', + '🚨 Screenshot on failure 🚨' + ); + } + + console.log( + ` ${!step.error ? '✅' : '❌'} ${title} (${step.duration} ms)` + ); + + if (step.error) { + console.log(` ${step.error.message}`); + } + } +} + +module.exports = MyReporter; diff --git a/test/local/playwright.config.js b/test/local/playwright.config.js new file mode 100755 index 0000000..27e7451 --- /dev/null +++ b/test/local/playwright.config.js @@ -0,0 +1,108 @@ +import { devices } from "@playwright/test"; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +const config = { + /* Maximum time one test can run for. */ + // globalTimeout: 120 * 1000, + timeout: 30 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 5000, + }, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + // forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: 2, + /* Opt out of parallel tests on CI. */ + workers: 1, + testDir: "./tests", + outputDir: "./output", + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: [["./lctReporter.js"], ["junit", { outputFile: "results.xml" }]], + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ + actionTimeout: 0, + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + screenshot: "only-on-failure", + ignoreHTTPSErrors: false, + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "chromium", + use: { + ...devices["Desktop Chrome"], + }, + }, + + { + name: "firefox", + use: { + ...devices["Desktop Firefox"], + }, + }, + + { + name: "webkit", + use: { + ...devices["Desktop Safari"], + }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { + // ...devices['Pixel 5'], + // }, + // }, + // { + // name: 'Mobile Safari', + // use: { + // ...devices['iPhone 12'], + // }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { + // channel: 'msedge', + // }, + // }, + // { + // name: 'Google Chrome', + // use: { + // channel: 'chrome', + // }, + // }, + ], + + /* Folder for test artifacts such as screenshots, videos, traces, etc. */ + // outputDir: 'test-results/', + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // port: 3000, + // }, +}; + +export default config; diff --git a/test/local/test.spec.js b/test/local/tests/test.spec.js similarity index 100% rename from test/local/test.spec.js rename to test/local/tests/test.spec.js From 01257d3a6f0dc00663a522f697f0a851949f98f2 Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Tue, 11 Feb 2025 16:30:14 +0100 Subject: [PATCH 05/11] rework container testing --- .github/workflows/publish-image.yml | 3 -- run_tests.sh | 48 ++++++++++++++------------ test/chromium/run.sh | 7 ---- test/firefox/run.sh | 7 ---- test/firefox/test.spec.js | 13 ------- test/{ => static}/lctReporter.js | 0 test/{ => static}/playwright.config.js | 2 ++ test/{chromium => static}/test.spec.js | 0 test/versions-match.sh | 20 ----------- test/webkit/run.sh | 7 ---- test/webkit/test.spec.js | 13 ------- 11 files changed, 28 insertions(+), 92 deletions(-) delete mode 100755 test/chromium/run.sh delete mode 100755 test/firefox/run.sh delete mode 100755 test/firefox/test.spec.js rename test/{ => static}/lctReporter.js (100%) rename test/{ => static}/playwright.config.js (98%) rename test/{chromium => static}/test.spec.js (100%) delete mode 100755 test/versions-match.sh delete mode 100755 test/webkit/run.sh delete mode 100755 test/webkit/test.spec.js diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 4632b65..736906d 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -25,9 +25,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Check playwright versions match - run: ./test/versions-match.sh - - name: Test Docker Image run: | docker build . --file Dockerfile -t $IMAGE_NAME --cache-from ghcr.io/mt-ag/$IMAGE_NAME diff --git a/run_tests.sh b/run_tests.sh index 0b68189..25c8714 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,14 +1,13 @@ IMAGE_NAME="lct-playwright-image:latest" -function copy_test_files() { - FOLDER=$1 +function prepare_test() { - rm -rf /test/$FOLDER/output/ || true - rm ./test/$FOLDER/lctReporter.js || true - rm ./test/$FOLDER/playwright.config.js || true + rm -rf /test/live || true + mkdir -p /test/live - cp ./test/lctReporter.js ./test/$FOLDER - cp ./test/playwright.config.js ./test/$FOLDER + cp ./test/static/lctReporter.js ./test/live + cp ./test/static/playwright.config.js ./test/live + cp ./test/static/test.spec.js ./test/live/tests } function single_file_exists() { @@ -22,29 +21,34 @@ function single_file_exists() { fi } -function test_result_files_exist() { - FOLDER=$1 +function check_result_and_cleanup() { + single_file_exists "./test/live/results.xml" + rm ./test/live/results.xml || true + single_file_exists "./test/live/example.png" + rm ./test/live/example.png || true + rm -rf ./test/live/output || true +} - single_file_exists "./test/$FOLDER/output/results.xml" - single_file_exists "./test/$FOLDER/output/output.log" +function run_container() { + BROWSER=$1 + docker run --rm --ipc=host -v $(pwd)/test/live:/app/workdir $IMAGE_NAME "--project=$BROWSER" } echo "Launching Test Suite..." -echo "Giving access to all files..." -chmod -R 777 ./test/* +prepare_test echo "Starting chromium test..." -copy_test_files "chromium" -docker run --rm --ipc=host -v $(pwd)/test/chromium:/app/volume $IMAGE_NAME -test_result_files_exist "chromium" +run_container "chromium" +echo "Verifying chromium test results..." +check_result_and_cleanup echo "Starting firefox test..." -copy_test_files "firefox" -docker run --rm --ipc=host -v $(pwd)/test/firefox:/app/volume $IMAGE_NAME -test_result_files_exist "firefox" +run_container "firefox" +echo "Verifying firefox test results..." +check_result_and_cleanup echo "Starting webkit test..." -copy_test_files "webkit" -docker run --rm --ipc=host -v $(pwd)/test/webkit:/app/volume $IMAGE_NAME -test_result_files_exist "webkit" +run_container "webkit" +echo "Verifying webkit test results..." +check_result_and_cleanup diff --git a/test/chromium/run.sh b/test/chromium/run.sh deleted file mode 100755 index 8c63269..0000000 --- a/test/chromium/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -echo "" -echo "Test script:" -cat test.spec.js -echo "" -echo "" -yarn playwright test test.spec.js --project=chromium diff --git a/test/firefox/run.sh b/test/firefox/run.sh deleted file mode 100755 index 9085b22..0000000 --- a/test/firefox/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -echo "" -echo "Test script:" -cat test.spec.js -echo "" -echo "" -yarn playwright test test.spec.js --project=firefox diff --git a/test/firefox/test.spec.js b/test/firefox/test.spec.js deleted file mode 100755 index 43bbee1..0000000 --- a/test/firefox/test.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -import { expect, test } from "@playwright/test"; - -test.describe("Go to example.com", () => { - test("should open example.com", async ({ page }) => { - await page.goto("https://example.com"); - await page.screenshot({ path: "example.png" }); - }); - - test("should have header", async ({ page }) => { - await page.goto("https://example.com"); - await expect(page.locator("h1")).toHaveText("Example Domain"); - }); -}); diff --git a/test/lctReporter.js b/test/static/lctReporter.js similarity index 100% rename from test/lctReporter.js rename to test/static/lctReporter.js diff --git a/test/playwright.config.js b/test/static/playwright.config.js similarity index 98% rename from test/playwright.config.js rename to test/static/playwright.config.js index 75a4daf..27e7451 100755 --- a/test/playwright.config.js +++ b/test/static/playwright.config.js @@ -26,6 +26,8 @@ const config = { retries: 2, /* Opt out of parallel tests on CI. */ workers: 1, + testDir: "./tests", + outputDir: "./output", /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: [["./lctReporter.js"], ["junit", { outputFile: "results.xml" }]], /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ diff --git a/test/chromium/test.spec.js b/test/static/test.spec.js similarity index 100% rename from test/chromium/test.spec.js rename to test/static/test.spec.js diff --git a/test/versions-match.sh b/test/versions-match.sh deleted file mode 100755 index 4808761..0000000 --- a/test/versions-match.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Path to your Dockerfile and package.json -DOCKERFILE_PATH="./Dockerfile" -PACKAGE_JSON_PATH="./files/package.json" - -# Extract version from Dockerfile -DOCKERFILE_VERSION=$(grep '^FROM' $DOCKERFILE_PATH | awk -F':' '{print $2}' | sed 's/-noble//' | sed 's/v//') - -# Extract version from package.json -PACKAGE_JSON_VERSION=$(awk -F'"' '/@playwright\/test/ {print $4}' $PACKAGE_JSON_PATH) - -# Compare versions -if [ "$DOCKERFILE_VERSION" = "$PACKAGE_JSON_VERSION" ]; then - echo "Versions match: $DOCKERFILE_VERSION" -else - echo "Versions do not match. Dockerfile version: $DOCKERFILE_VERSION, package.json version: $PACKAGE_JSON_VERSION" - # Exit with error - exit 1 -fi diff --git a/test/webkit/run.sh b/test/webkit/run.sh deleted file mode 100755 index 41498a6..0000000 --- a/test/webkit/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -echo "" -echo "Test script:" -cat test.spec.js -echo "" -echo "" -yarn playwright test test.spec.js --project=webkit diff --git a/test/webkit/test.spec.js b/test/webkit/test.spec.js deleted file mode 100755 index 43bbee1..0000000 --- a/test/webkit/test.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -import { expect, test } from "@playwright/test"; - -test.describe("Go to example.com", () => { - test("should open example.com", async ({ page }) => { - await page.goto("https://example.com"); - await page.screenshot({ path: "example.png" }); - }); - - test("should have header", async ({ page }) => { - await page.goto("https://example.com"); - await expect(page.locator("h1")).toHaveText("Example Domain"); - }); -}); From 599b848206001510bfe717a5fe3cbe4ed6372344 Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Tue, 11 Feb 2025 19:39:19 +0100 Subject: [PATCH 06/11] fix wrong directory --- run_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 25c8714..1c60208 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,8 +2,8 @@ IMAGE_NAME="lct-playwright-image:latest" function prepare_test() { - rm -rf /test/live || true - mkdir -p /test/live + rm -rf ./test/live || true + mkdir -p ./test/live cp ./test/static/lctReporter.js ./test/live cp ./test/static/playwright.config.js ./test/live From f2f94c6567a9c8d4a38530b77bf01ad73484ba22 Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Tue, 11 Feb 2025 19:45:57 +0100 Subject: [PATCH 07/11] create all needed directories --- run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index 1c60208..96b2a9d 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -3,7 +3,7 @@ IMAGE_NAME="lct-playwright-image:latest" function prepare_test() { rm -rf ./test/live || true - mkdir -p ./test/live + mkdir -p ./test/live/tests cp ./test/static/lctReporter.js ./test/live cp ./test/static/playwright.config.js ./test/live From 1342a4702a3b396ab4de7f63c020f8abd8731fea Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Wed, 12 Feb 2025 12:18:01 +0100 Subject: [PATCH 08/11] fixed permission when mounting --- Dockerfile | 17 +++++++++++------ README.md | 5 ++--- run_tests.sh | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 849837c..38125b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,29 +6,34 @@ ARG TZ=Europe/Berlin ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 -ENV NODE_PATH=/app/workdir/node_modules +ENV PLAYWRIGHT_BROWSERS_PATH=/pw-browsers LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image +# General System Setup RUN apt-get update && \ - # Install Node.js apt-get install -y curl wget gpg ca-certificates && \ mkdir -p /etc/apt/keyrings && \ curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ apt-get update && \ apt-get install -y nodejs && \ - rm -rf /var/lib/apt/lists/* && \ - groupadd pwuser && \ + npm config set --global update-notifier false && \ + rm -rf /var/lib/apt/lists/* + +# Directory and User Preparation +RUN groupadd pwuser && \ useradd -g pwuser pwuser && \ mkdir -p /app/workdir && \ - mkdir -p /app/volume + mkdir /pw-browsers +# Playwright Installation RUN cd /app && \ npm install -y @playwright/test && \ npx -y playwright@1.50.1 install --with-deps && \ chown pwuser:pwuser /app && \ - chmod -R 777 /app + chmod -R 777 /app && \ + chmod -R 777 /pw-browsers WORKDIR /app/workdir diff --git a/README.md b/README.md index 5f3424e..aec1efc 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,10 @@ ## Sample folder structure for mounted folder - ## Building the Image -`docker build . --file Dockerfile -t lct-playwright-image` +`docker build . --file Dockerfile -t lct-playwright-image:local` ## Testing the container -`docker run --rm --ipc=host -v $(pwd)/test/local:/app/workdir lct-playwright-image "--project=chromium"` +`docker run -u "$(id -u):$(id -g)" --rm --ipc=host -v $(pwd)/test/local:/app/workdir lct-playwright-image:local "--project=chromium"` diff --git a/run_tests.sh b/run_tests.sh index 96b2a9d..a44b0fc 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -31,7 +31,7 @@ function check_result_and_cleanup() { function run_container() { BROWSER=$1 - docker run --rm --ipc=host -v $(pwd)/test/live:/app/workdir $IMAGE_NAME "--project=$BROWSER" + docker run -u "$(id -u):$(id -g)" --rm --ipc=host -v $(pwd)/test/live:/app/workdir $IMAGE_NAME "--project=$BROWSER" } echo "Launching Test Suite..." From 34a582846ac5e1dc9defd7fdb64aa8996d08151e Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Wed, 12 Feb 2025 13:35:50 +0100 Subject: [PATCH 09/11] intermediate state --- Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 38125b4..c591ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,9 +21,12 @@ RUN apt-get update && \ npm config set --global update-notifier false && \ rm -rf /var/lib/apt/lists/* +ARG PW_USER=lct +ARG PW_GROUP=lct + # Directory and User Preparation -RUN groupadd pwuser && \ - useradd -g pwuser pwuser && \ +RUN groupadd $PW_GROUP && \ + useradd -g $PW_GROUP $PW_USER && \ mkdir -p /app/workdir && \ mkdir /pw-browsers @@ -31,7 +34,7 @@ RUN groupadd pwuser && \ RUN cd /app && \ npm install -y @playwright/test && \ npx -y playwright@1.50.1 install --with-deps && \ - chown pwuser:pwuser /app && \ + chown $PW_USER:$PW_GROUP /app && \ chmod -R 777 /app && \ chmod -R 777 /pw-browsers From 68586bb8eca8fc74508fa4ed6988ea243e58997e Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Wed, 12 Feb 2025 13:51:48 +0100 Subject: [PATCH 10/11] revert to ms image base and fix test script --- Dockerfile | 39 ++++++--------------------------------- run_tests.sh | 2 +- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/Dockerfile b/Dockerfile index c591ee2..e8196ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,15 @@ -FROM ubuntu:noble - -ARG DEBIAN_FRONTEND=noninteractive -ARG TZ=Europe/Berlin - -ENV LANG=C.UTF-8 -ENV LC_ALL=C.UTF-8 - -ENV PLAYWRIGHT_BROWSERS_PATH=/pw-browsers +FROM mcr.microsoft.com/playwright:v1.50.1-noble LABEL org.opencontainers.image.source https://github.com/mt-ag/lct-playwright-image -# General System Setup -RUN apt-get update && \ - apt-get install -y curl wget gpg ca-certificates && \ - mkdir -p /etc/apt/keyrings && \ - curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list && \ - apt-get update && \ - apt-get install -y nodejs && \ - npm config set --global update-notifier false && \ - rm -rf /var/lib/apt/lists/* - -ARG PW_USER=lct -ARG PW_GROUP=lct - -# Directory and User Preparation -RUN groupadd $PW_GROUP && \ - useradd -g $PW_GROUP $PW_USER && \ - mkdir -p /app/workdir && \ - mkdir /pw-browsers - # Playwright Installation -RUN cd /app && \ +RUN mkdir -p /app/workdir && \ + cd /app && \ + npm config set --global update-notifier false && \ npm install -y @playwright/test && \ npx -y playwright@1.50.1 install --with-deps && \ - chown $PW_USER:$PW_GROUP /app && \ - chmod -R 777 /app && \ - chmod -R 777 /pw-browsers + chown pwuser:pwuser /app && \ + chmod -R 777 /app WORKDIR /app/workdir diff --git a/run_tests.sh b/run_tests.sh index a44b0fc..4e02b99 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -31,7 +31,7 @@ function check_result_and_cleanup() { function run_container() { BROWSER=$1 - docker run -u "$(id -u):$(id -g)" --rm --ipc=host -v $(pwd)/test/live:/app/workdir $IMAGE_NAME "--project=$BROWSER" + docker run -u pwuser --rm --ipc=host -v $(pwd)/test/live:/app/workdir $IMAGE_NAME "--project=$BROWSER" } echo "Launching Test Suite..." From 7a8c4d97539ce8977229574078cdb6c97741a145 Mon Sep 17 00:00:00 2001 From: Moritz Klein Date: Wed, 12 Feb 2025 13:59:56 +0100 Subject: [PATCH 11/11] update readme --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aec1efc..7fc06c9 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,16 @@ ## Sample folder structure for mounted folder - -## Building the Image +## Building the Image locally `docker build . --file Dockerfile -t lct-playwright-image:local` -## Testing the container +## Testing the container locally -`docker run -u "$(id -u):$(id -g)" --rm --ipc=host -v $(pwd)/test/local:/app/workdir lct-playwright-image:local "--project=chromium"` +```sh +# Run on Top Level directory of repo +rm -rf ./test/local/results.xml ./test/local/example.png ./test/local/output +docker run -u pwuser --rm --ipc=host -v ./test/local:/app/workdir lct-playwright-image:local "--project=chromium" +# Verify if files exist +ls -la ./test/local +```