mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 00:58:34 +00:00
cleanup
This commit is contained in:
@@ -148,8 +148,10 @@ Options:
|
||||
--tarball PATH Output path for the image tar (default: ./local-storage/images/acore-modules-images.tar)
|
||||
--storage PATH Remote storage directory (default: <project-dir>/storage)
|
||||
--skip-storage Do not sync the storage directory
|
||||
--skip-env Do not upload .env to the remote host
|
||||
--preserve-containers Skip stopping/removing existing remote containers and images
|
||||
--clean-containers Stop/remove existing ac-* containers and project images on remote
|
||||
--copy-source Copy the full local project directory instead of syncing via git
|
||||
--cleanup-runtime Stop/remove existing ac-* containers and project images on remote
|
||||
--yes, -y Auto-confirm prompts (for existing deployments)
|
||||
--help Show this help
|
||||
EOF_HELP
|
||||
@@ -165,7 +167,9 @@ REMOTE_STORAGE=""
|
||||
SKIP_STORAGE=0
|
||||
ASSUME_YES=0
|
||||
COPY_SOURCE=0
|
||||
CLEANUP_RUNTIME=0
|
||||
SKIP_ENV=0
|
||||
PRESERVE_CONTAINERS=0
|
||||
CLEAN_CONTAINERS=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
@@ -178,8 +182,10 @@ while [[ $# -gt 0 ]]; do
|
||||
--tarball) TARBALL="$2"; shift 2;;
|
||||
--storage) REMOTE_STORAGE="$2"; shift 2;;
|
||||
--skip-storage) SKIP_STORAGE=1; shift;;
|
||||
--skip-env) SKIP_ENV=1; shift;;
|
||||
--preserve-containers) PRESERVE_CONTAINERS=1; shift;;
|
||||
--clean-containers) CLEAN_CONTAINERS=1; shift;;
|
||||
--copy-source) COPY_SOURCE=1; shift;;
|
||||
--cleanup-runtime) CLEANUP_RUNTIME=1; shift;;
|
||||
--yes|-y) ASSUME_YES=1; shift;;
|
||||
--help|-h) usage; exit 0;;
|
||||
*) echo "Unknown option: $1" >&2; usage; exit 1;;
|
||||
@@ -192,6 +198,11 @@ if [[ -z "$HOST" || -z "$USER" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$CLEAN_CONTAINERS" -eq 1 && "$PRESERVE_CONTAINERS" -eq 1 ]]; then
|
||||
echo "Cannot combine --clean-containers with --preserve-containers." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Normalize env file path if provided and recompute defaults
|
||||
if [ -n "$ENV_FILE" ] && [ -f "$ENV_FILE" ]; then
|
||||
ENV_FILE="$(cd "$(dirname "$ENV_FILE")" && pwd)/$(basename "$ENV_FILE")"
|
||||
@@ -302,14 +313,35 @@ validate_remote_environment(){
|
||||
local running_containers
|
||||
running_containers=$(run_ssh "docker ps --filter 'name=ac-' --format '{{.Names}}' 2>/dev/null | wc -l")
|
||||
if [ "$running_containers" -gt 0 ]; then
|
||||
echo "⚠️ Warning: Found $running_containers running AzerothCore containers"
|
||||
echo " Migration will overwrite existing deployment"
|
||||
if [ "$ASSUME_YES" != "1" ]; then
|
||||
read -r -p " Continue with migration? [y/N]: " reply
|
||||
case "$reply" in
|
||||
[Yy]*) echo " Proceeding with migration..." ;;
|
||||
*) echo " Migration cancelled."; exit 1 ;;
|
||||
esac
|
||||
if [ "$PRESERVE_CONTAINERS" -eq 1 ]; then
|
||||
echo "⚠️ Found $running_containers running AzerothCore containers; --preserve-containers set, leaving them running."
|
||||
if [ "$ASSUME_YES" != "1" ]; then
|
||||
read -r -p " Continue without stopping containers? [y/N]: " reply
|
||||
case "$reply" in
|
||||
[Yy]*) echo " Proceeding with migration (containers preserved)..." ;;
|
||||
*) echo " Migration cancelled."; exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
elif [ "$CLEAN_CONTAINERS" -eq 1 ]; then
|
||||
echo "⚠️ Found $running_containers running AzerothCore containers"
|
||||
echo " --clean-containers set: they will be stopped/removed during migration."
|
||||
if [ "$ASSUME_YES" != "1" ]; then
|
||||
read -r -p " Continue with cleanup? [y/N]: " reply
|
||||
case "$reply" in
|
||||
[Yy]*) echo " Proceeding with cleanup..." ;;
|
||||
*) echo " Migration cancelled."; exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Warning: Found $running_containers running AzerothCore containers"
|
||||
echo " Migration will NOT stop them automatically. Use --clean-containers to stop/remove."
|
||||
if [ "$ASSUME_YES" != "1" ]; then
|
||||
read -r -p " Continue with migration? [y/N]: " reply
|
||||
case "$reply" in
|
||||
[Yy]*) echo " Proceeding with migration..." ;;
|
||||
*) echo " Migration cancelled."; exit 1 ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -325,6 +357,25 @@ validate_remote_environment(){
|
||||
echo "✅ Remote environment validation complete"
|
||||
}
|
||||
|
||||
confirm_remote_storage_overwrite(){
|
||||
if [[ $SKIP_STORAGE -ne 0 ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ "$ASSUME_YES" = "1" ]]; then
|
||||
return
|
||||
fi
|
||||
local has_content
|
||||
has_content=$(run_ssh "if [ -d '$REMOTE_STORAGE' ]; then find '$REMOTE_STORAGE' -mindepth 1 -maxdepth 1 -print -quit; fi")
|
||||
if [ -n "$has_content" ]; then
|
||||
echo "⚠️ Remote storage at $REMOTE_STORAGE contains existing data."
|
||||
read -r -p " Continue and sync local storage over it? [y/N]: " reply
|
||||
case "${reply,,}" in
|
||||
y|yes) echo " Proceeding with storage sync..." ;;
|
||||
*) echo " Skipping storage sync for this run."; SKIP_STORAGE=1 ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
copy_source_tree(){
|
||||
echo " • Copying full local project directory..."
|
||||
ensure_remote_temp_dir
|
||||
@@ -388,11 +439,14 @@ setup_remote_repository(){
|
||||
}
|
||||
|
||||
cleanup_stale_docker_resources(){
|
||||
if [ "$CLEANUP_RUNTIME" -ne 1 ]; then
|
||||
if [ "$PRESERVE_CONTAINERS" -eq 1 ]; then
|
||||
echo "⋅ Skipping remote container/image cleanup (--preserve-containers)"
|
||||
return
|
||||
fi
|
||||
if [ "$CLEAN_CONTAINERS" -ne 1 ]; then
|
||||
echo "⋅ Skipping remote runtime cleanup (containers and images preserved)."
|
||||
return
|
||||
fi
|
||||
|
||||
echo "⋅ Cleaning up stale Docker resources on remote..."
|
||||
|
||||
# Stop and remove old containers
|
||||
@@ -446,6 +500,8 @@ if [ ${#MISSING_IMAGES[@]} -gt 0 ]; then
|
||||
printf ' • %s\n' "${MISSING_IMAGES[@]}"
|
||||
fi
|
||||
|
||||
confirm_remote_storage_overwrite
|
||||
|
||||
if [[ $SKIP_STORAGE -eq 0 ]]; then
|
||||
if [[ -d storage ]]; then
|
||||
echo "⋅ Syncing storage to remote"
|
||||
@@ -513,8 +569,34 @@ run_scp "$TARBALL" "$USER@$HOST:$REMOTE_TEMP_DIR/acore-modules-images.tar"
|
||||
run_ssh "docker load < '$REMOTE_TEMP_DIR/acore-modules-images.tar' && rm '$REMOTE_TEMP_DIR/acore-modules-images.tar'"
|
||||
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
echo "⋅ Uploading .env"
|
||||
run_scp "$ENV_FILE" "$USER@$HOST:$PROJECT_DIR/.env"
|
||||
if [[ $SKIP_ENV -eq 1 ]]; then
|
||||
echo "⋅ Skipping .env upload (--skip-env)"
|
||||
else
|
||||
remote_env_path="$PROJECT_DIR/.env"
|
||||
upload_env=1
|
||||
|
||||
if run_ssh "test -f '$remote_env_path'"; then
|
||||
if [ "$ASSUME_YES" = "1" ]; then
|
||||
echo "⋅ Overwriting existing remote .env (auto-confirm)"
|
||||
elif [ -t 0 ]; then
|
||||
read -r -p "⚠️ Remote .env exists at $remote_env_path. Overwrite? [y/N]: " reply
|
||||
case "$reply" in
|
||||
[Yy]*) ;;
|
||||
*) upload_env=0 ;;
|
||||
esac
|
||||
else
|
||||
echo "⚠️ Remote .env exists at $remote_env_path; skipping upload (no confirmation available)"
|
||||
upload_env=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $upload_env -eq 1 ]]; then
|
||||
echo "⋅ Uploading .env"
|
||||
run_scp "$ENV_FILE" "$USER@$HOST:$remote_env_path"
|
||||
else
|
||||
echo "⋅ Keeping existing remote .env"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "⋅ Remote prepares completed"
|
||||
|
||||
121
scripts/bash/update-remote.sh
Executable file
121
scripts/bash/update-remote.sh
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/bin/bash
|
||||
# Helper to push a fresh build to a remote host with minimal downtime and no data touch by default.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
DEFAULT_PROJECT_DIR="~$(printf '/%s' "$(basename "$ROOT_DIR")")"
|
||||
|
||||
HOST=""
|
||||
USER=""
|
||||
PORT=22
|
||||
IDENTITY=""
|
||||
PROJECT_DIR="$DEFAULT_PROJECT_DIR"
|
||||
PUSH_ENV=0
|
||||
PUSH_STORAGE=0
|
||||
CLEAN_CONTAINERS=0
|
||||
AUTO_DEPLOY=1
|
||||
ASSUME_YES=0
|
||||
|
||||
usage(){
|
||||
cat <<'EOF'
|
||||
Usage: scripts/bash/update-remote.sh --host HOST --user USER [options]
|
||||
|
||||
Options:
|
||||
--host HOST Remote hostname or IP (required)
|
||||
--user USER SSH username on remote host (required)
|
||||
--port PORT SSH port (default: 22)
|
||||
--identity PATH SSH private key
|
||||
--project-dir DIR Remote project directory (default: ~/<repo-name>)
|
||||
--remote-path DIR Alias for --project-dir (backward compat)
|
||||
--push-env Upload local .env to remote (default: skip)
|
||||
--push-storage Sync ./storage to remote (default: skip)
|
||||
--clean-containers Stop/remove remote ac-* containers & project images during migration (default: preserve)
|
||||
--no-auto-deploy Do not trigger remote deploy after migration
|
||||
--yes Auto-confirm prompts
|
||||
--help Show this help
|
||||
EOF
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--host) HOST="$2"; shift 2;;
|
||||
--user) USER="$2"; shift 2;;
|
||||
--port) PORT="$2"; shift 2;;
|
||||
--identity) IDENTITY="$2"; shift 2;;
|
||||
--project-dir) PROJECT_DIR="$2"; shift 2;;
|
||||
--remote-path) PROJECT_DIR="$2"; shift 2;;
|
||||
--push-env) PUSH_ENV=1; shift;;
|
||||
--push-storage) PUSH_STORAGE=1; shift;;
|
||||
--clean-containers) CLEAN_CONTAINERS=1; shift;;
|
||||
--no-auto-deploy) AUTO_DEPLOY=0; shift;;
|
||||
--yes) ASSUME_YES=1; shift;;
|
||||
--help|-h) usage; exit 0;;
|
||||
*) echo "Unknown option: $1" >&2; usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$HOST" || -z "$USER" ]]; then
|
||||
echo "--host and --user are required" >&2
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
deploy_args=(--remote --remote-host "$HOST" --remote-user "$USER")
|
||||
|
||||
if [ -n "$PROJECT_DIR" ]; then
|
||||
deploy_args+=(--remote-project-dir "$PROJECT_DIR")
|
||||
fi
|
||||
if [ -n "$IDENTITY" ]; then
|
||||
deploy_args+=(--remote-identity "$IDENTITY")
|
||||
fi
|
||||
if [ "$PORT" != "22" ]; then
|
||||
deploy_args+=(--remote-port "$PORT")
|
||||
fi
|
||||
|
||||
if [ "$PUSH_STORAGE" -ne 1 ]; then
|
||||
deploy_args+=(--remote-skip-storage)
|
||||
fi
|
||||
if [ "$PUSH_ENV" -ne 1 ]; then
|
||||
deploy_args+=(--remote-skip-env)
|
||||
fi
|
||||
|
||||
if [ "$CLEAN_CONTAINERS" -eq 1 ]; then
|
||||
deploy_args+=(--remote-clean-containers)
|
||||
else
|
||||
deploy_args+=(--remote-preserve-containers)
|
||||
fi
|
||||
|
||||
if [ "$AUTO_DEPLOY" -eq 1 ]; then
|
||||
deploy_args+=(--remote-auto-deploy)
|
||||
fi
|
||||
|
||||
deploy_args+=(--no-watch)
|
||||
|
||||
if [ "$ASSUME_YES" -eq 1 ]; then
|
||||
deploy_args+=(--yes)
|
||||
fi
|
||||
|
||||
echo "Remote update plan:"
|
||||
echo " Host/User : ${USER}@${HOST}:${PORT}"
|
||||
echo " Project Dir : ${PROJECT_DIR}"
|
||||
echo " Push .env : $([ "$PUSH_ENV" -eq 1 ] && echo yes || echo no)"
|
||||
echo " Push storage : $([ "$PUSH_STORAGE" -eq 1 ] && echo yes || echo no)"
|
||||
echo " Cleanup mode : $([ "$CLEAN_CONTAINERS" -eq 1 ] && echo 'clean containers' || echo 'preserve containers')"
|
||||
echo " Auto deploy : $([ "$AUTO_DEPLOY" -eq 1 ] && echo yes || echo no)"
|
||||
if [ "$AUTO_DEPLOY" -eq 1 ] && [ "$PUSH_ENV" -ne 1 ]; then
|
||||
echo " ⚠️ Auto-deploy is enabled but push-env is off; remote deploy will fail without a valid .env."
|
||||
fi
|
||||
|
||||
if [ "$ASSUME_YES" -ne 1 ]; then
|
||||
read -r -p "Proceed with remote update? [y/N]: " reply
|
||||
reply="${reply:-n}"
|
||||
case "${reply,,}" in
|
||||
y|yes) ;;
|
||||
*) echo "Aborted."; exit 1 ;;
|
||||
esac
|
||||
deploy_args+=(--yes)
|
||||
fi
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
./deploy.sh "${deploy_args[@]}"
|
||||
Reference in New Issue
Block a user