Skip to content

Instantly share code, notes, and snippets.

@uchagani
Created April 11, 2022 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchagani/af1c2fcc9f66c1dcb21650a3b914473e to your computer and use it in GitHub Desktop.
Save uchagani/af1c2fcc9f66c1dcb21650a3b914473e to your computer and use it in GitHub Desktop.
Playwright Dockerfile
FROM some-ubuntu-focal-based-image:latest
USER root
# === INSTALL JDK and Maven ===
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-11-jdk maven \
# Install utilities required for downloading browsers
curl \
# Install utilities required for downloading driver
unzip && \
rm -rf /var/lib/apt/lists/* && \
# Create the pwuser
adduser pwuser
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
# === BAKE BROWSERS INTO IMAGE ===
# Browsers will remain downloaded in `/ms-playwright`.
# Note: make sure to set 777 to the registry so that any user can access
# registry.
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
RUN mkdir /ms-playwright && \
mkdir /tmp/pw-java
COPY . /tmp/pw-java
RUN cd /tmp/pw-java && \
./playwright-scripts/get-playwright-source.sh && \
./scripts/download_driver_for_all_platforms.sh && \
mvn install -D skipTests --no-transfer-progress && \
DEBIAN_FRONTEND=noninteractive mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
-D exec.args="install-deps" -f playwright/pom.xml --no-transfer-progress && \
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI \
-D exec.args="install" -f playwright/pom.xml --no-transfer-progress && \
rm -rf /tmp/pw-java && \
chmod -R 777 $PLAYWRIGHT_BROWSERS_PATH
PLAYWRIGHT_VERSION=$(cat playwright-scripts/PLAYWRIGHT-VERSION
URL=https://github.com/microsoft/playwright-java/archive/refs/tags/v$PLAYWRIGHT_VERSION.tar.gz
FILENAME=playwright.tar.gz
curl -sSLo $FILENAME $URL
tar -xzf $FILENAME
mv playwright-java-PLAYWRIGHT_VERSION/* .
@fanzhe007
Copy link

tar -xzf $FILENAME not find get-playwright-source.sh,/bin/sh: 1: ./playwright-scripts/get-playwright-source.sh: not found

@uchagani
Copy link
Author

You need to put that script in a playwright-scripts folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment