From be3574136b5e70cc7d9eb25cc511d1fb25b8b429 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 29 Jul 2016 00:07:34 -0400 Subject: [PATCH 1/2] Properly handle non-deployed applications during apps:rename An application which has not been deployed will not have an image available, and therefore attempting to remove an (empty) cache directory will fail. Rather than checking for the image - which we should still do, as not having an image for a deployed app is an error state - we should instead only attempt the docker cache removal if the directory cannot be removed via rmdir. Closes #2294 --- plugins/apps/subcommands/rename | 4 +++- tests/unit/10_apps.bats | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/apps/subcommands/rename b/plugins/apps/subcommands/rename index fef991daf..2423ce369 100755 --- a/plugins/apps/subcommands/rename +++ b/plugins/apps/subcommands/rename @@ -13,7 +13,9 @@ apps_rename_cmd() { local NEW_APP="$3" mkdir -p "$DOKKU_ROOT/$NEW_APP" - docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache + if ! rmdir "$DOKKU_ROOT/$OLD_APP/cache" > /dev/null 2>&1; then + docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache + fi rm -rf "$DOKKU_ROOT/$OLD_APP/cache" cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP" DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP" diff --git a/tests/unit/10_apps.bats b/tests/unit/10_apps.bats index cf8287237..06300e2a2 100644 --- a/tests/unit/10_apps.bats +++ b/tests/unit/10_apps.bats @@ -68,4 +68,17 @@ load test_helper echo "output: "$output echo "status: "$status assert_success + + run dokku apps:create $TEST_APP + echo "output: "$output + echo "status: "$status + assert_success + run bash -c "dokku apps:rename $TEST_APP great-test-name" + echo "output: "$output + echo "status: "$status + assert_output $TEST_APP + run bash -c "dokku --force apps:destroy great-test-name" + echo "output: "$output + echo "status: "$status + assert_success } From b2fac23d58ae2d26f3f88c195b5622a8f3460d78 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 29 Jul 2016 16:32:40 -0400 Subject: [PATCH 2/2] Handle cases where directories and files are not-existent New applications will be missing a few different files and directories, which isn't strictly an error case. --- plugins/apps/subcommands/rename | 13 +++++++------ tests/unit/10_apps.bats | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/apps/subcommands/rename b/plugins/apps/subcommands/rename index 2423ce369..7ad59b08d 100755 --- a/plugins/apps/subcommands/rename +++ b/plugins/apps/subcommands/rename @@ -11,17 +11,18 @@ apps_rename_cmd() { [[ -d "$DOKKU_ROOT/$3" ]] && dokku_log_fail "Name is already taken" local OLD_APP="$2" local NEW_APP="$3" + local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache" mkdir -p "$DOKKU_ROOT/$NEW_APP" - if ! rmdir "$DOKKU_ROOT/$OLD_APP/cache" > /dev/null 2>&1; then - docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache + if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR"; then + docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$OLD_CACHE_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache fi - rm -rf "$DOKKU_ROOT/$OLD_APP/cache" + rm -rf "$OLD_CACHE_DIR" cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP" DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP" - sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS" - sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST" - sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" + [[ -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" ps_rebuild "$NEW_APP" plugn trigger post-app-rename "$OLD_APP" "$NEW_APP" echo "Renaming $OLD_APP to $NEW_APP... done" diff --git a/tests/unit/10_apps.bats b/tests/unit/10_apps.bats index 06300e2a2..621ad80b9 100644 --- a/tests/unit/10_apps.bats +++ b/tests/unit/10_apps.bats @@ -76,7 +76,7 @@ load test_helper run bash -c "dokku apps:rename $TEST_APP great-test-name" echo "output: "$output echo "status: "$status - assert_output $TEST_APP + assert_success run bash -c "dokku --force apps:destroy great-test-name" echo "output: "$output echo "status: "$status