Skip to content

Commit e127abb

Browse files
authored
chore: align Docker with upstream Docker infra (microsoft#831)
1 parent 5ee8f23 commit e127abb

File tree

8 files changed

+187
-38
lines changed

8 files changed

+187
-38
lines changed

.github/workflows/publish_canary_docker.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ jobs:
1717
username: playwright
1818
password: ${{ secrets.DOCKER_PASSWORD }}
1919
- uses: actions/checkout@v2
20-
- name: Build Docker image
21-
run: docker build -t playwright-java:localbuild-focal -f Dockerfile.focal .
22-
- name: tag & publish
23-
run: |
24-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:next
25-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:next-focal
26-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:sha-${{ github.sha }}
20+
- name: Set up Docker QEMU for arm64 docker builds
21+
uses: docker/setup-qemu-action@v1
22+
with:
23+
platforms: arm64
24+
- name: publish docker canary
25+
run: ./utils/docker/publish_docker.sh canary

.github/workflows/publish_docker_release.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ jobs:
1717
login-server: playwright.azurecr.io
1818
username: playwright
1919
password: ${{ secrets.DOCKER_PASSWORD }}
20+
- name: Set up Docker QEMU for arm64 docker builds
21+
uses: docker/setup-qemu-action@v1
22+
with:
23+
platforms: arm64
2024
- uses: actions/checkout@v2
21-
- name: Build Docker image
22-
run: docker build -t playwright-java:localbuild-focal -f Dockerfile.focal .
23-
- name: tag & publish
24-
run: |
25-
# GITHUB_REF has a form of `refs/tags/v1.3.0`.
26-
# TAG_NAME would be `v1.3.0`
27-
TAG_NAME=${GITHUB_REF#refs/tags/}
28-
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]];
29-
then
30-
echo "Wrong TAG_NAME format: $TAG_NAME"
31-
exit 1
32-
fi
33-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:latest
34-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:focal
35-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:${TAG_NAME}
36-
./scripts/tag_image_and_push.sh playwright-java:localbuild-focal playwright.azurecr.io/public/playwright/java:${TAG_NAME}-focal
25+
- run: ./utils/docker/publish_docker.sh stable
26+
if: (github.event_name != 'workflow_dispatch' && !github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true')
27+
- run: ./utils/docker/publish_docker.sh canary
28+
if: (github.event_name != 'workflow_dispatch' && github.event.release.prerelease) || (github.event_name == 'workflow_dispatch' && github.event.inputs.is_release != 'true')

.github/workflows/test_docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v2
2525
- name: Build Docker image
26-
run: docker build -t playwright-java:localbuild-focal -f Dockerfile.focal .
26+
run: bash utils/docker/build.sh --amd64 focal playwright-java:localbuild-focal
2727
- name: Test
2828
run: |
2929
CONTAINER_ID="$(docker run --rm --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-focal /bin/bash)"

scripts/tag_image_and_push.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@ FROM ubuntu:focal
22

33
# === INSTALL JDK and Maven ===
44

5-
RUN apt-get update && apt-get install -y --no-install-recommends \
6-
openjdk-11-jdk maven
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
openjdk-11-jdk maven \
8+
# Install utilities required for downloading browsers
9+
curl \
10+
# Install utilities required for downloading driver
11+
unzip && \
12+
rm -rf /var/lib/apt/lists/* && \
13+
# Create the pwuser
14+
adduser pwuser
715

816
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
917

10-
# Install utilities required for downloading driver
11-
RUN apt-get update && apt-get install -y --no-install-recommends \
12-
curl unzip
13-
14-
# === INSTALL playwright maven modules & browsers ===
18+
# === BAKE BROWSERS INTO IMAGE ===
1519

1620
# Browsers will remain downloaded in `/ms-playwright`.
1721
# Note: make sure to set 777 to the registry so that any user can access
1822
# registry.
1923
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
2024

21-
RUN mkdir /ms-playwright && chmod -R 777 $PLAYWRIGHT_BROWSERS_PATH
25+
RUN mkdir /ms-playwright && \
26+
chmod -R 777 $PLAYWRIGHT_BROWSERS_PATH && \
27+
mkdir /tmp/pw-java
2228

23-
RUN mkdir /tmp/pw-java
2429
COPY . /tmp/pw-java
30+
2531
RUN cd /tmp/pw-java && \
2632
./scripts/download_driver_for_all_platforms.sh && \
2733
mvn install -D skipTests --no-transfer-progress && \

utils/docker/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Docker build infra
2+
3+
This folder contains the infra to build the Docker images for Java. It's based on
4+
the upstream code located in [`microsoft/playwright/utils/docker`](https://github.com/microsoft/playwright/tree/main/utils/docker).

utils/docker/build.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -e
3+
set +x
4+
5+
if [[ ($1 == '--help') || ($1 == '-h') || ($1 == '') || ($2 == '') ]]; then
6+
echo "usage: $(basename $0) {--arm64,--amd64} {focal} playwright:localbuild-focal"
7+
echo
8+
echo "Build Playwright docker image and tag it as 'playwright:localbuild-focal'."
9+
echo "Once image is built, you can run it with"
10+
echo ""
11+
echo " docker run --rm -it playwright:localbuild-focal /bin/bash"
12+
echo ""
13+
echo "NOTE: this requires on Playwright PIP dependencies to be installed"
14+
echo ""
15+
exit 0
16+
fi
17+
18+
function cleanup() {
19+
:
20+
}
21+
22+
trap "cleanup; cd $(pwd -P)" EXIT
23+
cd "$(dirname "$0")"
24+
25+
PLATFORM=""
26+
if [[ "$1" == "--arm64" ]]; then
27+
PLATFORM="linux/arm64";
28+
elif [[ "$1" == "--amd64" ]]; then
29+
PLATFORM="linux/amd64"
30+
else
31+
echo "ERROR: unknown platform specifier - $1. Only --arm64 or --amd64 is supported"
32+
exit 1
33+
fi
34+
35+
docker build --platform "${PLATFORM}" -t "$3" -f "Dockerfile.$2" ../../

utils/docker/publish_docker.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set +x
5+
6+
trap "cd $(pwd -P)" EXIT
7+
cd "$(dirname "$0")"
8+
9+
MCR_IMAGE_NAME="playwright/java"
10+
# GITHUB_REF has a form of `refs/tags/v1.3.0`.
11+
# TAG_NAME would be `v1.3.0`
12+
TAG_NAME=${GITHUB_REF#refs/tags/}
13+
PW_VERSION="${TAG_NAME#v}"
14+
15+
RELEASE_CHANNEL="$1"
16+
if [[ "${RELEASE_CHANNEL}" == "stable" ]]; then
17+
if [[ ! "${PW_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]];
18+
echo "ERROR: cannot publish stable docker with Playwright version '${PW_VERSION}'"
19+
exit 1
20+
fi
21+
elif [[ "${RELEASE_CHANNEL}" == "canary" ]]; then
22+
23+
else
24+
echo "ERROR: unknown release channel - ${RELEASE_CHANNEL}"
25+
echo "Must be either 'stable' or 'canary'"
26+
exit 1
27+
fi
28+
29+
if [[ -z "${GITHUB_SHA}" ]]; then
30+
echo "ERROR: GITHUB_SHA env variable must be specified"
31+
exit 1
32+
fi
33+
34+
BIONIC_TAGS=(
35+
"next-bionic"
36+
"v${PW_VERSION}-bionic"
37+
)
38+
if [[ "$RELEASE_CHANNEL" == "stable" ]]; then
39+
BIONIC_TAGS+=("bionic")
40+
fi
41+
42+
FOCAL_TAGS=(
43+
"next"
44+
"sha-${GITHUB_SHA}"
45+
"next-focal"
46+
)
47+
48+
if [[ "$RELEASE_CHANNEL" == "stable" ]]; then
49+
FOCAL_TAGS+=("latest")
50+
FOCAL_TAGS+=("focal")
51+
FOCAL_TAGS+=("v${PW_VERSION}-focal")
52+
FOCAL_TAGS+=("v${PW_VERSION}")
53+
fi
54+
55+
tag_and_push() {
56+
local source="$1"
57+
local target="$2"
58+
echo "-- tagging: $target"
59+
docker tag $source $target
60+
docker push $target
61+
}
62+
63+
publish_docker_images_with_arch_suffix() {
64+
local FLAVOR="$1"
65+
local TAGS=()
66+
if [[ "$FLAVOR" == "bionic" ]]; then
67+
TAGS=("${BIONIC_TAGS[@]}")
68+
elif [[ "$FLAVOR" == "focal" ]]; then
69+
TAGS=("${FOCAL_TAGS[@]}")
70+
else
71+
echo "ERROR: unknown flavor - $FLAVOR. Must be either 'bionic' or 'focal'"
72+
exit 1
73+
fi
74+
local ARCH="$2"
75+
if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then
76+
echo "ERROR: unknown arch - $ARCH. Must be either 'amd64' or 'arm64'"
77+
exit 1
78+
fi
79+
# Prune docker images to avoid platform conflicts
80+
docker system prune -fa
81+
./build.sh "--${ARCH}" "${FLAVOR}" "${MCR_IMAGE_NAME}:localbuild"
82+
83+
for ((i = 0; i < ${#TAGS[@]}; i++)) do
84+
local TAG="${TAGS[$i]}"
85+
tag_and_push "${MCR_IMAGE_NAME}:localbuild" "playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}-${ARCH}"
86+
done
87+
}
88+
89+
publish_docker_manifest () {
90+
local FLAVOR="$1"
91+
local TAGS=()
92+
if [[ "$FLAVOR" == "bionic" ]]; then
93+
TAGS=("${BIONIC_TAGS[@]}")
94+
elif [[ "$FLAVOR" == "focal" ]]; then
95+
TAGS=("${FOCAL_TAGS[@]}")
96+
else
97+
echo "ERROR: unknown flavor - $FLAVOR. Must be either 'bionic' or 'focal'"
98+
exit 1
99+
fi
100+
101+
for ((i = 0; i < ${#TAGS[@]}; i++)) do
102+
local TAG="${TAGS[$i]}"
103+
local BASE_IMAGE_TAG="playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}"
104+
local IMAGE_NAMES=""
105+
if [[ "$2" == "arm64" || "$2" == "amd64" ]]; then
106+
IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$2"
107+
fi
108+
if [[ "$3" == "arm64" || "$3" == "amd64" ]]; then
109+
IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$3"
110+
fi
111+
docker manifest create "${BASE_IMAGE_TAG}" $IMAGE_NAMES
112+
docker manifest push "${BASE_IMAGE_TAG}"
113+
done
114+
}
115+
116+
publish_docker_images_with_arch_suffix focal amd64
117+
publish_docker_images_with_arch_suffix focal arm64
118+
publish_docker_manifest focal amd64 arm64

0 commit comments

Comments
 (0)