From 2e774f0806851dad5a5d5eb03228425fbeeedeee Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 17 Feb 2020 19:23:07 -0500 Subject: [PATCH] feat: unify apps:rename and apps:clone - add --skip-deploy to apps:rename - add all missing validation to rename command - fix log output to be a bit more logical --- docs/deployment/application-management.md | 8 +++++++- plugins/apps/subcommands/clone | 3 ++- plugins/apps/subcommands/rename | 21 ++++++++++++++++++--- plugins/ps/post-app-rename | 4 +++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/deployment/application-management.md b/docs/deployment/application-management.md index 9d58be15d..b738caede 100644 --- a/docs/deployment/application-management.md +++ b/docs/deployment/application-management.md @@ -134,6 +134,12 @@ Renaming node-js-app to io-js-app... done This will copy all of your app's contents into a new app directory with the name of your choice, delete your old app, then rebuild the new version of the app and deploy it. All of your config variables, including database urls, will be preserved. +By default, Dokku will deploy the renamed app, though you can skip the deploy by using the `--skip-deploy` flag: + +```shell +dokku apps:rename --skip-deploy node-js-app io-js-app +``` + ### Cloning an existing app > New as of 0.11.5 @@ -157,7 +163,7 @@ This will copy all of your app's contents into a new app directory with the name > Warning: If you have exposed specific ports via `docker-options` plugin, or performed anything that cannot be done against multiple applications, `apps:clone` may result in errors. -By default, Dokku will deploy this new application, though you can skip the deploy by using the `--skip-deploy` flag: +By default, Dokku will deploy this new app, though you can skip the deploy by using the `--skip-deploy` flag: ```shell dokku apps:clone --skip-deploy node-js-app io-js-app diff --git a/plugins/apps/subcommands/clone b/plugins/apps/subcommands/clone index 7d0b8257f..a89ca39db 100755 --- a/plugins/apps/subcommands/clone +++ b/plugins/apps/subcommands/clone @@ -33,10 +33,11 @@ cmd-apps-clone() { dokku_log_fail "Name is already taken" fi + dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP" apps_create "$NEW_APP" plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP" SKIP_REBUILD=$SKIP_REBUILD plugn trigger post-app-clone "$OLD_APP" "$NEW_APP" - dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP... done" + dokku_log_verbose_quiet "Done" } cmd-apps-clone "$@" diff --git a/plugins/apps/subcommands/rename b/plugins/apps/subcommands/rename index ba4032da8..38f1089e5 100755 --- a/plugins/apps/subcommands/rename +++ b/plugins/apps/subcommands/rename @@ -10,15 +10,30 @@ cmd-apps-rename() { declare cmd="apps:rename" [[ "$1" == "$cmd" ]] && shift 1 declare OLD_APP="$1" NEW_APP="$2" + local SKIP_REBUILD=false + for arg in "$@"; do + [[ "$arg" == "--skip-deploy" ]] && shift 1 && SKIP_REBUILD=true +s [[ "$arg" =~ ^--.* ]] || break + done + + OLD_APP="$1" NEW_APP="$2" [[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on" - [[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken" + is_valid_app_name "$OLD_APP" + is_valid_app_name "$NEW_APP" + apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist" + + if apps_exists "$NEW_APP" >/dev/null 2>&1; then + dokku_log_fail "Name is already taken" + fi + + dokku_log_info1_quiet "Renaming $OLD_APP to $NEW_APP" apps_create "$NEW_APP" plugn trigger post-app-rename-setup "$OLD_APP" "$NEW_APP" DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP" - plugn trigger post-app-rename "$OLD_APP" "$NEW_APP" - echo "Renaming $OLD_APP to $NEW_APP... done" + SKIP_REBUILD=$SKIP_REBUILD plugn trigger post-app-rename "$OLD_APP" "$NEW_APP" + dokku_log_verbose_quiet "Done" } cmd-apps-rename "$@" diff --git a/plugins/ps/post-app-rename b/plugins/ps/post-app-rename index 4b0bd16a4..7175b517b 100755 --- a/plugins/ps/post-app-rename +++ b/plugins/ps/post-app-rename @@ -10,7 +10,9 @@ trigger-ps-post-app-rename() { declare trigger="post-app-rename" declare OLD_APP="$1" NEW_APP="$2" - ps_rebuild "$NEW_APP" + if [[ "$SKIP_REBUILD" != "true" ]]; then + ps_rebuild "$NEW_APP" + fi } trigger-ps-post-app-rename "$@"