#!/usr/bin/env sh set -u usage() { cat <&2 usage exit 1 ;; esac done # Helper to run a command and fail with a useful message (equivalent to exec in build.ps1) exec_cmd() { if ! "$@"; then status=$? printf '%s failed with exit code %s\n' "$*" "$status" >&2 exit "$status" fi } if [ -z "$platforms" ]; then printf 'Error: PLATFORMS is empty. Set PLATFORMS or pass --platforms.\n' >&2 exit 1 fi if [ -z "$from_image" ] || [ -z "$from_tag" ]; then printf 'Error: FROM_IMAGE/FROM_TAG are empty. Set env vars or pass --from-image/--from-tag.\n' >&2 exit 1 fi if [ "$push" = true ]; then # Combine tags and tag (if provided) all_tags=$tags if [ -n "$tag" ]; then if [ -z "$all_tags" ]; then all_tags=$tag else all_tags="$all_tags $tag" fi fi else # Even when not pushing, honor --tag so the local image is named. all_tags=$tags if [ -n "$tag" ]; then if [ -z "$all_tags" ]; then all_tags=$tag else all_tags="$all_tags $tag" fi fi fi # Buildx expects comma-separated --platform list; reuse platforms as-is. tag_args="" for t in $all_tags; do tag_args="$tag_args -t $t" done build_date=$(date -u +"%Y-%m-%d %H:%M:%SZ") # Build argument vector to preserve spacing/quoting (e.g. NODE_VERSION="20 24") set -- docker buildx build \ --ulimit "nofile=4096:4096" \ --platform "$platforms" \ --build-arg "TARGETARCH=\$TARGETARCH" \ --build-arg "NODE_VERSION=$node" \ --build-arg "DISTRO=$distro" \ --build-arg "TYPE=$type" \ --build-arg "RUNNER=$runner" \ --build-arg "BUILD_DATE=$build_date" \ --build-arg "BUILD_OWNER=$owner" \ --build-arg "BUILD_OWNER_MAIL=$owner" \ --build-arg "BUILD_REPO=$repository" \ --build-arg "BUILD_TAG=$build_tag" \ --build-arg "BUILD_TAG_VERSION=$build_tag_version" \ --build-arg "BUILD_REF=$build_ref" \ --build-arg "FROM_IMAGE=$from_image" \ --build-arg "FROM_TAG=$from_tag" \ --file "./Dockerfile" # Append tag flags # shellcheck disable=SC2086 set -- "$@" $tag_args # Append push/load and final PATH argument if [ "$push" = true ]; then set -- "$@" --push . else set -- "$@" --load . fi exec_cmd "$@"