While this will require future updates if pack supports new build arguments, it also ensures builds safely consume arguments from other plugins.
200 lines
6.3 KiB
Bash
Executable File
200 lines
6.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
trigger-builder-pack-builder-build() {
|
|
declare desc="builder-pack builder-build plugin trigger"
|
|
declare trigger="builder-build"
|
|
declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3"
|
|
|
|
if [[ "$BUILDER_TYPE" != "pack" ]]; then
|
|
return
|
|
fi
|
|
|
|
local stack="$(plugn trigger buildpack-stack-name "$APP")"
|
|
if [[ -n "$stack" ]]; then
|
|
DOKKU_CNB_BUILDER="$stack"
|
|
fi
|
|
|
|
dokku_log_info1 "Building $APP from cnb stack $DOKKU_CNB_BUILDER..."
|
|
|
|
if ! command -v "pack" &>/dev/null; then
|
|
dokku_log_fail "Missing pack, install it"
|
|
fi
|
|
|
|
local IMAGE=$(get_app_image_name "$APP")
|
|
|
|
pushd "$SOURCECODE_WORK_DIR" &>/dev/null
|
|
|
|
ENV_ARGS=($(config_export app "$APP" --format pack-keys --merged))
|
|
eval "$(config_export app "$APP" --merged)"
|
|
|
|
if fn-plugn-trigger-exists "pre-build-pack"; then
|
|
dokku_log_warn "Deprecated: please upgrade plugin to use 'pre-build' plugin trigger instead of pre-build-pack"
|
|
plugn trigger pre-build-pack "$APP" "$SOURCECODE_WORK_DIR"
|
|
fi
|
|
plugn trigger pre-build "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR"
|
|
|
|
local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$BUILDER_TYPE")
|
|
[[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" --env=TRACE=true "
|
|
DOCKER_ARGS+=$(: | plugn trigger docker-args-process-build "$APP" "$BUILDER_TYPE")
|
|
|
|
DOCKER_ARGS=" $DOCKER_ARGS "
|
|
declare -a ARG_ARRAY
|
|
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
|
|
|
eval set -- "$DOCKER_ARGS"
|
|
|
|
declare -a PACK_ARGS
|
|
while true; do
|
|
case "$1" in
|
|
-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")
|
|
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
|
|
;;
|
|
*)
|
|
continue
|
|
;;
|
|
esac
|
|
done
|
|
|
|
pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web "${PACK_ARGS[@]}" "${ENV_ARGS[@]}"
|
|
docker-image-labeler relabel --label=dokku --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.image-stage=build --label=com.dokku.builder-type=pack --label=com.dokku.app-name=$APP "$IMAGE"
|
|
|
|
# ensure we have a port mapping
|
|
plugn trigger ports-configure "$APP"
|
|
plugn trigger ports-set-detected "$APP" "http:$(plugn trigger ports-get-property "$APP" proxy-port):5000"
|
|
|
|
if fn-plugn-trigger-exists "post-build-pack"; then
|
|
dokku_log_warn "Deprecated: please upgrade plugin to use 'post-build' plugin trigger instead of post-build-pack"
|
|
plugn trigger post-build-pack "$APP" "$SOURCECODE_WORK_DIR"
|
|
fi
|
|
plugn trigger post-build "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR"
|
|
}
|
|
|
|
trigger-builder-pack-builder-build "$@"
|