From 81542ef089158d65aa7e4dcdacba15b44cbd8fbd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 28 Dec 2018 17:07:26 -0500 Subject: [PATCH] feat: do not clone URLS and VHOST files to new apps This follows the heroku pattern of ensuring applications are "freshly" created, routing-wise. Closes #2740 --- docs/deployment/application-management.md | 4 ++-- plugins/apps/subcommands/clone | 4 +--- plugins/certs/post-app-clone-setup | 12 ++++++++++++ plugins/domains/post-app-clone-setup | 12 ++++++++++++ tests/unit/10_apps.bats | 6 ++++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100755 plugins/certs/post-app-clone-setup create mode 100755 plugins/domains/post-app-clone-setup diff --git a/docs/deployment/application-management.md b/docs/deployment/application-management.md index 2c5395343..b2a4eead9 100644 --- a/docs/deployment/application-management.md +++ b/docs/deployment/application-management.md @@ -149,9 +149,9 @@ dokku apps:clone node-js-app io-js-app Cloning 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 and then rebuild the new version of the app and deploy it. All of your config variables, including database urls, will be preserved. +This will copy all of your app's contents into a new app directory with the name of your choice and then rebuild the new version of the app and deploy it. All of your config variables, including database urls, will be preserved. Custom domains and SSL certificates will not be copied to the new app. -> Warning: If you have exposed specific ports via docker-options, added generic domains, or performed anything that cannot be done against multiple applications, `apps:clone` may result in errors. +> Warning: If you have exposed specific ports via docker-options, 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: diff --git a/plugins/apps/subcommands/clone b/plugins/apps/subcommands/clone index 7c8a1e3c9..7754b3903 100755 --- a/plugins/apps/subcommands/clone +++ b/plugins/apps/subcommands/clone @@ -37,7 +37,7 @@ apps_clone_cmd() { apps_create "$NEW_APP" pushd "$DOKKU_ROOT/$OLD_APP/." > /dev/null - find ./* -not \( -name .cache \) | grep -v -e "./cache" -e "./tls" | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" + find ./* -not \( -name .cache \) | grep -v "./cache" | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" popd > /dev/null 2>&1 || pushd "/tmp" > /dev/null plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP" @@ -46,8 +46,6 @@ apps_clone_cmd() { fi rm -rf "$NEW_CACHE_DIR" - [[ -f "$DOKKU_ROOT/$NEW_APP/URLS" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS" - [[ -f "$DOKKU_ROOT/$NEW_APP/VHOST" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST" [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]] && sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" [[ "$SKIP_REBUILD" == "true" ]] || ps_rebuild "$NEW_APP" plugn trigger post-app-clone "$OLD_APP" "$NEW_APP" diff --git a/plugins/certs/post-app-clone-setup b/plugins/certs/post-app-clone-setup new file mode 100755 index 000000000..93738664d --- /dev/null +++ b/plugins/certs/post-app-clone-setup @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +certs_post_app_clone_setup() { + declare desc="removes cert file when setting up a clone" + declare OLD_APP="$1" NEW_APP="$2" + local APP_DIR="$DOKKU_ROOT/$NEW_APP" + + rm -rf "$APP_DIR/tls" +} + +certs_post_app_clone_setup "$@" diff --git a/plugins/domains/post-app-clone-setup b/plugins/domains/post-app-clone-setup new file mode 100755 index 000000000..5093129f2 --- /dev/null +++ b/plugins/domains/post-app-clone-setup @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +domains_post_app_clone_setup() { + declare desc="removes domain files when setting up a clone" + declare OLD_APP="$1" NEW_APP="$2" + local APP_DIR="$DOKKU_ROOT/$NEW_APP" + + rm -rf "$APP_DIR/URLS" "$APP_DIR/VHOST" +} + +domains_post_app_clone_setup "$@" diff --git a/tests/unit/10_apps.bats b/tests/unit/10_apps.bats index 71dd6b0f7..daf87f0d1 100755 --- a/tests/unit/10_apps.bats +++ b/tests/unit/10_apps.bats @@ -152,6 +152,12 @@ teardown () { echo "output: $output" echo "status: $status" assert_success + run [ -d /home/dokku/great-test-name/tls ] + assert_failure + run [ -f /home/dokku/great-test-name/URLS ] + assert_failure + run [ -f /home/dokku/great-test-name/VHOST ] + assert_failure run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" echo "output: $output" echo "status: $status"