refactor: move cache and rebuild handling to plugin triggers
This commit is contained in:
1 parent
63f4ec3867
commit
8987ec6704
5 files changed
+71
-25
No files matched your search
@@ -21,8 +21,6 @@ cmd-apps-clone() {
|
|||||||
OLD_APP="$1" NEW_APP="$2"
|
OLD_APP="$1" NEW_APP="$2"
|
||||||
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||||
|
|
||||||
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
|
|
||||||
|
|
||||||
is_valid_app_name "$OLD_APP"
|
is_valid_app_name "$OLD_APP"
|
||||||
is_valid_app_name "$NEW_APP"
|
is_valid_app_name "$NEW_APP"
|
||||||
apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist"
|
apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist"
|
||||||
@@ -35,22 +33,9 @@ cmd-apps-clone() {
|
|||||||
dokku_log_fail "Name is already taken"
|
dokku_log_fail "Name is already taken"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
|
|
||||||
local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache"
|
|
||||||
|
|
||||||
apps_create "$NEW_APP"
|
apps_create "$NEW_APP"
|
||||||
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
|
|
||||||
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | 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"
|
plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP"
|
||||||
|
SKIP_REBUILD=$SKIP_REBUILD plugn trigger post-app-clone "$OLD_APP" "$NEW_APP"
|
||||||
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
|
|
||||||
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
|
||||||
fi
|
|
||||||
rm -rf "$NEW_CACHE_DIR"
|
|
||||||
|
|
||||||
[[ "$SKIP_REBUILD" == "true" ]] || ps_rebuild "$NEW_APP"
|
|
||||||
plugn trigger post-app-clone "$OLD_APP" "$NEW_APP"
|
|
||||||
dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP... done"
|
dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP... done"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,17 +13,8 @@ cmd-apps-rename() {
|
|||||||
|
|
||||||
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
[[ -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"
|
[[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken"
|
||||||
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
|
|
||||||
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
|
|
||||||
|
|
||||||
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$OLD_APP"
|
|
||||||
|
|
||||||
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then
|
|
||||||
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
|
||||||
fi
|
|
||||||
rm -rf "$OLD_CACHE_DIR"
|
|
||||||
apps_create "$NEW_APP"
|
apps_create "$NEW_APP"
|
||||||
cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP"
|
|
||||||
plugn trigger post-app-rename-setup "$OLD_APP" "$NEW_APP"
|
plugn trigger post-app-rename-setup "$OLD_APP" "$NEW_APP"
|
||||||
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
|
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
|
||||||
plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
|
plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||||
|
|
||||||
|
trigger-builder-herokuish-post-app-clone-setup() {
|
||||||
|
declare desc="builder-herokuish post-app-clone-setup plugin trigger"
|
||||||
|
declare trigger="post-app-clone-setup"
|
||||||
|
declare OLD_APP="$1" NEW_APP="$2"
|
||||||
|
|
||||||
|
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
|
||||||
|
local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache"
|
||||||
|
|
||||||
|
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
|
||||||
|
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
|
||||||
|
popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null
|
||||||
|
|
||||||
|
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
|
||||||
|
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
|
||||||
|
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
||||||
|
fi
|
||||||
|
rm -rf "$NEW_CACHE_DIR"
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger-builder-herokuish-post-app-clone-setup "$@"
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||||
|
|
||||||
|
trigger-builder-herokuish-post-app-clone-setup() {
|
||||||
|
declare desc="builder-herokuish post-app-clone-setup plugin trigger"
|
||||||
|
declare trigger="post-app-clone-setup"
|
||||||
|
declare OLD_APP="$1" NEW_APP="$2"
|
||||||
|
|
||||||
|
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
|
||||||
|
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
|
||||||
|
|
||||||
|
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then
|
||||||
|
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
|
||||||
|
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
||||||
|
fi
|
||||||
|
rm -rf "$OLD_CACHE_DIR"
|
||||||
|
|
||||||
|
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
|
||||||
|
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
|
||||||
|
popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger-builder-herokuish-post-app-clone-setup "$@"
|
||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||||
|
|
||||||
|
trigger-ps-post-app-clone() {
|
||||||
|
declare desc="ps post-app-clone plugin trigger"
|
||||||
|
declare trigger="post-app-clone"
|
||||||
|
declare OLD_APP="$1" NEW_APP="$2"
|
||||||
|
|
||||||
|
if [[ "$SKIP_REBUILD" != "true" ]]; then
|
||||||
|
ps_rebuild "$NEW_APP"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger-ps-post-app-clone "$@"
|
||||||
Reference in new issue
Block a user