test(e2e): run Playwright against an isolated Compose stand

This commit is contained in:
shira committed 2026-10-06 01:56:05 +03:00
1 parent 7a5105acc7
commit 4cd7d060bd
23 files changed
+431 -41

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
# Overlay for the isolated browser suite. Only deploy/scripts/e2e.sh combines
# it with docker-compose.yml, under a unique project name and a generated
# throwaway env file; never apply it to the working stand.
services:
frontend:
# The browser shares this container's network namespace, so the stand
# publishes no host port and cannot collide with a running stand.
ports: !reset []
playwright:
# The tag must match @playwright/test in frontend/package.json; the runner
# reads the version from there.
image: mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION:?Set PLAYWRIGHT_VERSION}-noble
profiles: ["e2e"]
# localhost:8080 inside this namespace is the frontend Nginx, so the
# browser origin equals the loopback APP_PUBLIC_URL the backend accepts.
network_mode: service:frontend
user: "${E2E_UID:?Set E2E_UID}:${E2E_GID:?Set E2E_GID}"
init: true
working_dir: /workspace/frontend
environment:
HOME: /tmp
CI: ${E2E_CI:-}
E2E_BASE_URL: http://localhost:8080
E2E_ARTIFACTS_DIR: /artifacts
# Only the dependencies installed from frontend/pnpm-lock.yaml and the
# suite are read; results go to the separate writable mount.
volumes:
- ../../frontend:/workspace/frontend:ro
- ${E2E_SPEC_DIR:?Set E2E_SPEC_DIR}:/workspace/frontend/e2e:ro
- ${E2E_ARTIFACTS_DIR:?Set E2E_ARTIFACTS_DIR}:/artifacts
command: ["node", "node_modules/@playwright/test/cli.js", "test"]
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
shm_size: 1gb
deploy:
resources:
limits:
cpus: "2.0"
memory: 2G
+1 -1
View File
@@ -9,7 +9,7 @@ services:
POSTGRES_EXPORTER_PASSWORD: ${POSTGRES_EXPORTER_PASSWORD:-}
volumes:
- postgres_data:/var/lib/postgresql
- ./initdb/10-postgres-exporter.sh:/docker-entrypoint-initdb.d/10-postgres-exporter.sh:ro
- ./initdb/10-postgres-exporter.sql:/docker-entrypoint-initdb.d/10-postgres-exporter.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""]
interval: 10s
@@ -1,21 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ -z "${POSTGRES_EXPORTER_USER:-}" && -z "${POSTGRES_EXPORTER_PASSWORD:-}" ]]; then
exit 0
fi
: "${POSTGRES_EXPORTER_USER:?POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set}"
: "${POSTGRES_EXPORTER_PASSWORD:?POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set}"
psql \
--username "$POSTGRES_USER" \
--dbname "$POSTGRES_DB" \
--set=exporter_user="$POSTGRES_EXPORTER_USER" \
--set=exporter_password="$POSTGRES_EXPORTER_PASSWORD" <<'SQL'
SELECT format('CREATE ROLE %I LOGIN PASSWORD %L', :'exporter_user', :'exporter_password')
WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = :'exporter_user')
\gexec
GRANT pg_monitor TO :"exporter_user";
SQL
@@ -0,0 +1,38 @@
-- Creates the optional PostgreSQL metrics login on first volume
-- initialization. The image entrypoint runs *.sql files with psql
-- (ON_ERROR_STOP=1, as POSTGRES_USER in POSTGRES_DB), independent of file
-- mode, unlike *.sh files, which it executes or sources depending on the
-- executable bit reported by the bind mount. \getenv needs psql 15 or newer.
--
-- Both credentials empty or unset: nothing happens. Exactly one set: the
-- initialization fails. Both set: the role is created if missing and gets
-- pg_monitor.
\getenv exporter_user POSTGRES_EXPORTER_USER
\getenv exporter_password POSTGRES_EXPORTER_PASSWORD
\if :{?exporter_user}
\else
\set exporter_user ''
\endif
\if :{?exporter_password}
\else
\set exporter_password ''
\endif
SELECT :'exporter_user' <> '' AS has_exporter_user,
:'exporter_password' <> '' AS has_exporter_password
\gset
\if :has_exporter_user
\if :has_exporter_password
SELECT format('CREATE ROLE %I LOGIN PASSWORD %L', :'exporter_user', :'exporter_password')
WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = :'exporter_user')
\gexec
GRANT pg_monitor TO :"exporter_user";
\else
DO $$ BEGIN RAISE EXCEPTION 'POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set'; END $$;
\endif
\elif :has_exporter_password
DO $$ BEGIN RAISE EXCEPTION 'POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set'; END $$;
\endif