This reduces duplication and allows users to rely on global arguments to generate most labels needed. The 'commit' command cannot have global arguments because the whitespace within the label change breaks string-based interpolation, and shell arrays cannot be exported.
38 lines
1.6 KiB
Bash
Executable File
38 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/apps/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
|
|
apps_rename_cmd() {
|
|
declare desc="renames an app"
|
|
local cmd="apps:rename"
|
|
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
|
[[ -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"
|
|
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" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm -v "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
|
fi
|
|
rm -rf "$OLD_CACHE_DIR"
|
|
apps_create "$NEW_APP"
|
|
cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP"
|
|
plugn trigger proxy-clear-config "$NEW_APP"
|
|
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
|
|
[[ -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"
|
|
docker_cleanup "$OLD_APP" "true"
|
|
echo "Renaming $OLD_APP to $NEW_APP... done"
|
|
}
|
|
|
|
apps_rename_cmd "$@"
|