feat: filter out unsupported build arguments with pack

While this will require future updates if pack supports new build arguments, it also ensures builds safely consume arguments from other plugins.
This commit is contained in:
Jose Diaz-Gonzalez
2025-11-15 20:28:13 -05:00
parent 43f25c218f
commit 97714e9c22

View File

@@ -50,17 +50,134 @@ trigger-builder-pack-builder-build() {
declare -a PACK_ARGS
while true; do
case "$1" in
--volume=* | -v=*)
-B | --builder)
PACK_ARGS+=("--builder")
PACK_ARGS+=("$2")
shift 2
;;
-b | --buildpack)
PACK_ARGS+=("--buildpack")
PACK_ARGS+=("$2")
shift 2
;;
-r | --buildpack-registry)
PACK_ARGS+=("--buildpack-registry")
PACK_ARGS+=("$2")
shift 2
;;
-D | --default-process)
PACK_ARGS+=("--default-process")
PACK_ARGS+=("$2")
shift 2
;;
-d | --descriptor)
PACK_ARGS+=("--descriptor")
PACK_ARGS+=("$2")
shift 2
;;
-e | --env)
PACK_ARGS+=("--env")
PACK_ARGS+=("$2")
shift 2
;;
-p | --path)
PACK_ARGS+=("--path")
PACK_ARGS+=("$2")
shift 2
;;
-t | --tag)
PACK_ARGS+=("--tag")
PACK_ARGS+=("$2")
shift 2
;;
--cache | --cache-image | --creation-time | --docker-host | --env-file | --extension | --gid | --insecure-registry | --lifecycle-image | --network | --platform | --post-buildpack | --pre-buildpack | --previous-image | --pull-policy | --report-output-dir | --run-image | --sbom-output-dir | --uid | --workspace)
PACK_ARGS+=("$1")
shift
PACK_ARGS+=("$2")
shift 2
;;
--clear-cache | --disable-system-buildpacks | --publish | --trust-builder | --trust-extra-buildpacks | --userns-host)
PACK_ARGS+=("$1")
shift 1
;;
--volume | -v)
PACK_ARGS+=("--volume")
PACK_ARGS+=("$2")
shift 2
;;
-B=* | --builder=*)
if [[ "$1" == "--builder=*" ]]; then
PACK_ARGS+=("--builder" "${1#--builder=}")
elif [[ "$1" == "-B=*" ]]; then
PACK_ARGS+=("--builder" "${1#-B=}")
fi
shift 1
;;
-b=* | --buildpack=*)
if [[ "$1" == "--buildpack=*" ]]; then
PACK_ARGS+=("--buildpack" "${1#--buildpack=}")
elif [[ "$1" == "-b=*" ]]; then
PACK_ARGS+=("--buildpack" "${1#-b=}")
fi
shift 1
;;
-r=* | --buildpack-registry=*)
if [[ "$1" == "--buildpack-registry=*" ]]; then
PACK_ARGS+=("--buildpack-registry" "${1#--buildpack-registry=}")
elif [[ "$1" == "-r=*" ]]; then
PACK_ARGS+=("--buildpack-registry" "${1#-r=}")
fi
shift 2
;;
-D=* | --default-process=*)
if [[ "$1" == "--default-process=*" ]]; then
PACK_ARGS+=("--default-process" "${1#--default-process=}")
elif [[ "$1" == "-D=*" ]]; then
PACK_ARGS+=("--default-process" "${1#-D=}")
fi
shift 1
;;
-d=* | --descriptor=*)
if [[ "$1" == "--descriptor=*" ]]; then
PACK_ARGS+=("--descriptor" "${1#--descriptor=}")
elif [[ "$1" == "-d=*" ]]; then
PACK_ARGS+=("--descriptor" "${1#-d=}")
fi
shift 1
;;
-e=* | --env=*)
if [[ "$1" == "--env=*" ]]; then
PACK_ARGS+=("--env" "${1#--env=}")
elif [[ "$1" == "-e=*" ]]; then
PACK_ARGS+=("--env" "${1#-e=}")
fi
shift 1
;;
-p=* | --path=*)
if [[ "$1" == "--path=*" ]]; then
PACK_ARGS+=("--path" "${1#--path=}")
elif [[ "$1" == "-p=*" ]]; then
PACK_ARGS+=("--path" "${1#-p=}")
fi
shift 1
;;
-t=* | --tag=*)
if [[ "$1" == "--tag=*" ]]; then
PACK_ARGS+=("--tag" "${1#--tag=}")
elif [[ "$1" == "-t=*" ]]; then
PACK_ARGS+=("--tag" "${1#-t=}")
fi
shift 1
;;
--volume=* | -v=*)
if [[ "$1" == "--volume=*" ]]; then
PACK_ARGS+=("--volume" "${1#--volume=}")
elif [[ "$1" == "-v=*" ]]; then
PACK_ARGS+=("--volume" "${1#-v=}")
fi
shift 1
;;
*)
break
continue
;;
esac
done