From 59a41f6051526b6c5057240eed517955dae8355c Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 7 Dec 2022 15:57:01 -0800 Subject: [PATCH] chore: prepare to publish dockerfile.vrt docker image (#19324) This patch: - adds a new `Dockerfile.vrt` image file based on focal that installs VRT-related dependencies inside it. - updates scripts to build & publish the new docker image. Drive-by: remove stale file --- utils/docker/Dockerfile.vrt | 50 ++++++++++++++++++++++++++++++++++ utils/docker/build.sh | 2 +- utils/docker/publish_docker.sh | 21 ++++++++++++-- utils/docker/start_agent.sh | 31 --------------------- 4 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 utils/docker/Dockerfile.vrt delete mode 100644 utils/docker/start_agent.sh diff --git a/utils/docker/Dockerfile.vrt b/utils/docker/Dockerfile.vrt new file mode 100644 index 0000000000..2bc5959bfd --- /dev/null +++ b/utils/docker/Dockerfile.vrt @@ -0,0 +1,50 @@ +FROM ubuntu:focal + +ARG DEBIAN_FRONTEND=noninteractive +ARG TZ=America/Los_Angeles +ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright:v%version%-vrt" + +# === INSTALL Node.js === + +RUN apt-get update && \ + # Install node16 + apt-get install -y curl wget gpg && \ + curl -sL https://deb.nodesource.com/setup_16.x | bash - && \ + apt-get install -y nodejs && \ + # Feature-parity with node.js base images. + apt-get install -y --no-install-recommends git openssh-client && \ + npm install -g yarn && \ + # clean apt cache + rm -rf /var/lib/apt/lists/* && \ + # Create the pwuser + adduser pwuser + +# === BAKE BROWSERS INTO IMAGE === + +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 + +# 2. Bake in Playwright Agent. +# Playwright Agent is used to bake in browsers and browser dependencies, +# and run docker server later on. +# 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 && \ + npx playwright mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \ + npx playwright install --with-deps && \ + npx playwright docker install-server-deps && \ + rm /tmp/playwright-core.tar.gz && \ + chmod -R 777 /ms-playwright && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /ms-playwright-agent +ENV DISPLAY_NUM=99 +ENV DISPLAY=:99 +ENTRYPOINT npx playwright docker run-server diff --git a/utils/docker/build.sh b/utils/docker/build.sh index 1d69a5d918..c95ef42ec7 100755 --- a/utils/docker/build.sh +++ b/utils/docker/build.sh @@ -3,7 +3,7 @@ set -e set +x if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then - echo "usage: $(basename $0) {--arm64,--amd64} {focal,jammy} playwright:localbuild-focal" + echo "usage: $(basename $0) {--arm64,--amd64} {focal,jammy,vrt} playwright:localbuild-focal" echo echo "Build Playwright docker image and tag it as 'playwright:localbuild-focal'." echo "Once image is built, you can run it with" diff --git a/utils/docker/publish_docker.sh b/utils/docker/publish_docker.sh index 01eebae08a..0f32518622 100755 --- a/utils/docker/publish_docker.sh +++ b/utils/docker/publish_docker.sh @@ -53,6 +53,15 @@ if [[ "$RELEASE_CHANNEL" == "stable" ]]; then JAMMY_TAGS+=("jammy") fi +VRT_TAGS=( + "next-vrt" + "v${PW_VERSION}-vrt" +) + +if [[ "$RELEASE_CHANNEL" == "stable" ]]; then + VRT_TAGS+=("vrt") +fi + tag_and_push() { local source="$1" local target="$2" @@ -68,8 +77,10 @@ publish_docker_images_with_arch_suffix() { TAGS=("${FOCAL_TAGS[@]}") elif [[ "$FLAVOR" == "jammy" ]]; then TAGS=("${JAMMY_TAGS[@]}") + elif [[ "$FLAVOR" == "vrt" ]]; then + TAGS=("${VRT_TAGS[@]}") else - echo "ERROR: unknown flavor - $FLAVOR. Must be either 'focal', or 'jammy'" + echo "ERROR: unknown flavor - $FLAVOR. Must be either 'focal', 'jammy' or 'vrt'" exit 1 fi local ARCH="$2" @@ -94,8 +105,10 @@ publish_docker_manifest () { TAGS=("${FOCAL_TAGS[@]}") elif [[ "$FLAVOR" == "jammy" ]]; then TAGS=("${JAMMY_TAGS[@]}") + elif [[ "$FLAVOR" == "vrt" ]]; then + TAGS=("${VRT_TAGS[@]}") else - echo "ERROR: unknown flavor - $FLAVOR. Must be either 'focal', or 'jammy'" + echo "ERROR: unknown flavor - $FLAVOR. Must be either 'focal', 'jammy' or 'vrt'" exit 1 fi @@ -121,3 +134,7 @@ publish_docker_manifest focal amd64 arm64 publish_docker_images_with_arch_suffix jammy amd64 publish_docker_images_with_arch_suffix jammy arm64 publish_docker_manifest jammy amd64 arm64 + +publish_docker_images_with_arch_suffix vrt amd64 +publish_docker_images_with_arch_suffix vrt arm64 +publish_docker_manifest vrt amd64 arm64 diff --git a/utils/docker/start_agent.sh b/utils/docker/start_agent.sh deleted file mode 100644 index 349c618487..0000000000 --- a/utils/docker/start_agent.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -set -e -set +x - -DISPLAY_NUM=99 -export DISPLAY=":${DISPLAY_NUM}" - -SCREEN_WIDTH=1360 -SCREEN_HEIGHT=1020 -SCREEN_DEPTH=24 -SCREEN_DPI=96 -GEOMETRY="${SCREEN_WIDTH}""x""${SCREEN_HEIGHT}""x""${SCREEN_DEPTH}" - -nohup /usr/bin/xvfb-run --server-num=${DISPLAY_NUM} \ - --listen-tcp \ - --server-args="-screen 0 ${GEOMETRY} -fbdir /var/tmp -dpi ${SCREEN_DPI} -listen tcp -noreset -ac +extension RANDR" \ - /usr/bin/fluxbox -display ${DISPLAY} >/dev/null 2>&1 & - -for i in $(seq 1 50) - do - if xdpyinfo -display ${DISPLAY} >/dev/null 2>&1; then - break - fi - echo "Waiting for Xvfb..." - sleep 0.2 - done - -nohup x11vnc -forever -shared -rfbport 5900 -rfbportv6 5900 -display ${DISPLAY} >/dev/null 2>&1 & -nohup /opt/bin/noVNC/utils/launch.sh --listen 7900 --vnc localhost:5900 >/dev/null 2>&1 & - -npx playwright experimental-grid-agent --agent-id "$1" --grid-url "$2"