From 574c5cdbcef04e69760ccb1a8eaf19550a560e83 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 5 Nov 2026 13:57:52 +0000 Subject: [PATCH] Add browsers for tests: Playwright, Firefox, geckodriver, headless Chrome (closes #10) Firefox comes from Mozilla's own apt repo, pinned above Ubuntu's snap-only package. geckodriver is at its latest release, independent of the Firefox version. Playwright installs its Chromium and Firefox; WebKit is skipped because no repository uses it today. Playwright's Chromium is exposed as the headless Chrome. Model: deepseek-v4-pro --- Dockerfile | 1 + README.md | 23 +++++++++++++++++++---- bin/test | 4 ++++ build.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 345ddfd..1c338cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ ENV LANG=C.UTF-8 \ COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \ COREPACK_ENABLE_AUTO_PIN=0 \ PYENV_ROOT=/usr/local/pyenv \ + PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \ GOPATH=/root/go \ PATH=/usr/local/go/bin:/root/go/bin:/usr/local/nvm/current/bin:/usr/local/pyenv/shims:/usr/local/pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin diff --git a/README.md b/README.md index 3d6cfd7..a31ce2a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ Image: `git.eeqj.de/sneak/baseimage`, built for `linux/amd64` and | yarn, pnpm | corepack, cache pre-populated | `/usr/local/corepack` | | wrangler | `npm install -g wrangler` | nvm LTS global bin | | prettier | `npm install -g prettier` | nvm LTS global bin | +| Playwright | `npm install -g playwright` | nvm LTS global bin | +| Playwright browsers | `playwright install` (chromium, firefox) | `/ms-playwright` | +| Firefox | Mozilla apt repo | `/usr/bin/firefox` | +| geckodriver | GitHub release | `/usr/local/bin/geckodriver` | +| headless Chrome | Playwright Chromium | `chromium` on `PATH` | | Python (distro) | apt `python3`, `pip`, `venv` | `/usr/bin/python3` | | pyenv | git tag | `/usr/local/pyenv` | | Python (latest) | `pyenv install` | `/usr/local/pyenv/versions/*` | @@ -68,7 +73,8 @@ dependencies in child images. Environment variables set in the image: `NVM_DIR`, `NVM_SYMLINK_CURRENT`, `COREPACK_HOME`, `COREPACK_ENABLE_DOWNLOAD_PROMPT=0`, -`COREPACK_ENABLE_AUTO_PIN=0`, `PYENV_ROOT`, `GOPATH`, `LANG=C.UTF-8`. +`COREPACK_ENABLE_AUTO_PIN=0`, `PYENV_ROOT`, `GOPATH`, `LANG=C.UTF-8`, +`PLAYWRIGHT_BROWSERS_PATH`. ### Yarn and corepack @@ -91,9 +97,18 @@ the `Dockerfile`: | `NVM_GIT_TAG` | `nvm-sh/nvm` release tag | | `PYENV_GIT_TAG` | `pyenv/pyenv` release tag | -Everything else resolves to its current release at build time: Ubuntu -packages, Go, Node LTS, Python, Hugo, golangci-lint, npm, yarn, pnpm, -wrangler. +Everything else resolves to its current release at build time: + +- Ubuntu packages +- Go, Node LTS, and Python +- Hugo and golangci-lint +- npm, yarn, pnpm, wrangler, and prettier +- Playwright and its browsers +- Firefox and geckodriver + +Playwright installs its browsers for the image's Playwright version only. A +child image that pins a different Playwright version downloads its own +browsers. ## Services and init diff --git a/bin/test b/bin/test index 34102a5..813d905 100755 --- a/bin/test +++ b/bin/test @@ -39,6 +39,10 @@ docker run --rm "$img" bash -ec ' valkey-cli shutdown nosave psql --version postgres --version + playwright --version + firefox --version + geckodriver --version + chromium --version ' echo "== $img: runit service lifecycle" diff --git a/build.sh b/build.sh index 0a7cefe..3278f8c 100755 --- a/build.sh +++ b/build.sh @@ -77,7 +77,7 @@ nvm install --lts nvm alias default "lts/*" nvm use default set -ux -npm install -g npm@latest corepack wrangler prettier +npm install -g npm@latest corepack wrangler prettier playwright corepack enable # Pre-populate the corepack cache so projects that pin a package manager # do not download at run time. The last yarn installed becomes the default. @@ -90,6 +90,42 @@ pnpm --version yarn --version nvm cache clear +# --- browsers for tests: Firefox, geckodriver, Playwright -------------------- +# Ubuntu's firefox is a snap that does not run in a container, so use +# Mozilla's own apt repository for the real binary. +install -d -m 0755 /etc/apt/keyrings +curl -fsSL https://packages.mozilla.org/apt/repo-signing-key.gpg \ + -o /etc/apt/keyrings/packages.mozilla.org.asc +echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" \ + > /etc/apt/sources.list.d/mozilla.list +cat > /etc/apt/preferences.d/mozilla <<'EOF' +Package: * +Pin: origin packages.mozilla.org +Pin-Priority: 1000 +EOF +apt-get update +apt-get -y install --no-install-recommends -t mozilla firefox + +# geckodriver, at its latest release (independent of the Firefox version). +gd="$(latest_tag mozilla/geckodriver)" +case "$arch" in + arm64) gd_arch=linux-aarch64 ;; + *) gd_arch=linux64 ;; +esac +curl -fsSL "https://github.com/mozilla/geckodriver/releases/download/${gd}/geckodriver-${gd}-${gd_arch}.tar.gz" | + tar -C /usr/local/bin -xz geckodriver + +# Playwright's Chromium and Firefox. WebKit is skipped because no repository +# uses it today. Playwright's Chromium is also the headless Chrome for +# chromedp-style clients, exposed as `chromium` on PATH. +playwright install --with-deps chromium firefox +chromiums=( "$PLAYWRIGHT_BROWSERS_PATH"/chromium-*/chrome-linux*/chrome ) +if [ "${#chromiums[@]}" -ne 1 ] || [ ! -x "${chromiums[0]}" ]; then + echo "error: expected exactly one chromium binary, found ${#chromiums[@]}" >&2 + exit 1 +fi +ln -s "${chromiums[0]}" /usr/local/bin/chromium + # --- pyenv, Python (latest), pip, virtualenv --------------------------------- git clone -q --depth 1 --branch "$PYENV_GIT_TAG" https://github.com/pyenv/pyenv.git "$PYENV_ROOT" rm -rf "$PYENV_ROOT/.git" @@ -141,6 +177,10 @@ COREPACK_ENABLE_NETWORK=0 yarn --version COREPACK_ENABLE_NETWORK=0 pnpm --version wrangler --version prettier --version +playwright --version +firefox --version +geckodriver --version +chromium --version python3 --version pip --version virtualenv --version