11ARG ACR_CACHE_PREFIX
2- FROM ${ACR_CACHE_PREFIX}ubuntu:jammy
2+ FROM ${ACR_CACHE_PREFIX}ubuntu:jammy AS base
33
44ARG DEBIAN_FRONTEND=noninteractive
55ARG TZ=America/Los_Angeles
@@ -38,8 +38,26 @@ RUN --mount=type=bind,source=utils/docker/maven,target=/tmp/maven \
3838ARG PW_TARGET_ARCH
3939ENV JAVA_HOME=/usr/lib/jvm/java-25-openjdk-${PW_TARGET_ARCH}
4040
41+ # === BUILD PLAYWRIGHT JAVA ===
42+
43+ # The image gets only what the final stage explicitly copies or mounts from this stage.
44+ FROM base AS builder
45+
46+ # The optional Maven settings secret routes dependency resolution through a mirror
47+ # (see .azure-pipelines/publish-docker.yml). The CLI runs from /build: the classes of
48+ # the playwright module and its runtime dependencies.
49+ RUN --mount=type=bind,source=.,target=/tmp/pw-java,rw \
50+ --mount=type=secret,id=mavensettings,target=/root/.m2/settings.xml,required=false \
51+ cd /tmp/pw-java && \
52+ mvn install -D skipTests --no-transfer-progress && \
53+ mvn dependency:copy-dependencies -D includeScope=runtime -D outputDirectory=/build/lib \
54+ -f playwright/pom.xml --no-transfer-progress && \
55+ cp -r playwright/target/classes /build/classes
56+
4157# === BAKE BROWSERS INTO IMAGE ===
4258
59+ FROM base
60+
4361# Browsers will remain downloaded in `/ms-playwright`.
4462# Note: make sure to set 777 to the registry so that any user can access
4563# registry.
@@ -50,25 +68,17 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
5068# it into /tmp on every launch. See https://github.com/microsoft/playwright-java/issues/1268.
5169ENV PLAYWRIGHT_DRIVER_DIR=/ms-playwright-driver
5270
53- RUN mkdir /ms-playwright && \
54- mkdir /tmp/pw-java
71+ # Keep the playwright-java artifacts in the local Maven repository so that Maven projects
72+ # built in the image resolve them without downloading.
73+ COPY --from=builder /root/.m2/repository/com/microsoft/playwright /root/.m2/repository/com/microsoft/playwright
5574
56- COPY . /tmp/pw-java
75+ RUN mkdir /ms-playwright
5776
58- # The optional Maven settings secret routes dependency resolution through a mirror
59- # (see .azure-pipelines/publish-docker.yml).
60- RUN --mount=type=secret,id=mavensettings,target=/root/.m2/settings.xml,required=false \
61- cd /tmp/pw-java && \
62- mvn install -D skipTests --no-transfer-progress && \
63- mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
64- -D exec.args="install-driver" -f playwright/pom.xml --no-transfer-progress && \
65- DEBIAN_FRONTEND=noninteractive mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
66- -D exec.args="install-deps" -f playwright/pom.xml --no-transfer-progress && \
67- mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
68- -D exec.args="install" -f playwright/pom.xml --no-transfer-progress && \
69- mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
70- -D exec.args="mark-docker-image '${DOCKER_IMAGE_NAME_TEMPLATE}'" -f playwright/pom.xml --no-transfer-progress && \
71- rm -rf /tmp/pw-java && \
77+ RUN --mount=type=bind,from=builder,source=/build,target=/tmp/pw-java \
78+ java -cp '/tmp/pw-java/classes:/tmp/pw-java/lib/*' com.microsoft.playwright.CLI install-driver && \
79+ DEBIAN_FRONTEND=noninteractive java -cp '/tmp/pw-java/classes:/tmp/pw-java/lib/*' com.microsoft.playwright.CLI install-deps && \
80+ java -cp '/tmp/pw-java/classes:/tmp/pw-java/lib/*' com.microsoft.playwright.CLI install && \
81+ java -cp '/tmp/pw-java/classes:/tmp/pw-java/lib/*' com.microsoft.playwright.CLI mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
7282 # Workaround for https://github.com/microsoft/playwright/issues/27313
7383 # While the gstreamer plugin load process can be in-process, it ended up throwing
7484 # an error that it can't have libsoup2 and libsoup3 in the same process because
0 commit comments