2019-07-30 14:29:48 -04:00
|
|
|
#!/usr/bin/env bash
|
2021-03-21 21:43:53 -04:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
|
|
|
|
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/internal-functions"
|
2019-07-30 14:29:48 -04:00
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
|
|
2020-02-10 02:40:59 -05:00
|
|
|
trigger-builder-dockerfile-builder-build() {
|
2019-07-30 14:29:48 -04:00
|
|
|
declare desc="builder-dockerfile builder-build plugin trigger"
|
2020-02-10 02:40:59 -05:00
|
|
|
declare trigger="builder-build"
|
2019-07-30 14:29:48 -04:00
|
|
|
declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3"
|
|
|
|
|
|
|
|
|
|
if [[ "$BUILDER_TYPE" != "dockerfile" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
2021-01-23 17:38:20 -05:00
|
|
|
dokku_log_info1 "Building $APP from Dockerfile"
|
|
|
|
|
|
2019-07-30 14:29:48 -04:00
|
|
|
local IMAGE=$(get_app_image_name "$APP")
|
2022-07-04 23:41:39 -04:00
|
|
|
local DOCKER_BUILD_LABEL_ARGS=("--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=dockerfile" "--label=com.dokku.app-name=$APP")
|
2019-07-30 14:29:48 -04:00
|
|
|
|
|
|
|
|
pushd "$SOURCECODE_WORK_DIR" &>/dev/null
|
|
|
|
|
|
2024-09-22 20:16:19 -04:00
|
|
|
if [[ ! -f "$SOURCECODE_WORK_DIR/Dockerfile" ]]; then
|
|
|
|
|
dokku_log_fail "No Dockerfile found in source code directory"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-08-19 12:08:44 -04:00
|
|
|
if fn-plugn-trigger-exists "pre-build-dockerfile"; then
|
|
|
|
|
dokku_log_warn "Deprecated: please upgrade plugin to use 'pre-build' plugin trigger instead of pre-build-dockerfile"
|
|
|
|
|
plugn trigger pre-build-dockerfile "$APP"
|
|
|
|
|
fi
|
|
|
|
|
plugn trigger pre-build "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR"
|
2019-07-30 14:29:48 -04:00
|
|
|
|
|
|
|
|
local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$BUILDER_TYPE")
|
2020-02-01 16:17:59 -08:00
|
|
|
DOCKER_ARGS+=$(: | plugn trigger docker-args-process-build "$APP" "$BUILDER_TYPE")
|
2025-11-15 23:17:48 -05:00
|
|
|
DOCKER_ARGS+=" $DOKKU_GLOBAL_BUILD_ARGS"
|
2019-07-30 14:29:48 -04:00
|
|
|
|
2025-11-15 23:17:48 -05:00
|
|
|
DOCKER_ARGS=" $DOCKER_ARGS "
|
|
|
|
|
eval set -- "$DOCKER_ARGS"
|
|
|
|
|
|
|
|
|
|
declare -a DOCKERFILE_ARGS
|
|
|
|
|
while true; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--add-host)
|
|
|
|
|
DOCKERFILE_ARGS+=("--add-host")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--add-host=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--add-host" "${1#--add-host=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--allow)
|
|
|
|
|
DOCKERFILE_ARGS+=("--allow")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--allow=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--allow" "${1#--allow=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--annotation)
|
|
|
|
|
DOCKERFILE_ARGS+=("--annotation")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--annotation=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--annotation" "${1#--annotation=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--attest)
|
|
|
|
|
DOCKERFILE_ARGS+=("--attest")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--attest=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--attest" "${1#--attest=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--build-arg)
|
|
|
|
|
DOCKERFILE_ARGS+=("--build-arg")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--build-arg=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--build-arg" "${1#--build-arg=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--builder)
|
|
|
|
|
DOCKERFILE_ARGS+=("--builder")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--builder=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--builder" "${1#--builder=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--cache-from)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cache-from")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--cache-from=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cache-from" "${1#--cache-from=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--cache-to)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cache-to")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--cache-to=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cache-to" "${1#--cache-to=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--call)
|
2025-11-16 01:10:15 -05:00
|
|
|
DOCKERFILE_ARGS+=("--call")
|
2025-11-15 23:17:48 -05:00
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
2025-11-16 01:10:15 -05:00
|
|
|
--call=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--call" "${1#--call=}")
|
2025-11-15 23:17:48 -05:00
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--cgroup-parent)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cgroup-parent")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--cgroup-parent=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--cgroup-parent" "${1#--cgroup-parent=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--label)
|
|
|
|
|
DOCKERFILE_ARGS+=("--label")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--label=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--label" "${1#--label=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--network)
|
|
|
|
|
DOCKERFILE_ARGS+=("--network")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--network=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--network" "${1#--network=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--platform)
|
|
|
|
|
DOCKERFILE_ARGS+=("--platform")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--platform=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--platform" "${1#--platform=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--progress)
|
|
|
|
|
DOCKERFILE_ARGS+=("--progress")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--progress=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--progress" "${1#--progress=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--provenance)
|
|
|
|
|
DOCKERFILE_ARGS+=("--provenance")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--provenance=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--provenance" "${1#--provenance=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--sbom)
|
|
|
|
|
DOCKERFILE_ARGS+=("--sbom")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--sbom=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--sbom" "${1#--sbom=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--secret)
|
|
|
|
|
DOCKERFILE_ARGS+=("--secret")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--secret=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--secret" "${1#--secret=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--shm-size)
|
|
|
|
|
DOCKERFILE_ARGS+=("--shm-size")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--shm-size=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--shm-size" "${1#--shm-size=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--ssh)
|
|
|
|
|
DOCKERFILE_ARGS+=("--platform")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--ssh=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--ssh" "${1#--ssh=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--target)
|
|
|
|
|
DOCKERFILE_ARGS+=("--target")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--target=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--target" "${1#--target=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--ulimit)
|
|
|
|
|
DOCKERFILE_ARGS+=("--tag")
|
|
|
|
|
DOCKERFILE_ARGS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--tag=*)
|
|
|
|
|
DOCKERFILE_ARGS+=("--tag" "${1#--tag=}")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
--check | -D | --debug | --no-cache)
|
|
|
|
|
DOCKERFILE_ARGS+=("$1")
|
|
|
|
|
shift 1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
2025-11-16 01:24:28 -05:00
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
|
shift
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
break
|
2025-11-15 23:17:48 -05:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2019-07-30 14:29:48 -04:00
|
|
|
|
2023-07-01 06:45:21 -04:00
|
|
|
eval "$(config_export app "$APP")"
|
2025-11-15 23:28:44 -05:00
|
|
|
"$DOCKER_BIN" image build "${DOCKER_BUILD_LABEL_ARGS[@]}" "${DOCKERFILE_ARGS[@]}" --tag $IMAGE .
|
2019-07-30 14:29:48 -04:00
|
|
|
|
2023-07-16 03:35:40 -04:00
|
|
|
plugn trigger ports-set-detected "$APP" "$(fn-builder-dockerfile-get-detect-port-map "$APP" "$IMAGE" "$SOURCECODE_WORK_DIR/Dockerfile")"
|
2023-08-19 12:13:40 -04:00
|
|
|
if fn-plugn-trigger-exists "post-build-dockerfile"; then
|
|
|
|
|
dokku_log_warn "Deprecated: please upgrade plugin to use 'post-build' plugin trigger instead of post-build-dockerfile"
|
|
|
|
|
plugn trigger post-build-dockerfile "$APP"
|
|
|
|
|
fi
|
|
|
|
|
plugn trigger post-build "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR"
|
2019-07-30 14:29:48 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 02:40:59 -05:00
|
|
|
trigger-builder-dockerfile-builder-build "$@"
|