refactor: switch detected builder so first one wins

Also rename internal cnb references to pack (where possible).
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-02-28 16:19:41 -05:00
1 parent 43b9d9d4b6
commit 1ec71cd509
12 files changed
+59 -37

No files matched your search

+5 -1
View File
@@ -3,4 +3,8 @@
## Changes ## Changes
- The commands `proxy:enable`, `proxy:disable` and `proxy:build-config` now support the `--all` flag in addition to general parallelism. - The commands `proxy:enable`, `proxy:disable` and `proxy:build-config` now support the `--all` flag in addition to general parallelism.
- The `builder-cnb` plugin has been renamed `builder-pack` - The `builder-cnb` plugin has been renamed `builder-pack`, and all related plugin triggers have had the suffix `-cnb` changed to `-pack`.
## Deprecations
- The 1.0.0 release of Dokku will no longer select buildpack builders over dockerfile builders if both builders match. Instead, Dokku will choose the first builder that responds to the `builder-detect` trigger.
+13 -13
View File
@@ -157,7 +157,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"; SOURCECODE_WORK_DIR="$2" APP="$1"; SOURCECODE_WORK_DIR="$2"
if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then
echo -n "cnb" echo -n "pack"
fi fi
``` ```
@@ -1093,12 +1093,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# TODO # TODO
``` ```
### `post-build-cnb` ### `post-build-pack`
> Warning: The cnb plugin trigger apis are under development and may change > Warning: The pack plugin trigger apis are under development and may change
> between minor releases until the 1.0 release. > between minor releases until the 1.0 release.
- Description: Allows you to run commands after the build image is create for a given app. Only applies to apps using cnb. - Description: Allows you to run commands after the build image is create for a given app. Only applies to apps using pack.
- Invoked by: `internal function dokku_build() (build phase)` - Invoked by: `internal function dokku_build() (build phase)`
- Arguments: `$APP` `$SOURCECODE_WORK_DIR` - Arguments: `$APP` `$SOURCECODE_WORK_DIR`
- Example: - Example:
@@ -1326,14 +1326,14 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
# TODO # TODO
``` ```
### `post-release-cnb` ### `post-release-pack`
> Warning: The cnb plugin trigger apis are under development and may change > Warning: The pack plugin trigger apis are under development and may change
> between minor releases until the 1.0 release. > between minor releases until the 1.0 release.
> Warning: Image mutation in this trigger may result in an invalid run state, and is heavily discouraged. > Warning: Image mutation in this trigger may result in an invalid run state, and is heavily discouraged.
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to apps using cnb. - Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to apps using pack.
- Invoked by: `internal function dokku_release() (release phase)` - Invoked by: `internal function dokku_release() (release phase)`
- Arguments: `$APP $IMAGE_TAG` - Arguments: `$APP $IMAGE_TAG`
- Example: - Example:
@@ -1400,12 +1400,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# TODO # TODO
``` ```
### `pre-build-cnb` ### `pre-build-pack`
> Warning: The cnb plugin trigger apis are under development and may change > Warning: The pack plugin trigger apis are under development and may change
> between minor releases until the 1.0 release. > between minor releases until the 1.0 release.
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to apps using cnb. - Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to apps using pack.
- Invoked by: `internal function dokku_build() (build phase)` - Invoked by: `internal function dokku_build() (build phase)`
- Arguments: `$APP` `$SOURCECODE_WORK_DIR` - Arguments: `$APP` `$SOURCECODE_WORK_DIR`
- Example: - Example:
@@ -1557,12 +1557,12 @@ docker commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" $CID $IMAGE >/dev/null
``` ```
### `pre-release-cnb` ### `pre-release-pack`
> Warning: The cnb plugin trigger apis are under development and may change > Warning: The pack plugin trigger apis are under development and may change
> between minor releases until the 1.0 release. > between minor releases until the 1.0 release.
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to apps using cnb. - Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to apps using pack.
- Invoked by: `internal function dokku_release() (release phase)` - Invoked by: `internal function dokku_release() (release phase)`
- Arguments: `$APP $IMAGE_TAG` - Arguments: `$APP $IMAGE_TAG`
- Example: - Example:
+1 -1
View File
@@ -188,7 +188,7 @@ func executeScript(appName string, image string, imageTag string, phase string)
if isHerokuishImage { if isHerokuishImage {
imageSourceType = "herokuish" imageSourceType = "herokuish"
} else if isCnbImage { } else if isCnbImage {
imageSourceType = "cnb" imageSourceType = "pack"
} }
cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName)) cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName))
+18
View File
@@ -8,6 +8,24 @@ trigger-builder-dockerfile-builder-detect() {
declare trigger="builder-detect" declare trigger="builder-detect"
declare APP="$1" SOURCECODE_WORK_DIR="$2" declare APP="$1" SOURCECODE_WORK_DIR="$2"
# hack: unfortunately our legacy code requires that buildpacks
# are detected before dockerfile support is detected
# as such, we need to force-check the herokuish and pack
# builders before allowing the dockerfile check to succeed
# in a future release, we may drop this hack, but for now,
# such is life
if [[ -f "$PLUGIN_ENABLED_PATH/builder-herokuish/builder-detect" ]]; then
if [[ -n "$($PLUGIN_ENABLED_PATH/builder-herokuish/builder-detect "$APP" "$SOURCECODE_WORK_DIR")" ]]; then
return
fi
fi
if [[ -f "$PLUGIN_ENABLED_PATH/builder-pack/builder-detect" ]]; then
if [[ -n "$($PLUGIN_ENABLED_PATH/builder-pack/builder-detect "$APP" "$SOURCECODE_WORK_DIR")" ]]; then
return
fi
fi
if [[ -f "$SOURCECODE_WORK_DIR/Dockerfile" ]]; then if [[ -f "$SOURCECODE_WORK_DIR/Dockerfile" ]]; then
echo "dockerfile" echo "dockerfile"
return return
+3 -3
View File
@@ -9,7 +9,7 @@ trigger-builder-pack-builder-build() {
declare trigger="builder-build" declare trigger="builder-build"
declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3" declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3"
if [[ "$BUILDER_TYPE" != "cnb" ]]; then if [[ "$BUILDER_TYPE" != "pack" ]]; then
return return
fi fi
@@ -33,13 +33,13 @@ trigger-builder-pack-builder-build() {
config_export app "$APP" --format envfile --merged >"$TMP_FILE" config_export app "$APP" --format envfile --merged >"$TMP_FILE"
plugn trigger pre-build-cnb "$APP" "$SOURCECODE_WORK_DIR" plugn trigger pre-build-pack "$APP" "$SOURCECODE_WORK_DIR"
pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web
docker-image-labeler --label=com.dokku.image-stage=build --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE" docker-image-labeler --label=com.dokku.image-stage=build --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE"
plugn trigger post-build-cnb "$APP" "$SOURCECODE_WORK_DIR" plugn trigger post-build-pack "$APP" "$SOURCECODE_WORK_DIR"
} }
trigger-builder-pack-builder-build "$@" trigger-builder-pack-builder-build "$@"
+2 -2
View File
@@ -9,12 +9,12 @@ trigger-builder-pack-builder-detect() {
declare APP="$1" SOURCECODE_WORK_DIR="$2" declare APP="$1" SOURCECODE_WORK_DIR="$2"
if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then
echo "cnb" echo "pack"
return return
fi fi
if [[ "$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)" == "1" ]]; then if [[ "$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)" == "1" ]]; then
echo "cnb" echo "pack"
return return
fi fi
} }
+3 -3
View File
@@ -8,15 +8,15 @@ trigger-builder-pack-builder-release() {
declare trigger="builder-release" declare trigger="builder-release"
declare BUILDER_TYPE="$1" APP="$2" IMAGE_TAG="$3" declare BUILDER_TYPE="$1" APP="$2" IMAGE_TAG="$3"
if [[ "$BUILDER_TYPE" != "cnb" ]]; then if [[ "$BUILDER_TYPE" != "pack" ]]; then
return return
fi fi
plugn trigger pre-release-cnb "$APP" "$IMAGE_TAG" plugn trigger pre-release-pack "$APP" "$IMAGE_TAG"
local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
docker-image-labeler --label=com.dokku.image-stage=release --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE" docker-image-labeler --label=com.dokku.image-stage=release --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE"
plugn trigger post-release-cnb "$APP" "$IMAGE_TAG" plugn trigger post-release-pack "$APP" "$IMAGE_TAG"
} }
trigger-builder-pack-builder-release "$@" trigger-builder-pack-builder-release "$@"
+2 -2
View File
@@ -639,7 +639,7 @@ dokku_release() {
local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
if is_image_cnb_based "$IMAGE"; then if is_image_cnb_based "$IMAGE"; then
IMAGE_SOURCE_TYPE="cnb" IMAGE_SOURCE_TYPE="pack"
fi fi
plugn trigger builder-release "$IMAGE_SOURCE_TYPE" "$APP" "$IMAGE_TAG" plugn trigger builder-release "$IMAGE_SOURCE_TYPE" "$APP" "$IMAGE_TAG"
@@ -710,7 +710,7 @@ dokku_receive() {
local DOKKU_CNB_EXPERIMENTAL="$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)" local DOKKU_CNB_EXPERIMENTAL="$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)"
if [[ "$DOKKU_CNB_EXPERIMENTAL" == "1" ]]; then if [[ "$DOKKU_CNB_EXPERIMENTAL" == "1" ]]; then
IMAGE_SOURCE_TYPE="cnb" IMAGE_SOURCE_TYPE="pack"
fi fi
DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE"
+1 -1
View File
@@ -53,7 +53,7 @@ git_trigger_build() {
plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV" plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV"
BUILDER="$(plugn trigger builder-detect "$APP" "$TMP_WORK_DIR" | tail -n1 || true)" BUILDER="$(plugn trigger builder-detect "$APP" "$TMP_WORK_DIR" | head -n1 || true)"
[[ -z "$BUILDER" ]] && BUILDER="herokuish" [[ -z "$BUILDER" ]] && BUILDER="herokuish"
plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV" plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV"
@@ -28,7 +28,7 @@ trigger-scheduler-docker-local-scheduler-deploy() {
is_image_herokuish_based "$IMAGE" "$APP" && DOKKU_HEROKUISH=true is_image_herokuish_based "$IMAGE" "$APP" && DOKKU_HEROKUISH=true
local IMAGE_SOURCE_TYPE="dockerfile" local IMAGE_SOURCE_TYPE="dockerfile"
[[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish" [[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish"
[[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="cnb" [[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="pack"
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
local oldids=$(get_app_container_ids "$APP") local oldids=$(get_app_container_ids "$APP")
+1 -1
View File
@@ -45,7 +45,7 @@ tar_trigger_build() {
plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV" plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV"
BUILDER="$(plugn trigger builder-detect "$APP" "$TMP_WORK_DIR" | tail -n1 || true)" BUILDER="$(plugn trigger builder-detect "$APP" "$TMP_WORK_DIR" | head -n1 || true)"
[[ -z "$BUILDER" ]] && BUILDER="herokuish" [[ -z "$BUILDER" ]] && BUILDER="herokuish"
plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV" plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV"
+9 -9
View File
@@ -10,7 +10,7 @@ teardown() {
destroy_app destroy_app
} }
@test "(builder) builder-detect [cnb]" { @test "(builder) builder-detect [pack]" {
local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX") local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX")
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM
@@ -21,11 +21,11 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output "cnb" assert_output "pack"
sudo rm -rf $TMP/* sudo rm -rf $TMP/*
echo "output: $output" echo "output: $output"
@@ -39,11 +39,11 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
assert_output "cnb" assert_output "pack"
} }
@test "(builder) builder-detect [dockerfile]" { @test "(builder) builder-detect [dockerfile]" {
@@ -56,7 +56,7 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
@@ -77,7 +77,7 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
@@ -95,7 +95,7 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
@@ -113,7 +113,7 @@ teardown() {
assert_success assert_success
chown -R dokku:dokku "$TMP" chown -R dokku:dokku "$TMP"
run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | tail -n1" run /bin/bash -c "dokku plugin:trigger builder-detect $TEST_APP $TMP | head -n1"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success