From e1dc98f1e72ca59de23fd3446222a58704979a21 Mon Sep 17 00:00:00 2001 From: uprightbass360 Date: Sun, 23 Nov 2025 16:42:50 -0500 Subject: [PATCH] deploy updates --- deploy.sh | 55 +++++++++++++++++++++++++++++++++++ docs/GETTING_STARTED.md | 2 ++ scripts/bash/migrate-stack.sh | 23 +++++++++++++-- scripts/go/go.mod | 2 +- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/deploy.sh b/deploy.sh index 923f274..7ed8d88 100755 --- a/deploy.sh +++ b/deploy.sh @@ -35,6 +35,9 @@ REMOTE_COPY_SOURCE=0 REMOTE_ARGS_PROVIDED=0 REMOTE_AUTO_DEPLOY=0 REMOTE_AUTO_DEPLOY=0 +REMOTE_STORAGE_OVERRIDE="" +REMOTE_CONTAINER_USER_OVERRIDE="" +REMOTE_ENV_FILE="" MODULE_HELPER="$ROOT_DIR/scripts/python/modules.py" MODULE_STATE_INITIALIZED=0 @@ -164,6 +167,23 @@ collect_remote_details(){ *) REMOTE_SKIP_STORAGE=0 ;; esac fi + + # Optional remote env overrides (default to current values) + local storage_default container_user_default + storage_default="$(read_env STORAGE_PATH "./storage")" + container_user_default="$(read_env CONTAINER_USER "$(id -u):$(id -g)")" + + if [ -z "$REMOTE_STORAGE_OVERRIDE" ] && [ "$interactive" -eq 1 ]; then + local storage_input + read -rp "Remote storage path (STORAGE_PATH) [${storage_default}]: " storage_input + REMOTE_STORAGE_OVERRIDE="${storage_input:-$storage_default}" + fi + + if [ -z "$REMOTE_CONTAINER_USER_OVERRIDE" ] && [ "$interactive" -eq 1 ]; then + local cu_input + read -rp "Remote container user (CONTAINER_USER) [${container_user_default}]: " cu_input + REMOTE_CONTAINER_USER_OVERRIDE="${cu_input:-$container_user_default}" + fi } validate_remote_configuration(){ @@ -220,6 +240,8 @@ Options: --remote-skip-storage Skip syncing the storage directory during migration --remote-copy-source Copy the local project directory to remote instead of relying on git --remote-auto-deploy Run './deploy.sh --yes --no-watch' on the remote host after migration + --remote-storage-path PATH Override STORAGE_PATH/STORAGE_PATH_LOCAL in the remote .env + --remote-container-user USER[:GROUP] Override CONTAINER_USER in the remote .env --skip-config Skip applying server configuration preset -h, --help Show this help @@ -248,6 +270,8 @@ while [[ $# -gt 0 ]]; do --remote-skip-storage) REMOTE_SKIP_STORAGE=1; REMOTE_MODE=1; REMOTE_ARGS_PROVIDED=1; shift;; --remote-copy-source) REMOTE_COPY_SOURCE=1; REMOTE_MODE=1; REMOTE_ARGS_PROVIDED=1; shift;; --remote-auto-deploy) REMOTE_AUTO_DEPLOY=1; REMOTE_MODE=1; REMOTE_ARGS_PROVIDED=1; shift;; + --remote-storage-path) REMOTE_STORAGE_OVERRIDE="$2"; REMOTE_MODE=1; REMOTE_ARGS_PROVIDED=1; shift 2;; + --remote-container-user) REMOTE_CONTAINER_USER_OVERRIDE="$2"; REMOTE_MODE=1; REMOTE_ARGS_PROVIDED=1; shift 2;; --skip-config) SKIP_CONFIG=1; shift;; -h|--help) usage; exit 0;; *) err "Unknown option: $1"; usage; exit 1;; @@ -607,6 +631,33 @@ determine_profile(){ } run_remote_migration(){ + if [ -z "$REMOTE_ENV_FILE" ] && { [ -n "$REMOTE_STORAGE_OVERRIDE" ] || [ -n "$REMOTE_CONTAINER_USER_OVERRIDE" ]; }; then + local base_env="" + if [ -f "$ENV_PATH" ]; then + base_env="$ENV_PATH" + elif [ -f "$TEMPLATE_PATH" ]; then + base_env="$TEMPLATE_PATH" + fi + REMOTE_ENV_FILE="$(mktemp)" + if [ -n "$base_env" ]; then + cp "$base_env" "$REMOTE_ENV_FILE" + else + : > "$REMOTE_ENV_FILE" + fi + if [ -n "$REMOTE_STORAGE_OVERRIDE" ]; then + { + echo + echo "STORAGE_PATH=$REMOTE_STORAGE_OVERRIDE" + } >>"$REMOTE_ENV_FILE" + fi + if [ -n "$REMOTE_CONTAINER_USER_OVERRIDE" ]; then + { + echo + echo "CONTAINER_USER=$REMOTE_CONTAINER_USER_OVERRIDE" + } >>"$REMOTE_ENV_FILE" + fi + fi + local args=(--host "$REMOTE_HOST" --user "$REMOTE_USER") if [ -n "$REMOTE_PORT" ] && [ "$REMOTE_PORT" != "22" ]; then @@ -633,6 +684,10 @@ run_remote_migration(){ args+=(--yes) fi + if [ -n "$REMOTE_ENV_FILE" ]; then + args+=(--env-file "$REMOTE_ENV_FILE") + fi + (cd "$ROOT_DIR" && ./scripts/bash/migrate-stack.sh "${args[@]}") } diff --git a/docs/GETTING_STARTED.md b/docs/GETTING_STARTED.md index 2343a16..062f7a8 100644 --- a/docs/GETTING_STARTED.md +++ b/docs/GETTING_STARTED.md @@ -170,6 +170,8 @@ Optional flags: - `--remote-port 2222` - Custom SSH port - `--remote-identity ~/.ssh/custom_key` - Specific SSH key - `--remote-skip-storage` - Don't sync storage directory (fresh install on remote) +- `--remote-storage-path /mnt/acore-storage` - Override STORAGE_PATH on the remote host (local-storage stays per .env) +- `--remote-container-user 1001:1001` - Override CONTAINER_USER on the remote host (uid:gid) ### Step 3: Deploy on Remote Host ```bash diff --git a/scripts/bash/migrate-stack.sh b/scripts/bash/migrate-stack.sh index 984f8de..327be41 100755 --- a/scripts/bash/migrate-stack.sh +++ b/scripts/bash/migrate-stack.sh @@ -144,6 +144,7 @@ Options: --port PORT SSH port (default: 22) --identity PATH SSH private key (passed to scp/ssh) --project-dir DIR Remote project directory (default: ~/) + --env-file PATH Use this env file for image lookup and upload (default: ./.env) --tarball PATH Output path for the image tar (default: ./local-storage/images/acore-modules-images.tar) --storage PATH Remote storage directory (default: /storage) --skip-storage Do not sync the storage directory @@ -171,6 +172,7 @@ while [[ $# -gt 0 ]]; do --port) PORT="$2"; shift 2;; --identity) IDENTITY="$2"; shift 2;; --project-dir) PROJECT_DIR="$2"; shift 2;; + --env-file) ENV_FILE="$2"; shift 2;; --tarball) TARBALL="$2"; shift 2;; --storage) REMOTE_STORAGE="$2"; shift 2;; --skip-storage) SKIP_STORAGE=1; shift;; @@ -187,6 +189,14 @@ if [[ -z "$HOST" || -z "$USER" ]]; then 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")" +else + ENV_FILE="$PROJECT_ROOT/.env" +fi +DEFAULT_PROJECT_NAME="$(project_name::resolve "$ENV_FILE" "$TEMPLATE_FILE")" + expand_remote_path(){ local path="$1" case "$path" in @@ -224,7 +234,11 @@ resolve_path_relative_to_project(){ echo "${path%/}" } -STAGE_SQL_PATH_RAW="$(read_env_value STAGE_PATH_MODULE_SQL "${STORAGE_PATH_LOCAL:-./local-storage}/module-sql-updates")" +STAGE_SQL_PATH_RAW="$(read_env_value STAGE_PATH_MODULE_SQL "${LOCAL_STORAGE_ROOT:-./local-storage}/module-sql-updates")" +# Ensure STORAGE_PATH_LOCAL is defined to avoid set -u failures during expansion +if [ -z "${STORAGE_PATH_LOCAL:-}" ]; then + STORAGE_PATH_LOCAL="$LOCAL_STORAGE_ROOT" +fi # Expand any env references (e.g., ${STORAGE_PATH_LOCAL}) STAGE_SQL_PATH_RAW="$(eval "echo \"$STAGE_SQL_PATH_RAW\"")" LOCAL_STAGE_SQL_DIR="$(resolve_path_relative_to_project "$STAGE_SQL_PATH_RAW" "$PROJECT_ROOT")" @@ -396,6 +410,9 @@ validate_remote_environment collect_deploy_image_refs echo "⋅ Exporting deployment images to $TARBALL" +# Ensure destination directory exists +ensure_host_writable "$(dirname "$TARBALL")" + # Check which images are available and collect them IMAGES_TO_SAVE=() MISSING_IMAGES=() @@ -487,9 +504,9 @@ ensure_remote_temp_dir 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 ]]; then +if [[ -f "$ENV_FILE" ]]; then echo "⋅ Uploading .env" - run_scp .env "$USER@$HOST:$PROJECT_DIR/.env" + run_scp "$ENV_FILE" "$USER@$HOST:$PROJECT_DIR/.env" fi echo "⋅ Remote prepares completed" diff --git a/scripts/go/go.mod b/scripts/go/go.mod index d7141af..b337c68 100644 --- a/scripts/go/go.mod +++ b/scripts/go/go.mod @@ -1,6 +1,6 @@ module acore-compose/statusdash -go 1.22.2 +go 1.22 require ( github.com/gizak/termui/v3 v3.1.0 // indirect