Skip to content

Commit

Permalink
Use docker-compose to build Playwright deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Timshel committed Jul 6, 2024
1 parent ec8ef0f commit 6814b52
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 91 deletions.
24 changes: 24 additions & 0 deletions playwright/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
34 changes: 34 additions & 0 deletions playwright/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
74 changes: 4 additions & 70 deletions playwright/global-setup.ts
Original file line number Diff line number Diff line change
@@ -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;
42 changes: 21 additions & 21 deletions playwright/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions playwright/webvault-resolver/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions playwright/webvault-resolver/build.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6814b52

Please sign in to comment.