Files
dokku/plugins/builder-pack/builder-build
Jose Diaz-Gonzalez 4bc3de5540 feat: write auto-detected port mappings during a deploy
During an app build, we now auto-detect ports based on the source code. This is usually http:80:5000, with Dockerfile-based deploys having their ports extracted from the docker image or Dockerfile. Additionally, we add an https:443 mapping for any detected http:80 mapping when there is an ssl certificate, and all http port mappings are transformed to https mappings for Dockerfile-based deploys.

While the ports aren't currently consumed, a future refactor will provide the ability to fallback to the new detected ports when there is no user-specified port mapping.
2023-08-05 10:58:57 -04:00

43 lines
1.5 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 (experimental)..."
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)"
plugn trigger pre-build-pack "$APP" "$SOURCECODE_WORK_DIR"
pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web "${ENV_ARGS[@]}"
docker-image-labeler --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"
plugn trigger ports-set-detected "$APP" "http:80:5000"
plugn trigger post-build-pack "$APP" "$SOURCECODE_WORK_DIR"
}
trigger-builder-pack-builder-build "$@"