From 0498a707c8f0ff17a26afb8b3c8270bc5fb76ecd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 27 Dec 2018 04:58:43 -0500 Subject: [PATCH] fix: Add a trigger to allow plugins to cleanup after a new clone is created --- docs/development/plugin-triggers.md | 15 +++++++++++++++ plugins/20_events/post-app-clone-setup | 1 + plugins/apps/subcommands/clone | 1 + 3 files changed, 17 insertions(+) create mode 120000 plugins/20_events/post-app-clone-setup diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 6bf29a48f..8c7986b04 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -559,6 +559,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `post-app-clone-setup` + +- Description: Allows you to run commands after an app is setup, and before it is rebuild. This is useful for cleaning up tasks, or ensuring configuration from an old app is copied to the new app +- Invoked by: `dokku apps:clone` +- Arguments: `$OLD_APP_NAME $NEW_APP_NAME` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `post-app-rename` - Description: Allows you to run commands after an app was renamed. diff --git a/plugins/20_events/post-app-clone-setup b/plugins/20_events/post-app-clone-setup new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/post-app-clone-setup @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/apps/subcommands/clone b/plugins/apps/subcommands/clone index 8076c0668..e31c828ff 100755 --- a/plugins/apps/subcommands/clone +++ b/plugins/apps/subcommands/clone @@ -39,6 +39,7 @@ apps_clone_cmd() { pushd "$DOKKU_ROOT/$OLD_APP/." > /dev/null 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" if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache