mirror of
https://github.com/dokku/dokku.git
synced 2026-02-24 04:00:36 +01:00
43 lines
1.7 KiB
Bash
Executable File
43 lines
1.7 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_clone_cmd() {
|
|
declare desc="clones an app"
|
|
declare OLD_APP="$2" NEW_APP="$3"
|
|
local cmd="apps:clone"
|
|
local SKIP_REBUILD=false
|
|
|
|
if [[ "$2" == "--skip-deploy" ]]; then
|
|
SKIP_REBUILD=true
|
|
OLD_APP="$3"
|
|
NEW_APP="$4"
|
|
fi
|
|
|
|
[[ -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"
|
|
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
|
|
local NEW_CACHE_DIR_ON_HOST="$DOKKU_ROOT_ON_HOST/$NEW_APP/cache"
|
|
|
|
apps_create "$NEW_APP"
|
|
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
|
|
|
|
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
|
|
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$NEW_CACHE_DIR_ON_HOST:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
|
|
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"
|
|
echo "Cloning $OLD_APP to $NEW_APP... done"
|
|
}
|
|
|
|
apps_clone_cmd "$@"
|