Skip to content

Commit 4b6f031

Browse files
authored
devops(docker): split browser layers and use zstd compression for faster pulls (#41232)
1 parent ae114c8 commit 4b6f031

3 files changed

Lines changed: 57 additions & 23 deletions

File tree

utils/docker/Dockerfile.jammy

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ENV LC_ALL=C.UTF-8
1111
# === INSTALL Node.js ===
1212

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

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

3131
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
3232

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

37-
# 2. Bake in browsers & deps.
38-
# Browsers will be downloaded in `/ms-playwright`.
39-
# Note: make sure to set 777 to the registry so that any user can access
40-
# registry.
41-
RUN mkdir /ms-playwright && \
37+
# 2. Set up playwright-core and install all system dependencies in one layer.
38+
RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \
4239
mkdir /ms-playwright-agent && \
4340
cd /ms-playwright-agent && npm init -y && \
4441
npm i /tmp/playwright-core.tar.gz && \
4542
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
46-
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
43+
npm exec --no -- playwright-core install-deps && \
4744
# Workaround for https://github.com/microsoft/playwright/issues/27313
4845
# While the gstreamer plugin load process can be in-process, it ended up throwing
4946
# an error that it can't have libsoup2 and libsoup3 in the same process because
@@ -53,7 +50,21 @@ RUN mkdir /ms-playwright && \
5350
else \
5451
rm /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstwebrtc.so; \
5552
fi && \
53+
rm -rf /var/lib/apt/lists/*
54+
55+
# 3. Install each browser binary in its own layer for parallel pulling.
56+
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
57+
RUN cd /ms-playwright-agent && \
58+
npm exec --no -- playwright-core install chromium && \
59+
chmod -R 777 /ms-playwright/chromium-* /ms-playwright/chromium_headless_shell-* /ms-playwright/ffmpeg-*
60+
61+
RUN cd /ms-playwright-agent && \
62+
npm exec --no -- playwright-core install firefox && \
63+
chmod -R 777 /ms-playwright/firefox-*
64+
65+
RUN cd /ms-playwright-agent && \
66+
npm exec --no -- playwright-core install webkit && \
5667
rm /tmp/playwright-core.tar.gz && \
5768
rm -rf /ms-playwright-agent && \
5869
rm -rf ~/.npm/ && \
59-
chmod -R 777 /ms-playwright
70+
chmod -R 777 /ms-playwright/webkit-*

utils/docker/Dockerfile.noble

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ENV LC_ALL=C.UTF-8
1111
# === INSTALL Node.js ===
1212

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

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

3131
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
3232

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

37-
# 2. Bake in browsers & deps.
38-
# Browsers will be downloaded in `/ms-playwright`.
39-
# Note: make sure to set 777 to the registry so that any user can access
40-
# registry.
41-
RUN mkdir /ms-playwright && \
37+
# 2. Set up playwright-core and install all system dependencies in one layer.
38+
RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \
4239
mkdir /ms-playwright-agent && \
4340
cd /ms-playwright-agent && npm init -y && \
4441
npm i /tmp/playwright-core.tar.gz && \
4542
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
46-
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
43+
npm exec --no -- playwright-core install-deps && \
44+
rm -rf /var/lib/apt/lists/*
45+
46+
# 3. Install each browser binary in its own layer for parallel pulling.
47+
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
48+
RUN cd /ms-playwright-agent && \
49+
npm exec --no -- playwright-core install chromium && \
50+
chmod -R 777 /ms-playwright/chromium-* /ms-playwright/chromium_headless_shell-* /ms-playwright/ffmpeg-*
51+
52+
RUN cd /ms-playwright-agent && \
53+
npm exec --no -- playwright-core install firefox && \
54+
chmod -R 777 /ms-playwright/firefox-*
55+
56+
RUN cd /ms-playwright-agent && \
57+
npm exec --no -- playwright-core install webkit && \
4758
rm /tmp/playwright-core.tar.gz && \
4859
rm -rf /ms-playwright-agent && \
4960
rm -rf ~/.npm/ && \
50-
chmod -R 777 /ms-playwright
61+
chmod -R 777 /ms-playwright/webkit-*

utils/docker/Dockerfile.resolute

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,36 @@ RUN apt-get update && \
2727
adduser pwuser
2828

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

3132
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
3233

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

37-
# 2. Bake in browsers & deps.
38-
# Browsers will be downloaded in `/ms-playwright`.
39-
# Note: make sure to set 777 to the registry so that any user can access
40-
# registry.
41-
RUN mkdir /ms-playwright && \
38+
# 2. Set up playwright-core and install all system dependencies in one layer.
39+
RUN install -d -m 777 /ms-playwright /ms-playwright/.links && \
4240
mkdir /ms-playwright-agent && \
4341
cd /ms-playwright-agent && npm init -y && \
4442
npm i /tmp/playwright-core.tar.gz && \
4543
npm exec --no -- playwright-core mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
46-
npm exec --no -- playwright-core install --with-deps && rm -rf /var/lib/apt/lists/* && \
44+
npm exec --no -- playwright-core install-deps && \
45+
rm -rf /var/lib/apt/lists/*
46+
47+
# 3. Install each browser binary in its own layer for parallel pulling.
48+
# Note: installing chromium also installs chromium-headless-shell and ffmpeg.
49+
RUN cd /ms-playwright-agent && \
50+
npm exec --no -- playwright-core install chromium && \
51+
chmod -R 777 /ms-playwright/chromium-* /ms-playwright/chromium_headless_shell-* /ms-playwright/ffmpeg-*
52+
53+
RUN cd /ms-playwright-agent && \
54+
npm exec --no -- playwright-core install firefox && \
55+
chmod -R 777 /ms-playwright/firefox-*
56+
57+
RUN cd /ms-playwright-agent && \
58+
npm exec --no -- playwright-core install webkit && \
4759
rm /tmp/playwright-core.tar.gz && \
4860
rm -rf /ms-playwright-agent && \
4961
rm -rf ~/.npm/ && \
50-
chmod -R 777 /ms-playwright
62+
chmod -R 777 /ms-playwright/webkit-*

0 commit comments

Comments
 (0)