From 4022ebd31c62d46b9f494c0ef955a8596dc30df9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 10 Jul 2021 01:56:37 -0400 Subject: [PATCH] refactor: allow missing project.toml We should treat the project.toml as an optional file, as is the Procfile. Additionally, moving the file into place early will ensure there is no chance of selecting the wrong file. --- .../builders/cloud-native-buildpacks.md | 2 +- plugins/builder-pack/builder-build | 12 -------- plugins/builder-pack/core-post-extract | 30 +++++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100755 plugins/builder-pack/core-post-extract diff --git a/docs/deployment/builders/cloud-native-buildpacks.md b/docs/deployment/builders/cloud-native-buildpacks.md index e20a01fac..572a6d2c4 100644 --- a/docs/deployment/builders/cloud-native-buildpacks.md +++ b/docs/deployment/builders/cloud-native-buildpacks.md @@ -53,7 +53,7 @@ dokku builder:set node-js-app selected pack ### Changing the `project.toml` location -When deploying a monorepo, it may be desirable to specify the specific path of the `project.toml` file to use for a given app. This can be done via the `builder-pack:set` command. If a value other than `project.toml` is specified and that file does not exist in the app's build directory, then the build will fail. +When deploying a monorepo, it may be desirable to specify the specific path of the `project.toml` file to use for a given app. This can be done via the `builder-pack:set` command. If a value other than `project.toml` is specified and that file does not exist in the app's build directory, Dokku will continue the build process as if the repository has no `project.toml`. ```shell dokku builder-pack:set node-js-app projecttoml-path project2.toml diff --git a/plugins/builder-pack/builder-build b/plugins/builder-pack/builder-build index 1ea07c4e3..7a9644d14 100755 --- a/plugins/builder-pack/builder-build +++ b/plugins/builder-pack/builder-build @@ -1,7 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" -source "$PLUGIN_AVAILABLE_PATH/builder-pack/internal-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -29,17 +28,6 @@ trigger-builder-pack-builder-build() { pushd "$SOURCECODE_WORK_DIR" &>/dev/null - local NEW_PROJECT_TOML="$(fn-builder-pack-computed-projecttoml-path "$APP")" - if [[ -n "$NEW_PROJECT_TOML" ]]; then - if [[ ! -f "$NEW_PROJECT_TOML" ]] && [[ "$NEW_PROJECT_TOML" != "project.toml" ]]; then - dokku_log_fail "Invalid projecttoml-path specified: $NEW_PROJECT_TOML" - fi - - if [[ "$NEW_PROJECT_TOML" != "project.toml" ]]; then - mv "$NEW_PROJECT_TOML" project.toml - fi - fi - local TMP_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") trap "rm -rf '$TMP_FILE' >/dev/null" RETURN INT TERM diff --git a/plugins/builder-pack/core-post-extract b/plugins/builder-pack/core-post-extract new file mode 100755 index 000000000..83ea6540e --- /dev/null +++ b/plugins/builder-pack/core-post-extract @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/builder-pack/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-builder-pack-core-post-extract() { + declare desc="builder-pack post-extract plugin trigger" + declare trigger="post-extract" + declare APP="$1" SOURCECODE_WORK_DIR="$2" + local NEW_PROJECT_TOML="$(fn-builder-pack-computed-projecttoml-path "$APP")" + + pushd "$TMP_WORK_DIR" >/dev/null + + if [[ -z "$NEW_PROJECT_TOML" ]]; then + return + fi + + if [[ ! -f "$NEW_PROJECT_TOML" ]]; then + rm -f project.toml + return + fi + + if [[ "$NEW_PROJECT_TOML" != "project.toml" ]]; then + mv "$NEW_PROJECT_TOML" project.toml + fi + popd &>/dev/null +} + +trigger-builder-pack-post-extract "$@"