initial commit
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -u
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
|
||||
Environment-backed options (CLI flags are optional):
|
||||
--owner VALUE (default: \$IMAGE_LABEL_OWNER)
|
||||
--repository VALUE (default: \$IMAGE_LABEL_REPO)
|
||||
--slug VALUE (default: catthehacker/ubuntu)
|
||||
--tags TAG [TAG ...] Multiple destination tags
|
||||
--tag TAG Single destination tag
|
||||
--node VALUE (default: \$NODE)
|
||||
--distro VALUE (default: ubuntu)
|
||||
--type VALUE (default: \$TYPE)
|
||||
--runner VALUE (default: \$RUNNER)
|
||||
--platforms CSV (default: \$PLATFORMS, comma-separated)
|
||||
--build-tag VALUE (default: \$BUILD_TAG)
|
||||
--build-tag-version VAL (default: \$BUILD_TAG_VERSION)
|
||||
--build-ref VALUE (default: \$BUILD_REF)
|
||||
--from-image VALUE (default: \$FROM_IMAGE)
|
||||
--from-tag VALUE (default: \$FROM_TAG)
|
||||
--push Push manifest to remote registries
|
||||
-h, --help Show this help and exit
|
||||
EOF
|
||||
}
|
||||
|
||||
# Defaults from environment (mirrors build.ps1 parameter defaults), with safe fallbacks
|
||||
owner=${IMAGE_LABEL_OWNER:-actions}
|
||||
repository=${IMAGE_LABEL_REPO:-ubuntu}
|
||||
tags=""
|
||||
tag=""
|
||||
node=${NODE:-"20 24"}
|
||||
distro='ubuntu'
|
||||
type=${TYPE:-act}
|
||||
runner=${RUNNER:-root}
|
||||
platforms=${PLATFORMS:-linux/amd64,linux/arm64}
|
||||
build_tag=${BUILD_TAG:-act-24.04}
|
||||
build_tag_version=${BUILD_TAG_VERSION:-dev}
|
||||
build_ref=${BUILD_REF:-local}
|
||||
from_image=${FROM_IMAGE:-buildpack-deps}
|
||||
from_tag=${FROM_TAG:-24.04}
|
||||
push=false
|
||||
|
||||
# Argument parsing (simple long options, designed to be close to build.ps1 semantics)
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--owner)
|
||||
owner=$2
|
||||
shift 2
|
||||
;;
|
||||
--repository)
|
||||
repository=$2
|
||||
shift 2
|
||||
;;
|
||||
--tags)
|
||||
shift
|
||||
# Collect all following non-option arguments as tags
|
||||
while [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; do
|
||||
if [ -z "$tags" ]; then
|
||||
tags=$1
|
||||
else
|
||||
tags="$tags $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
;;
|
||||
--tag)
|
||||
tag=$2
|
||||
shift 2
|
||||
;;
|
||||
--node)
|
||||
node=$2
|
||||
shift 2
|
||||
;;
|
||||
--distro)
|
||||
distro=$2
|
||||
shift 2
|
||||
;;
|
||||
--type)
|
||||
type=$2
|
||||
shift 2
|
||||
;;
|
||||
--runner)
|
||||
runner=$2
|
||||
shift 2
|
||||
;;
|
||||
--platforms)
|
||||
platforms=$2
|
||||
shift 2
|
||||
;;
|
||||
--build-tag)
|
||||
build_tag=$2
|
||||
shift 2
|
||||
;;
|
||||
--build-tag-version)
|
||||
build_tag_version=$2
|
||||
shift 2
|
||||
;;
|
||||
--build-ref)
|
||||
build_ref=$2
|
||||
shift 2
|
||||
;;
|
||||
--from-image)
|
||||
from_image=$2
|
||||
shift 2
|
||||
;;
|
||||
--from-tag)
|
||||
from_tag=$2
|
||||
shift 2
|
||||
;;
|
||||
--push)
|
||||
push=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
printf 'Unknown argument: %s\n' "$1" >&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 "$@"
|
||||
|
||||
Reference in New Issue
Block a user