diff --git a/playwright/Dockerfile b/playwright/Dockerfile new file mode 100644 index 0000000000..7341aae7f3 --- /dev/null +++ b/playwright/Dockerfile @@ -0,0 +1,24 @@ +FROM docker.io/library/debian:bookworm-slim + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get update \ + && apt-get install -y --no-install-recommends docker.io git nodejs npm \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + libmariadb-dev-compat \ + libpq5 \ + openssl + +RUN mkdir /playwright +WORKDIR /playwright + +COPY package.json . +RUN npm install && npx playwright install-deps && npx playwright install firefox + +COPY *.ts test.env ./ +COPY tests ./tests + +ENTRYPOINT ["/usr/bin/npx", "playwright"] +CMD ["test", "--project=sqllite"] diff --git a/playwright/docker-compose.yml b/playwright/docker-compose.yml new file mode 100644 index 0000000000..89000d2b12 --- /dev/null +++ b/playwright/docker-compose.yml @@ -0,0 +1,34 @@ +services: + VaultWarden: + container_name: playwright_vaultwarden + image: playwright_vaultwarden + build: + context: .. + dockerfile: Dockerfile + entrypoint: /bin/bash + restart: "no" + WebVault: + container_name: playwright_web-vault_resolver + image: playwright_web-vault_resolver + build: + context: webvault-resolver + dockerfile: Dockerfile + args: + REPO_URL: ${PW_WV_REPO_URL} # Ex: https://github.com/stefan0xC/bw_web_builds + COMMIT_HASH: ${PW_WV_COMMIT_HASH} # Ex: c5b5279a8478385cee66a8cdfc804690cffe0315 + restart: "no" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - VaultWarden + Playwright: + container_name: playwright_playwright + image: playwright_playwright + build: + context: . + dockerfile: Dockerfile + restart: "no" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + depends_on: + - WebVault diff --git a/playwright/global-setup.ts b/playwright/global-setup.ts index 7f99a2fd98..f662f635a8 100644 --- a/playwright/global-setup.ts +++ b/playwright/global-setup.ts @@ -1,79 +1,13 @@ import { firefox, type FullConfig } from '@playwright/test'; import { exec, execSync } from 'node:child_process'; import fs from 'fs'; -import yaml from 'js-yaml'; - -const utils = require('./global-utils'); - -utils.loadEnv(); - -function readCurrentVersion(){ - try { - const vw_version_file = fs.readFileSync('temp/web-vault/vw-version.json', { - encoding: 'utf8', - flag: 'r' - }); - - return JSON.parse(vw_version_file)["version"]; - } catch(err) { - console.log(`Failed to read frontend current version: ${err}`); - } -} - -function readDockerVersion(){ - try { - const docker_settings = fs.readFileSync('../docker/DockerSettings.yaml', { - encoding: 'utf8', - flag: 'r' - }); - - const settings = yaml.load(docker_settings); - return settings["vault_version"]; - } catch(err) { - console.log(`Failed to read docker frontend current version: ${err}`); - } -} - -function retrieveFrontend(){ - const vw_version = readCurrentVersion(); - const vv = readDockerVersion() - - if( !vv ){ - console.log("Empty docker frontend version"); - process.exit(1); - } - - try { - if( vv != `v${vw_version}`) { - fs.rmSync("./temp/web-vault", { recursive: true, force: true }); - - execSync(`cd temp && wget -c https://github.com/dani-garcia/bw_web_builds/releases/download/${vv}/bw_web_${vv}.tar.gz -O - | tar xz`, { stdio: "inherit" }); - - console.log(`Retrieved bw_web_builds-${vv}`); - } else { - console.log(`Using existing bw_web_builds-${vv}`); - } - } catch(err) { - console.log(`Failed to retrieve frontend: ${err}`); - process.exit(1); - } -} - -function buildServer(){ - if( !fs.existsSync('temp/vaultwarden') ){ - console.log("Rebuilding server"); - execSync(`cd .. && cargo build --features sqlite,mysql,postgresql --release`, { stdio: "inherit" }); - execSync(`cp ../target/release/vaultwarden temp/vaultwarden`, { stdio: "inherit" }); - } else { - console.log("Using existing server"); - } -} async function globalSetup(config: FullConfig) { - execSync("mkdir -p temp/logs"); + fs.rmSync("temp/web-vault", { recursive: true, force: true }); - buildServer(); - retrieveFrontend(); + execSync("mkdir -p temp/logs"); + execSync("docker cp playwright_vaultwarden:/vaultwarden temp/vaultwarden", { stdio: "inherit" }); + execSync("docker cp playwright_web-vault:/web-vault temp/web-vault", { stdio: "inherit" }); } export default globalSetup; diff --git a/playwright/package-lock.json b/playwright/package-lock.json index 0b5fd2e986..93cbff97a8 100644 --- a/playwright/package-lock.json +++ b/playwright/package-lock.json @@ -18,24 +18,24 @@ } }, "node_modules/@playwright/test": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.41.2.tgz", - "integrity": "sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.45.1.tgz", + "integrity": "sha512-Wo1bWTzQvGA7LyKGIZc8nFSTFf2TkthGIFBR+QVNilvwouGzFd4PYukZe3rvf5PSqjHi1+1NyKSDZKcQWETzaA==", "dev": true, "dependencies": { - "playwright": "1.41.2" + "playwright": "1.45.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/@types/node": { - "version": "20.11.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz", - "integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==", + "version": "20.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.10.tgz", + "integrity": "sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -60,15 +60,15 @@ "dev": true }, "node_modules/dotenv": { - "version": "16.4.1", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.1.tgz", - "integrity": "sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==", + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", "dev": true, "engines": { "node": ">=12" }, "funding": { - "url": "https://github.com/motdotla/dotenv?sponsor=1" + "url": "https://dotenvx.com" } }, "node_modules/dotenv-expand": { @@ -116,33 +116,33 @@ } }, "node_modules/playwright": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", - "integrity": "sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.45.1.tgz", + "integrity": "sha512-Hjrgae4kpSQBr98nhCj3IScxVeVUixqj+5oyif8TdIn2opTCPEzqAqNMeK42i3cWDCVu9MI+ZsGWw+gVR4ISBg==", "dev": true, "dependencies": { - "playwright-core": "1.41.2" + "playwright-core": "1.45.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" }, "optionalDependencies": { "fsevents": "2.3.2" } }, "node_modules/playwright-core": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.41.2.tgz", - "integrity": "sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA==", + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.45.1.tgz", + "integrity": "sha512-LF4CUUtrUu2TCpDw4mcrAIuYrEjVDfT1cHbJMfwnE2+1b8PZcFzPNgvZCvq2JfQ4aTjRCCHw5EJ2tmr2NSzdPg==", "dev": true, "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/undici-types": { diff --git a/playwright/webvault-resolver/Dockerfile b/playwright/webvault-resolver/Dockerfile new file mode 100644 index 0000000000..a1cca22f70 --- /dev/null +++ b/playwright/webvault-resolver/Dockerfile @@ -0,0 +1,12 @@ +FROM docker + +arg REPO_URL +arg COMMIT_HASH + +ENV COMMIT_HASH=${COMMIT_HASH} + +RUN if [[ -n "${REPO_URL}" ]]; then git clone ${REPO_URL} /bw_web_builds && cd /bw_web_builds && git reset --hard "${COMMIT_HASH}" ; fi + +COPY build.sh /build.sh + +ENTRYPOINT ["/build.sh"] diff --git a/playwright/webvault-resolver/build.sh b/playwright/webvault-resolver/build.sh new file mode 100755 index 0000000000..e3826e3b09 --- /dev/null +++ b/playwright/webvault-resolver/build.sh @@ -0,0 +1,21 @@ +#!/bin/ash + +CANARY=/playwright_web-vault_resolver-done + +if [ -f $CANARY ] +then + echo "Web vault selection should already be done. Will not run." + exit 0 +fi + +docker rm -f playwright_web-vault || true + +if [[ -n "$COMMIT_HASH" ]]; then + cd /bw_web_builds + docker build . -t "playwright_web-vault_$COMMIT_HASH" + docker create --name playwright_web-vault "playwright_web-vault_$COMMIT_HASH:latest" +else + docker create --name playwright_web-vault playwright_vaultwarden:latest +fi + +touch $CANARY