Skip to content

Commit 8cb967b

Browse files
committed
cherry-pick(#3200): devops(docker): move docker publishing to Azure Pipelines
1 parent ab18c77 commit 8cb967b

7 files changed

Lines changed: 234 additions & 102 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Trigger: any `v*` release tag (e.g. v1.40.0).
2+
# Can also be queued manually from the ADO UI.
3+
trigger:
4+
tags:
5+
include:
6+
- v*
7+
8+
pr: none
9+
10+
parameters:
11+
- name: releaseChannel
12+
displayName: "IMPORTANT: set this to 'canary' when triggering manually"
13+
type: string
14+
default: stable
15+
values:
16+
- stable
17+
- canary
18+
19+
resources:
20+
repositories:
21+
- repository: 1esPipelines
22+
type: git
23+
name: 1ESPipelineTemplates/1ESPipelineTemplates
24+
ref: refs/tags/release
25+
26+
extends:
27+
template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
28+
parameters:
29+
pool:
30+
name: DevDivPlaywrightAzurePipelinesUbuntu2204
31+
os: linux
32+
sdl:
33+
sourceAnalysisPool:
34+
name: DevDivPlaywrightAzurePipelinesWindows2022
35+
# The image must be windows-based due to restrictions of the SDL tools. See: https://aka.ms/AAo6v8e
36+
os: windows
37+
suppression:
38+
suppressionFile: $(Build.SourcesDirectory)\.azure-pipelines\guardian\SDL\.gdnsuppress
39+
stages:
40+
- stage: Publish
41+
jobs:
42+
- job: PublishDocker
43+
displayName: "Publish Docker images to ACR"
44+
# arm64 images are cross-built under QEMU emulation, which is slow.
45+
timeoutInMinutes: 360
46+
steps:
47+
# Full history and tags: setuptools-scm derives the package version
48+
# (and thus the image tags) from the release tag.
49+
- checkout: self
50+
fetchDepth: 0
51+
fetchTags: true
52+
displayName: "Checkout code"
53+
54+
- task: UsePythonVersion@0
55+
inputs:
56+
versionSpec: '3.10'
57+
displayName: "Use Python"
58+
59+
# Resolve pip installs through the DevDiv_PublicPackages feed. The task exports
60+
# an authenticated PIP_INDEX_URL, which build.sh also forwards to the image builds.
61+
- task: PipAuthenticate@1
62+
inputs:
63+
artifactFeeds: DevDiv/DevDiv_PublicPackages
64+
displayName: "Authenticate pip to DevDiv_PublicPackages feed"
65+
66+
- task: UseNode@1
67+
inputs:
68+
version: '24.x'
69+
displayName: "Install Node.js"
70+
71+
# Relocate the Docker data-root to the large /mnt volume: this job builds
72+
# 6 images (jammy/noble/resolute x amd64/arm64) and `docker system prune`s
73+
# between them, so the default disk fills up.
74+
- task: Bash@3
75+
displayName: "Setup docker"
76+
inputs:
77+
targetType: "inline"
78+
script: |
79+
set -x
80+
sudo service docker stop
81+
sudo mkdir -p /etc/docker
82+
echo '{ "data-root": "/mnt/docker" }' | sudo tee /etc/docker/daemon.json
83+
sudo service docker start
84+
85+
# scripts/build_driver.py fetches playwright-core with `npm pack`, which
86+
# picks up the registry and credentials from this .npmrc.
87+
- task: Bash@3
88+
displayName: "setup .npmrc"
89+
inputs:
90+
targetType: "inline"
91+
script: echo "registry=https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/DevDiv_PublicPackages/npm/registry/" >> .npmrc
92+
93+
- task: npmAuthenticate@0
94+
displayName: "authenticate the private npm registry"
95+
inputs:
96+
workingFile: .npmrc
97+
98+
- script: |
99+
python -m pip install --upgrade pip --disable-pip-version-check
100+
pip install -r local-requirements.txt --disable-pip-version-check
101+
pip install -r requirements.txt --disable-pip-version-check
102+
pip install -e . --disable-pip-version-check
103+
displayName: "Install dependencies"
104+
105+
- task: AzureCLI@2
106+
displayName: "Login to ACR via OIDC"
107+
inputs:
108+
azureSubscription: "Playwright-CDN"
109+
scriptType: "bash"
110+
scriptLocation: "inlineScript"
111+
inlineScript: "az acr login --name playwright"
112+
113+
- task: Bash@3
114+
displayName: "Register QEMU (binfmt) for arm64 cross-build"
115+
inputs:
116+
targetType: "inline"
117+
script: "docker run --rm --privileged ${ACR_CACHE_PREFIX}tonistiigi/binfmt --install arm64"
118+
env:
119+
ACR_CACHE_PREFIX: "playwright.azurecr.io/cached/"
120+
121+
- task: Bash@3
122+
displayName: "Build & publish Docker images"
123+
inputs:
124+
targetType: "inline"
125+
script: "./utils/docker/publish_docker.sh ${{ parameters.releaseChannel }}"
126+
env:
127+
ACR_CACHE_PREFIX: "playwright.azurecr.io/cached/"
128+
UBUNTU_MIRROR_PREFIX: "azure."

.github/workflows/publish_docker.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

utils/docker/Dockerfile.jammy

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
FROM ubuntu:jammy
1+
ARG ACR_CACHE_PREFIX
2+
FROM ${ACR_CACHE_PREFIX}ubuntu:jammy
23

34
ARG DEBIAN_FRONTEND=noninteractive
45
ARG TZ=America/Los_Angeles
56
ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright/python:v%version%-jammy"
7+
ARG UBUNTU_MIRROR_PREFIX
68

79
ENV LANG=C.UTF-8
810
ENV LC_ALL=C.UTF-8
911

1012
# === INSTALL Python ===
1113

12-
RUN apt-get update && \
14+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
15+
find /etc/apt -type f \( -name '*.list' -o -name '*.sources' \) \
16+
-exec sed -i "s|http://archive.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}archive.ubuntu.com|g; s|http://ports.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}ports.ubuntu.com|g" {} + && \
17+
apt-get update && \
1318
# Install Python
1419
apt-get install -y python3 python3-distutils curl && \
1520
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
@@ -35,7 +40,8 @@ COPY ./dist/*-manylinux*.whl /tmp/
3540
# Browsers will be downloaded in `/ms-playwright`.
3641
# Note: make sure to set 777 to the registry so that any user can access
3742
# registry.
38-
RUN mkdir /ms-playwright && \
43+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
44+
mkdir /ms-playwright && \
3945
mkdir /ms-playwright-agent && \
4046
cd /ms-playwright-agent && \
4147
pip install virtualenv && \

utils/docker/Dockerfile.noble

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
FROM ubuntu:noble
1+
ARG ACR_CACHE_PREFIX
2+
FROM ${ACR_CACHE_PREFIX}ubuntu:noble
23

34
ARG DEBIAN_FRONTEND=noninteractive
45
ARG TZ=America/Los_Angeles
56
ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright/python:v%version%-noble"
7+
ARG UBUNTU_MIRROR_PREFIX
68

79
ENV LANG=C.UTF-8
810
ENV LC_ALL=C.UTF-8
911

1012
# === INSTALL Python ===
1113

12-
RUN apt-get update && \
14+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
15+
find /etc/apt -type f \( -name '*.list' -o -name '*.sources' \) \
16+
-exec sed -i "s|http://archive.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}archive.ubuntu.com|g; s|http://ports.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}ports.ubuntu.com|g" {} + && \
17+
apt-get update && \
1318
# Install Python
1419
apt-get install -y python3 curl && \
1520
# Align with upstream Python image and don't be externally managed:
@@ -38,7 +43,8 @@ COPY ./dist/*-manylinux*.whl /tmp/
3843
# Browsers will be downloaded in `/ms-playwright`.
3944
# Note: make sure to set 777 to the registry so that any user can access
4045
# registry.
41-
RUN mkdir /ms-playwright && \
46+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
47+
mkdir /ms-playwright && \
4248
mkdir /ms-playwright-agent && \
4349
cd /ms-playwright-agent && \
4450
pip install virtualenv && \

utils/docker/Dockerfile.resolute

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
FROM ubuntu:resolute
1+
ARG ACR_CACHE_PREFIX
2+
FROM ${ACR_CACHE_PREFIX}ubuntu:resolute
23

34
ARG DEBIAN_FRONTEND=noninteractive
45
ARG TZ=America/Los_Angeles
56
ARG DOCKER_IMAGE_NAME_TEMPLATE="mcr.microsoft.com/playwright/python:v%version%-resolute"
7+
ARG UBUNTU_MIRROR_PREFIX
68

79
ENV LANG=C.UTF-8
810
ENV LC_ALL=C.UTF-8
911

1012
# === INSTALL Python ===
1113

12-
RUN apt-get update && \
14+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
15+
find /etc/apt -type f \( -name '*.list' -o -name '*.sources' \) \
16+
-exec sed -i "s|http://archive.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}archive.ubuntu.com|g; s|http://ports.ubuntu.com|http://${UBUNTU_MIRROR_PREFIX}ports.ubuntu.com|g" {} + && \
17+
apt-get update && \
1318
# Install Python
1419
apt-get install -y python3 curl && \
1520
# Align with upstream Python image and don't be externally managed:
@@ -38,7 +43,8 @@ COPY ./dist/*-manylinux*.whl /tmp/
3843
# Browsers will be downloaded in `/ms-playwright`.
3944
# Note: make sure to set 777 to the registry so that any user can access
4045
# registry.
41-
RUN mkdir /ms-playwright && \
46+
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf,required=false \
47+
mkdir /ms-playwright && \
4248
mkdir /ms-playwright-agent && \
4349
cd /ms-playwright-agent && \
4450
pip install virtualenv && \

utils/docker/build.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fi
1717

1818
function cleanup() {
1919
rm -rf "dist/"
20+
rm -f "${PIP_CONF:-}"
2021
}
2122

2223
trap "cleanup; cd $(pwd -P)" EXIT
@@ -40,4 +41,20 @@ else
4041
exit 1
4142
fi
4243

43-
docker build --platform "${PLATFORM}" -t "$3" -f "Dockerfile.$2" .
44+
# Let pip inside the image use the same package index as the host. Passed as a
45+
# BuildKit secret, so the (possibly authenticated) URL never lands in an image layer.
46+
SECRET_ARGS=()
47+
if [[ -n "${PIP_INDEX_URL:-}" ]]; then
48+
PIP_CONF="$(mktemp)"
49+
printf '[global]\nindex-url = %s\n' "${PIP_INDEX_URL}" > "${PIP_CONF}"
50+
SECRET_ARGS+=(--secret "id=pipconf,src=${PIP_CONF}")
51+
fi
52+
53+
# Keep each arch image a plain single-platform manifest without the unknown/unknown platform entry.
54+
export BUILDX_NO_DEFAULT_ATTESTATIONS=1
55+
56+
docker build --platform "${PLATFORM}" \
57+
--build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX}" \
58+
--build-arg UBUNTU_MIRROR_PREFIX="${UBUNTU_MIRROR_PREFIX}" \
59+
"${SECRET_ARGS[@]}" \
60+
-t "$3" -f "Dockerfile.$2" .

0 commit comments

Comments
 (0)