Skip to content
Open
34 changes: 14 additions & 20 deletions utils/docker/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ENV LC_ALL=C.UTF-8
# === INSTALL Node.js ===

RUN apt-get update && \
# Install Node.js
apt-get install -y curl wget gpg ca-certificates && \
mkdir -p /etc/apt/keyrings && \
curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
Expand All @@ -27,33 +26,28 @@ RUN apt-get update && \
adduser pwuser

# === BAKE BROWSERS INTO IMAGE ===
# Browsers are split into separate layers to enable parallel pulls.

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# 1. Add tip-of-tree Playwright package to install its browsers.
# The package should be built beforehand from tip-of-tree Playwright.
COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz
COPY ./install_browsers.sh /tmp/install_browsers.sh

# 2. Bake in browsers & deps.
# Browsers will be downloaded in `/ms-playwright`.
# Note: make sure to set 777 to the registry so that any user can access
# registry.
RUN mkdir /ms-playwright && \
mkdir /ms-playwright-agent && \
cd /ms-playwright-agent && npm init -y && \
npm i /tmp/playwright-core.tar.gz && \
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
# 2. Set up playwright-core and install all system dependencies in one layer.
RUN /tmp/install_browsers.sh install-deps && \
# Workaround for https://github.com/microsoft/playwright/issues/27313
# While the gstreamer plugin load process can be in-process, it ended up throwing
# an error that it can't have libsoup2 and libsoup3 in the same process because
# libgstwebrtc is linked against libsoup2. So we just remove the plugin.
if [ "$(uname -m)" = "aarch64" ]; then \
rm /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstwebrtc.so; \
else \
rm /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstwebrtc.so; \
fi && \
rm /tmp/playwright-core.tar.gz && \
rm -rf /ms-playwright-agent && \
rm -rf ~/.npm/ && \
chmod -R 777 /ms-playwright
/tmp/install_browsers.sh remove-gstwebrtc

# 3. Install each browser binary in its own layer for parallel pulling.
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
RUN /tmp/install_browsers.sh chromium

RUN /tmp/install_browsers.sh firefox

RUN /tmp/install_browsers.sh webkit && \
/tmp/install_browsers.sh cleanup
28 changes: 13 additions & 15 deletions utils/docker/Dockerfile.noble
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ENV LC_ALL=C.UTF-8
# === INSTALL Node.js ===

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we also have Dockerfile.resolute now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated it


RUN apt-get update && \
# Install Node.js
apt-get install -y curl wget gpg ca-certificates && \
mkdir -p /etc/apt/keyrings && \
curl -sL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
Expand All @@ -27,24 +26,23 @@ RUN apt-get update && \
adduser pwuser

# === BAKE BROWSERS INTO IMAGE ===
# Browsers are split into separate layers to enable parallel pulls.

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# 1. Add tip-of-tree Playwright package to install its browsers.
# The package should be built beforehand from tip-of-tree Playwright.
COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz
COPY ./install_browsers.sh /tmp/install_browsers.sh

# 2. Bake in browsers & deps.
# Browsers will be downloaded in `/ms-playwright`.
# Note: make sure to set 777 to the registry so that any user can access
# registry.
RUN mkdir /ms-playwright && \
mkdir /ms-playwright-agent && \
cd /ms-playwright-agent && npm init -y && \
npm i /tmp/playwright-core.tar.gz && \
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
rm /tmp/playwright-core.tar.gz && \
rm -rf /ms-playwright-agent && \
rm -rf ~/.npm/ && \
chmod -R 777 /ms-playwright
# 2. Set up playwright-core and install all system dependencies in one layer.
RUN /tmp/install_browsers.sh install-deps

# 3. Install each browser binary in its own layer for parallel pulling.
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
RUN /tmp/install_browsers.sh chromium

RUN /tmp/install_browsers.sh firefox

RUN /tmp/install_browsers.sh webkit && \
/tmp/install_browsers.sh cleanup
27 changes: 13 additions & 14 deletions utils/docker/Dockerfile.resolute
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ RUN apt-get update && \
adduser pwuser

# === BAKE BROWSERS INTO IMAGE ===
# Browsers are split into separate layers to enable parallel pulls.

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# 1. Add tip-of-tree Playwright package to install its browsers.
# The package should be built beforehand from tip-of-tree Playwright.
COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz
COPY ./install_browsers.sh /tmp/install_browsers.sh

# 2. Bake in browsers & deps.
# Browsers will be downloaded in `/ms-playwright`.
# Note: make sure to set 777 to the registry so that any user can access
# registry.
RUN mkdir /ms-playwright && \
mkdir /ms-playwright-agent && \
cd /ms-playwright-agent && npm init -y && \
npm i /tmp/playwright-core.tar.gz && \
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
rm /tmp/playwright-core.tar.gz && \
rm -rf /ms-playwright-agent && \
rm -rf ~/.npm/ && \
chmod -R 777 /ms-playwright
# 2. Set up playwright-core and install all system dependencies in one layer.
RUN /tmp/install_browsers.sh install-deps

# 3. Install each browser binary in its own layer for parallel pulling.
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
RUN /tmp/install_browsers.sh chromium

RUN /tmp/install_browsers.sh firefox

RUN /tmp/install_browsers.sh webkit && \
/tmp/install_browsers.sh cleanup
47 changes: 47 additions & 0 deletions utils/docker/install_browsers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely convinced this separate script makes it easier to maintain things. Also, we are now mixing up a refactoring and a "split layers" feature, which makes it hard to review what exactly is changing in the Dockerfile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still get the split layers feature, whilst consolidating duplicate logic in 3 files, which I faced an issue with because I kept changing things in jammy, and forgetting to update noble / resolute.

set -euo pipefail

case "${1:-}" in
install-deps)
install -d -m 777 /ms-playwright /ms-playwright/.links
mkdir /ms-playwright-agent
cd /ms-playwright-agent
npm init -y
npm i /tmp/playwright-core.tar.gz
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}"
npm exec --no -- playwright-core install-deps
rm -rf /var/lib/apt/lists/*
;;
remove-gstwebrtc)
if [ "$(uname -m)" = "aarch64" ]; then
rm /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstwebrtc.so
else
rm /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstwebrtc.so
fi
;;
chromium)
cd /ms-playwright-agent
npm exec --no -- playwright-core install chromium
chmod -R 777 /ms-playwright/chromium-* /ms-playwright/chromium_headless_shell-* /ms-playwright/ffmpeg-*
;;
firefox)
cd /ms-playwright-agent
npm exec --no -- playwright-core install firefox
chmod -R 777 /ms-playwright/firefox-*
;;
webkit)
cd /ms-playwright-agent
npm exec --no -- playwright-core install webkit
chmod -R 777 /ms-playwright/webkit-*
;;
cleanup)
rm /tmp/playwright-core.tar.gz
rm -rf /ms-playwright-agent
rm -rf ~/.npm/
rm /tmp/install_browsers.sh
;;
*)
echo "usage: $(basename "$0") {install-deps|remove-gstwebrtc|chromium|firefox|webkit|cleanup}"
exit 1
;;
esac