同步完整源码 - 2026-05-24
This commit is contained in:
@@ -0,0 +1 @@
|
||||
oras/
|
||||
@@ -0,0 +1,61 @@
|
||||
FROM ubuntu:jammy
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ARG TZ=America/Los_Angeles
|
||||
ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright/python:v%version%-jammy"
|
||||
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=C.UTF-8
|
||||
|
||||
# === INSTALL Python ===
|
||||
|
||||
RUN apt-get update && \
|
||||
# Install Python
|
||||
apt-get install -y python3 python3-distutils curl && \
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
|
||||
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
|
||||
python get-pip.py && \
|
||||
rm get-pip.py && \
|
||||
# Feature-parity with node.js base images.
|
||||
apt-get install -y --no-install-recommends git openssh-client gpg && \
|
||||
# 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 ./dist/*-manylinux*.whl /tmp/
|
||||
|
||||
# 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 && \
|
||||
pip install virtualenv && \
|
||||
virtualenv venv && \
|
||||
. venv/bin/activate && \
|
||||
# if its amd64 then install the manylinux1_x86_64 pip package
|
||||
if [ "$(uname -m)" = "x86_64" ]; then pip install /tmp/*manylinux1_x86_64*.whl; fi && \
|
||||
# if its arm64 then install the manylinux1_aarch64 pip package
|
||||
if [ "$(uname -m)" = "aarch64" ]; then pip install /tmp/*manylinux_2_17_aarch64*.whl; fi && \
|
||||
playwright mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
|
||||
playwright install --with-deps && rm -rf /var/lib/apt/lists/* && \
|
||||
# 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/*.whl && \
|
||||
rm -rf /ms-playwright-agent && \
|
||||
chmod -R 777 /ms-playwright
|
||||
@@ -0,0 +1,55 @@
|
||||
FROM ubuntu:noble
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ARG TZ=America/Los_Angeles
|
||||
ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright/python:v%version%-noble"
|
||||
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=C.UTF-8
|
||||
|
||||
# === INSTALL Python ===
|
||||
|
||||
RUN apt-get update && \
|
||||
# Install Python
|
||||
apt-get install -y python3 curl && \
|
||||
# Align with upstream Python image and don't be externally managed:
|
||||
# https://github.com/docker-library/python/issues/948
|
||||
rm /usr/lib/python3.12/EXTERNALLY-MANAGED && \
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
|
||||
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
|
||||
python get-pip.py && \
|
||||
rm get-pip.py && \
|
||||
# Feature-parity with node.js base images.
|
||||
apt-get install -y --no-install-recommends git openssh-client gpg && \
|
||||
# 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 ./dist/*-manylinux*.whl /tmp/
|
||||
|
||||
# 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 && \
|
||||
pip install virtualenv && \
|
||||
virtualenv venv && \
|
||||
. venv/bin/activate && \
|
||||
# if its amd64 then install the manylinux1_x86_64 pip package
|
||||
if [ "$(uname -m)" = "x86_64" ]; then pip install /tmp/*manylinux1_x86_64*.whl; fi && \
|
||||
# if its arm64 then install the manylinux1_aarch64 pip package
|
||||
if [ "$(uname -m)" = "aarch64" ]; then pip install /tmp/*manylinux_2_17_aarch64*.whl; fi && \
|
||||
playwright mark-docker-image "${DOCKER_IMAGE_NAME_TEMPLATE}" && \
|
||||
playwright install --with-deps && rm -rf /var/lib/apt/lists/* && \
|
||||
rm /tmp/*.whl && \
|
||||
rm -rf /ms-playwright-agent && \
|
||||
chmod -R 777 /ms-playwright
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set +x
|
||||
|
||||
if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then
|
||||
echo "usage: $(basename $0) {--arm64,--amd64} {jammy,noble} playwright:localbuild-noble"
|
||||
echo
|
||||
echo "Build Playwright docker image and tag it as 'playwright:localbuild-noble'."
|
||||
echo "Once image is built, you can run it with"
|
||||
echo ""
|
||||
echo " docker run --rm -it playwright:localbuild-noble /bin/bash"
|
||||
echo ""
|
||||
echo "NOTE: this requires on Playwright PIP dependencies to be installed"
|
||||
echo ""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function cleanup() {
|
||||
rm -rf "dist/"
|
||||
}
|
||||
|
||||
trap "cleanup; cd $(pwd -P)" EXIT
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
pushd ../../
|
||||
for wheel in $(python setup.py --list-wheels); do
|
||||
PLAYWRIGHT_TARGET_WHEEL=$wheel python -m build --wheel
|
||||
done
|
||||
popd
|
||||
mkdir dist/
|
||||
cp ../../dist/*-manylinux*.whl dist/
|
||||
|
||||
PLATFORM=""
|
||||
if [[ "$1" == "--arm64" ]]; then
|
||||
PLATFORM="linux/arm64";
|
||||
elif [[ "$1" == "--amd64" ]]; then
|
||||
PLATFORM="linux/amd64"
|
||||
else
|
||||
echo "ERROR: unknown platform specifier - $1. Only --arm64 or --amd64 is supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker build --platform "${PLATFORM}" -t "$3" -f "Dockerfile.$2" .
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set +x
|
||||
|
||||
trap "cd $(pwd -P)" EXIT
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
MCR_IMAGE_NAME="playwright/python"
|
||||
PW_VERSION=$(python -c "from playwright._repo_version import version;print(version)")
|
||||
|
||||
RELEASE_CHANNEL="$1"
|
||||
if [[ "${RELEASE_CHANNEL}" == "stable" ]]; then
|
||||
if [[ "${PW_VERSION}" == *post* ]]; then
|
||||
echo "ERROR: cannot publish stable docker with Playwright version '${PW_VERSION}'"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "ERROR: unknown release channel - ${RELEASE_CHANNEL}"
|
||||
echo "Must be either 'stable' or 'canary'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ubuntu 22.04
|
||||
JAMMY_TAGS=(
|
||||
"v${PW_VERSION}-jammy"
|
||||
)
|
||||
|
||||
# Ubuntu 24.04
|
||||
NOBLE_TAGS=(
|
||||
"v${PW_VERSION}"
|
||||
"v${PW_VERSION}-noble"
|
||||
)
|
||||
|
||||
tag_and_push() {
|
||||
local source="$1"
|
||||
local target="$2"
|
||||
echo "-- tagging: $target"
|
||||
docker tag $source $target
|
||||
docker push $target
|
||||
attach_eol_manifest $target
|
||||
}
|
||||
|
||||
attach_eol_manifest() {
|
||||
local image="$1"
|
||||
local today=$(date -u +'%Y-%m-%d')
|
||||
install_oras_if_needed
|
||||
# oras is re-using Docker credentials, so we don't need to login.
|
||||
# Following the advice in https://portal.microsofticm.com/imp/v3/incidents/incident/476783820/summary
|
||||
./oras/oras attach --artifact-type application/vnd.microsoft.artifact.lifecycle --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$today" $image
|
||||
}
|
||||
|
||||
install_oras_if_needed() {
|
||||
if [[ -x oras/oras ]]; then
|
||||
return
|
||||
fi
|
||||
local version="1.1.0"
|
||||
curl -sLO "https://github.com/oras-project/oras/releases/download/v${version}/oras_${version}_linux_amd64.tar.gz"
|
||||
mkdir -p oras
|
||||
tar -zxf oras_${version}_linux_amd64.tar.gz -C oras
|
||||
rm oras_${version}_linux_amd64.tar.gz
|
||||
}
|
||||
|
||||
publish_docker_images_with_arch_suffix() {
|
||||
local FLAVOR="$1"
|
||||
local TAGS=()
|
||||
if [[ "$FLAVOR" == "jammy" ]]; then
|
||||
TAGS=("${JAMMY_TAGS[@]}")
|
||||
elif [[ "$FLAVOR" == "noble" ]]; then
|
||||
TAGS=("${NOBLE_TAGS[@]}")
|
||||
else
|
||||
echo "ERROR: unknown flavor - $FLAVOR. Must be either 'jammy', or 'noble'"
|
||||
exit 1
|
||||
fi
|
||||
local ARCH="$2"
|
||||
if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then
|
||||
echo "ERROR: unknown arch - $ARCH. Must be either 'amd64' or 'arm64'"
|
||||
exit 1
|
||||
fi
|
||||
# Prune docker images to avoid platform conflicts
|
||||
docker system prune -fa
|
||||
./build.sh "--${ARCH}" "${FLAVOR}" "${MCR_IMAGE_NAME}:localbuild"
|
||||
|
||||
for ((i = 0; i < ${#TAGS[@]}; i++)) do
|
||||
local TAG="${TAGS[$i]}"
|
||||
tag_and_push "${MCR_IMAGE_NAME}:localbuild" "playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}-${ARCH}"
|
||||
done
|
||||
}
|
||||
|
||||
publish_docker_manifest () {
|
||||
local FLAVOR="$1"
|
||||
local TAGS=()
|
||||
if [[ "$FLAVOR" == "jammy" ]]; then
|
||||
TAGS=("${JAMMY_TAGS[@]}")
|
||||
elif [[ "$FLAVOR" == "noble" ]]; then
|
||||
TAGS=("${NOBLE_TAGS[@]}")
|
||||
else
|
||||
echo "ERROR: unknown flavor - $FLAVOR. Must be either 'jammy', or 'noble'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for ((i = 0; i < ${#TAGS[@]}; i++)) do
|
||||
local TAG="${TAGS[$i]}"
|
||||
local BASE_IMAGE_TAG="playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}"
|
||||
local IMAGE_NAMES=""
|
||||
if [[ "$2" == "arm64" || "$2" == "amd64" ]]; then
|
||||
IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$2"
|
||||
fi
|
||||
if [[ "$3" == "arm64" || "$3" == "amd64" ]]; then
|
||||
IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$3"
|
||||
fi
|
||||
docker manifest create "${BASE_IMAGE_TAG}" $IMAGE_NAMES
|
||||
docker manifest push "${BASE_IMAGE_TAG}"
|
||||
done
|
||||
}
|
||||
|
||||
# Jammy
|
||||
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 noble amd64
|
||||
publish_docker_images_with_arch_suffix noble arm64
|
||||
publish_docker_manifest noble amd64 arm64
|
||||
Reference in New Issue
Block a user