From 1ec71cd509b5f59532ab0fc945d5210387311d99 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 28 Feb 2021 16:02:22 -0500 Subject: [PATCH] refactor: switch detected builder so first one wins Also rename internal cnb references to pack (where possible). --- docs/appendices/0.24.0-migration-guide.md | 6 ++++- docs/development/plugin-triggers.md | 26 +++++++++---------- plugins/app-json/functions.go | 2 +- plugins/builder-dockerfile/builder-detect | 18 +++++++++++++ plugins/builder-pack/builder-build | 6 ++--- plugins/builder-pack/builder-detect | 4 +-- plugins/builder-pack/builder-release | 6 ++--- plugins/common/functions | 4 +-- plugins/git/functions | 2 +- .../scheduler-docker-local/scheduler-deploy | 2 +- plugins/tar/functions | 2 +- tests/unit/builder.bats | 18 ++++++------- 12 files changed, 59 insertions(+), 37 deletions(-) diff --git a/docs/appendices/0.24.0-migration-guide.md b/docs/appendices/0.24.0-migration-guide.md index f55d81c2f..fb104995d 100644 --- a/docs/appendices/0.24.0-migration-guide.md +++ b/docs/appendices/0.24.0-migration-guide.md @@ -3,4 +3,8 @@ ## Changes - 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. diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index fa8505b9b..da4ac32ef 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -157,7 +157,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x APP="$1"; SOURCECODE_WORK_DIR="$2" if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then - echo -n "cnb" + echo -n "pack" fi ``` @@ -1093,12 +1093,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # 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. -- 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)` - Arguments: `$APP` `$SOURCECODE_WORK_DIR` - Example: @@ -1326,14 +1326,14 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) # 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. > 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)` - Arguments: `$APP $IMAGE_TAG` - Example: @@ -1400,12 +1400,12 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # 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. -- 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)` - Arguments: `$APP` `$SOURCECODE_WORK_DIR` - 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. -- 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)` - Arguments: `$APP $IMAGE_TAG` - Example: diff --git a/plugins/app-json/functions.go b/plugins/app-json/functions.go index e70c5f281..65bc8bd3a 100644 --- a/plugins/app-json/functions.go +++ b/plugins/app-json/functions.go @@ -188,7 +188,7 @@ func executeScript(appName string, image string, imageTag string, phase string) if isHerokuishImage { imageSourceType = "herokuish" } else if isCnbImage { - imageSourceType = "cnb" + imageSourceType = "pack" } cacheDir := fmt.Sprintf("%s/cache", common.AppRoot(appName)) diff --git a/plugins/builder-dockerfile/builder-detect b/plugins/builder-dockerfile/builder-detect index d14de16aa..43cd9fcdb 100755 --- a/plugins/builder-dockerfile/builder-detect +++ b/plugins/builder-dockerfile/builder-detect @@ -8,6 +8,24 @@ trigger-builder-dockerfile-builder-detect() { declare trigger="builder-detect" 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 echo "dockerfile" return diff --git a/plugins/builder-pack/builder-build b/plugins/builder-pack/builder-build index 10854f868..d1dcd96f8 100755 --- a/plugins/builder-pack/builder-build +++ b/plugins/builder-pack/builder-build @@ -9,7 +9,7 @@ trigger-builder-pack-builder-build() { declare trigger="builder-build" declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3" - if [[ "$BUILDER_TYPE" != "cnb" ]]; then + if [[ "$BUILDER_TYPE" != "pack" ]]; then return fi @@ -33,13 +33,13 @@ trigger-builder-pack-builder-build() { 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 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 "$@" diff --git a/plugins/builder-pack/builder-detect b/plugins/builder-pack/builder-detect index b40d1d52f..d269c11dc 100755 --- a/plugins/builder-pack/builder-detect +++ b/plugins/builder-pack/builder-detect @@ -9,12 +9,12 @@ trigger-builder-pack-builder-detect() { declare APP="$1" SOURCECODE_WORK_DIR="$2" if [[ -f "$SOURCECODE_WORK_DIR/project.toml" ]]; then - echo "cnb" + echo "pack" return fi if [[ "$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)" == "1" ]]; then - echo "cnb" + echo "pack" return fi } diff --git a/plugins/builder-pack/builder-release b/plugins/builder-pack/builder-release index 95e028369..a5819abd0 100755 --- a/plugins/builder-pack/builder-release +++ b/plugins/builder-pack/builder-release @@ -8,15 +8,15 @@ trigger-builder-pack-builder-release() { declare trigger="builder-release" declare BUILDER_TYPE="$1" APP="$2" IMAGE_TAG="$3" - if [[ "$BUILDER_TYPE" != "cnb" ]]; then + if [[ "$BUILDER_TYPE" != "pack" ]]; then return 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") 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 "$@" diff --git a/plugins/common/functions b/plugins/common/functions index a5b5a3711..df6ed38c6 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -639,7 +639,7 @@ dokku_release() { local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") if is_image_cnb_based "$IMAGE"; then - IMAGE_SOURCE_TYPE="cnb" + IMAGE_SOURCE_TYPE="pack" fi 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)" if [[ "$DOKKU_CNB_EXPERIMENTAL" == "1" ]]; then - IMAGE_SOURCE_TYPE="cnb" + IMAGE_SOURCE_TYPE="pack" fi DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" diff --git a/plugins/git/functions b/plugins/git/functions index a67b795e1..16ea953a7 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -53,7 +53,7 @@ git_trigger_build() { 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" plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV" diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index d7a169695..dd19ef6b7 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -28,7 +28,7 @@ trigger-scheduler-docker-local-scheduler-deploy() { is_image_herokuish_based "$IMAGE" "$APP" && DOKKU_HEROKUISH=true local IMAGE_SOURCE_TYPE="dockerfile" [[ "$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 oldids=$(get_app_container_ids "$APP") diff --git a/plugins/tar/functions b/plugins/tar/functions index c95d29303..fc7e6698d 100755 --- a/plugins/tar/functions +++ b/plugins/tar/functions @@ -45,7 +45,7 @@ tar_trigger_build() { 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" plugn trigger pre-receive-app "$APP" "$BUILDER" "$TMP_WORK_DIR" "$REV" diff --git a/tests/unit/builder.bats b/tests/unit/builder.bats index d6f620c4e..f978bb73d 100644 --- a/tests/unit/builder.bats +++ b/tests/unit/builder.bats @@ -10,7 +10,7 @@ teardown() { destroy_app } -@test "(builder) builder-detect [cnb]" { +@test "(builder) builder-detect [pack]" { local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX") trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM @@ -21,11 +21,11 @@ teardown() { assert_success 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 "status: $status" assert_success - assert_output "cnb" + assert_output "pack" sudo rm -rf $TMP/* echo "output: $output" @@ -39,11 +39,11 @@ teardown() { assert_success 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 "status: $status" assert_success - assert_output "cnb" + assert_output "pack" } @test "(builder) builder-detect [dockerfile]" { @@ -56,7 +56,7 @@ teardown() { assert_success 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 "status: $status" assert_success @@ -77,7 +77,7 @@ teardown() { assert_success 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 "status: $status" assert_success @@ -95,7 +95,7 @@ teardown() { assert_success 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 "status: $status" assert_success @@ -113,7 +113,7 @@ teardown() { assert_success 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 "status: $status" assert_success