Skip to content

Commit 82b984f

Browse files
authored
devops(docker): route apt through the Azure Debian mirror (#1759)
## Summary - The docker publish pipeline fails in `playwright-core install-deps chromium`: the agents cannot reach `deb.debian.org` (it resolves to `192.0.2.133`, TEST-NET-1), so apt gets no package lists and every browser dependency is `Unable to locate package`. - Add a `DEBIAN_MIRROR_HOST` build arg and set it to `debian-archive.trafficmanager.net` in the pipeline. This mirrors what playwright does with `UBUNTU_MIRROR_PREFIX: "azure."`; the Azure Debian mirror is a different host rather than a prefix of `deb.debian.org`, hence the different shape. - apt is repointed only for the duration of `install-deps` and restored right after, so the published image keeps `deb.debian.org` for anyone running apt in a derived image. - Default is `deb.debian.org`, so local and GitHub Actions builds are unchanged.
1 parent ea43eee commit 82b984f

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

.azure-pipelines/publish-docker.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ extends:
119119
script: "./utils/docker/publish_docker.sh ${{ parameters.releaseChannel }}"
120120
env:
121121
ACR_CACHE_PREFIX: "playwright.azurecr.io/cached/"
122+
# The agents cannot reach deb.debian.org, so apt goes through the Azure mirror.
123+
DEBIAN_MIRROR_HOST: "debian-archive.trafficmanager.net"
122124
NPMRC_SECRET: "$(Build.SourcesDirectory)/.npmrc"

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ARG PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
22
# Registry prefix for the base image, e.g. 'playwright.azurecr.io/cached/' in the publish pipeline.
33
ARG ACR_CACHE_PREFIX
4+
# Debian archive host used by apt, e.g. 'debian-archive.trafficmanager.net' in the publish pipeline.
5+
ARG DEBIAN_MIRROR_HOST=deb.debian.org
46

57
# ------------------------------
68
# Base
@@ -11,6 +13,7 @@ FROM ${ACR_CACHE_PREFIX}node:22-bookworm-slim AS base
1113

1214
ARG PLAYWRIGHT_BROWSERS_PATH
1315
ENV PLAYWRIGHT_BROWSERS_PATH=${PLAYWRIGHT_BROWSERS_PATH}
16+
ARG DEBIAN_MIRROR_HOST
1417

1518
# Set the working directory
1619
WORKDIR /app
@@ -20,8 +23,11 @@ RUN --mount=type=cache,target=/root/.npm,sharing=locked,id=npm-cache \
2023
--mount=type=bind,source=package-lock.json,target=package-lock.json \
2124
--mount=type=secret,id=npmrc,target=/root/.npmrc,required=false \
2225
npm ci --omit=dev && \
23-
# Install system dependencies for playwright
24-
npx -y playwright-core install-deps chromium
26+
# Install system dependencies for playwright. apt is pointed at the mirror only for
27+
# the duration of the install, so the published image keeps the default archive host.
28+
sed -i "s|deb.debian.org|${DEBIAN_MIRROR_HOST}|g" /etc/apt/sources.list.d/debian.sources && \
29+
npx -y playwright-core install-deps chromium && \
30+
sed -i "s|${DEBIAN_MIRROR_HOST}|deb.debian.org|g" /etc/apt/sources.list.d/debian.sources
2531

2632
# ------------------------------
2733
# Builder

utils/docker/build.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then
1111
echo " docker run -i --rm --init playwright-mcp:localbuild"
1212
echo ""
1313
echo "Optional environment variables:"
14-
echo " ACR_CACHE_PREFIX registry prefix for the base image, e.g. 'playwright.azurecr.io/cached/'"
15-
echo " NPMRC_SECRET path to an .npmrc to use for 'npm ci' inside the image (BuildKit secret)"
14+
echo " ACR_CACHE_PREFIX registry prefix for the base image, e.g. 'playwright.azurecr.io/cached/'"
15+
echo " DEBIAN_MIRROR_HOST apt archive host, e.g. 'debian-archive.trafficmanager.net'"
16+
echo " NPMRC_SECRET path to an .npmrc to use for 'npm ci' inside the image (BuildKit secret)"
1617
echo ""
1718
exit 0
1819
fi
@@ -38,6 +39,12 @@ if [[ -n "${NPMRC_SECRET:-}" ]]; then
3839
SECRET_ARGS+=(--secret "id=npmrc,src=${NPMRC_SECRET}")
3940
fi
4041

42+
# Only override the Dockerfile's default archive host when a mirror is requested.
43+
MIRROR_ARGS=()
44+
if [[ -n "${DEBIAN_MIRROR_HOST:-}" ]]; then
45+
MIRROR_ARGS+=(--build-arg "DEBIAN_MIRROR_HOST=${DEBIAN_MIRROR_HOST}")
46+
fi
47+
4148
# Keep each arch image a plain single-platform manifest without the unknown/unknown platform entry.
4249
export BUILDX_NO_DEFAULT_ATTESTATIONS=1
4350

@@ -54,6 +61,7 @@ fi
5461
for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do
5562
if docker build --platform "${PLATFORM}" \
5663
--build-arg ACR_CACHE_PREFIX="${ACR_CACHE_PREFIX:-}" \
64+
"${MIRROR_ARGS[@]}" \
5765
"${SECRET_ARGS[@]}" \
5866
-t "$2" -f Dockerfile .; then
5967
exit 0

0 commit comments

Comments
 (0)