|
| 1 | +#!/usr/bin/env 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/mcp" |
| 10 | + |
| 11 | +RELEASE_CHANNEL="$1" |
| 12 | +if [[ "${RELEASE_CHANNEL}" != "stable" && "${RELEASE_CHANNEL}" != "canary" ]]; then |
| 13 | + echo "ERROR: unknown release channel - '${RELEASE_CHANNEL}'" |
| 14 | + echo "Must be either 'stable' or 'canary'" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +MCP_VERSION=$(node -p "require('../../package.json').version") |
| 19 | +if [[ "${RELEASE_CHANNEL}" == "stable" && ! "${MCP_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 20 | + echo "ERROR: cannot publish stable docker with @playwright/mcp version '${MCP_VERSION}'" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +TAGS=() |
| 25 | +if [[ "${RELEASE_CHANNEL}" == "stable" ]]; then |
| 26 | + TAGS+=("v${MCP_VERSION}" "latest") |
| 27 | +else |
| 28 | + TAGS+=("v${MCP_VERSION}-canary-$(date -u +'%Y%m%d%H%M%S')") |
| 29 | + echo "== CANARY build: publishing to ${TAGS[0]} tag ==" |
| 30 | +fi |
| 31 | + |
| 32 | +tag_and_push() { |
| 33 | + local source="$1" |
| 34 | + local target="$2" |
| 35 | + echo "-- tagging: $target" |
| 36 | + docker tag $source $target |
| 37 | + docker push $target |
| 38 | + attach_eol_manifest $target |
| 39 | +} |
| 40 | + |
| 41 | +attach_eol_manifest() { |
| 42 | + local image="$1" |
| 43 | + local today=$(date -u +'%Y-%m-%d') |
| 44 | + install_oras_if_needed |
| 45 | + # oras is re-using Docker credentials, so we don't need to login. |
| 46 | + # Following the advice in https://portal.microsofticm.com/imp/v3/incidents/incident/476783820/summary |
| 47 | + ./oras/oras attach --artifact-type application/vnd.microsoft.artifact.lifecycle --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$today" $image |
| 48 | +} |
| 49 | + |
| 50 | +install_oras_if_needed() { |
| 51 | + if [[ -x oras/oras ]]; then |
| 52 | + return |
| 53 | + fi |
| 54 | + local version="1.1.0" |
| 55 | + local arch="amd64" |
| 56 | + if [[ "$(uname -m)" == "aarch64" || "$(uname -m)" == "arm64" ]]; then |
| 57 | + arch="arm64" |
| 58 | + fi |
| 59 | + curl -sLO "https://github.com/oras-project/oras/releases/download/v${version}/oras_${version}_linux_${arch}.tar.gz" |
| 60 | + mkdir -p oras |
| 61 | + tar -zxf oras_${version}_linux_${arch}.tar.gz -C oras |
| 62 | + rm oras_${version}_linux_${arch}.tar.gz |
| 63 | +} |
| 64 | + |
| 65 | +publish_docker_images_with_arch_suffix() { |
| 66 | + local ARCH="$1" |
| 67 | + if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then |
| 68 | + echo "ERROR: unknown arch - $ARCH. Must be either 'amd64' or 'arm64'" |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + # Prune docker images to avoid platform conflicts |
| 72 | + docker system prune -fa |
| 73 | + ./build.sh "--${ARCH}" playwright-mcp:localbuild |
| 74 | + |
| 75 | + for ((i = 0; i < ${#TAGS[@]}; i++)) do |
| 76 | + local TAG="${TAGS[$i]}" |
| 77 | + tag_and_push playwright-mcp:localbuild "playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}-${ARCH}" |
| 78 | + done |
| 79 | +} |
| 80 | + |
| 81 | +publish_docker_manifest () { |
| 82 | + for ((i = 0; i < ${#TAGS[@]}; i++)) do |
| 83 | + local TAG="${TAGS[$i]}" |
| 84 | + local BASE_IMAGE_TAG="playwright.azurecr.io/public/${MCR_IMAGE_NAME}:${TAG}" |
| 85 | + local IMAGE_NAMES="" |
| 86 | + if [[ "$1" == "arm64" || "$1" == "amd64" ]]; then |
| 87 | + IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$1" |
| 88 | + fi |
| 89 | + if [[ "$2" == "arm64" || "$2" == "amd64" ]]; then |
| 90 | + IMAGE_NAMES="${IMAGE_NAMES} ${BASE_IMAGE_TAG}-$2" |
| 91 | + fi |
| 92 | + docker manifest create "${BASE_IMAGE_TAG}" $IMAGE_NAMES |
| 93 | + docker manifest push "${BASE_IMAGE_TAG}" |
| 94 | + attach_eol_manifest "${BASE_IMAGE_TAG}" |
| 95 | + done |
| 96 | +} |
| 97 | + |
| 98 | +# arm64 first: its QEMU-emulated build must run while the host is fresh. Running |
| 99 | +# it after the native amd64 build has churned the host triggers a qemu segfault |
| 100 | +# in aarch64 ldconfig during libc-bin setup. amd64 is a native build and is |
| 101 | +# unaffected by preceding work, so it goes second. |
| 102 | +publish_docker_images_with_arch_suffix arm64 |
| 103 | +publish_docker_images_with_arch_suffix amd64 |
| 104 | +publish_docker_manifest amd64 arm64 |
0 commit comments