ci: add playwright deps to Dockerfile
What
Split the Docker image that is used for CI and deployer.
CI:
The existing Dockerfile dependencies are only needed for deployer, so
create an empty Dockerfile.ci, which seems strange, but we need it to
specify the correct NODE_VERSION
Deployer:
Run npx playwright install --with-deps to install the chromium browser and its
dependencies. We add this as a separate layer so that playwright
dependencies and other dependencies are cached individually.
This increases the size of the Docker image by quite a bit.
Why
Split the images for CI and Deployer because if we continue using the same image we slow down pipelines and the playwright is only needed for the deployer and not CI.
When running the E2E inside of the original Dockerfile it fails.
1) e2e/session_routing.spec.ts:6:7 › session prefix › legacy cell ────────────────────────────────
Error: browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ npx playwright install ║
║ ║
║ <3 Playwright Team ║
╚═════════════════════════════════════════════════════════════════════════╝
...
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Please install them with the following command: ║
║ ║
║ npx playwright install-deps ║
║ ║
║ Alternatively, use apt: ║
║ apt-get install libglib2.0-0\ ║
║ libnss3\ ║
║ libnspr4\ ║
║ libdbus-1-3\ ║
║ libatk1.0-0\ ║
║ libatk-bridge2.0-0\ ║
║ libcups2\ ║
║ libxcb1\ ║
║ libxkbcommon0\ ║
║ libatspi2.0-0\ ║
║ libx11-6\ ║
║ libxcomposite1\ ║
║ libxdamage1\ ║
║ libxext6\ ║
║ libxfixes3\ ║
║ libxrandr2\ ║
║ libgbm1\ ║
║ libpango-1.0-0\ ║
║ libcairo2\ ║
║ libasound2 ║
║ ║
║ <3 Playwright Team ║
╚══════════════════════════════════════════════════════╝
Testing
Before:
$ docker run -v $PWD:/app --rm -it --entrypoint=/bin/bash registry.gitlab.com/gitlab-org/cells/http-router/node:latest
root@a92c06a3a818:/app# rm -rf node_modules/
root@a92c06a3a818:/app# npm ci
root@a92c06a3a818:/app# npm run e2e:gstg
...
Error: browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium_headless_shell-1169/chrome-linux/headless_shell
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ npx playwright install ║
║ ║
║ <3 Playwright Team ║
╚═════════════════════════════════════════════════════════════════════════╝
After:
$ docker build -f Dockerfile.deployer . -t http-router:deployer --build-arg NODE_VERSION=22.14.0
$ docker run -v $PWD:/app --rm -it --entrypoint=/bin/bash http-router:deployer
root@54fedb883625:/app# npm ci
root@54fedb883625:/app# npm run e2e:gstg // Tests will fail but they
run.
reference: gitlab-com/gl-infra/tenant-scale/cells-infrastructure/team#22 (closed)