From 29b9f3c159f3de9b6b208020aaa7818358900a92 Mon Sep 17 00:00:00 2001 From: cclohmar Date: Mon, 6 Jul 2026 15:36:48 +0100 Subject: [PATCH] feat(deploy): add --destroy flag and smart update modes --- deploy.sh | 94 ++++++++++++++++++++++++++++++++---------------------- install.sh | 2 +- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/deploy.sh b/deploy.sh index 2f5f5a0..668bfc1 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,47 +1,51 @@ #!/usr/bin/env bash set -euo pipefail -# NextWorkspace Deploy — clean-slate deployment -HEALTH_CHECK_RETRIES=10 -HEALTH_CHECK_INTERVAL=2 - REPO_DIR="/opt/NextWks" TARGET_DIR="/opt/workspace" SERVICE_NAME="nextworkspace" BINARY_NAME="nextworkspace" +HEALTH_CHECK_RETRIES=10 +HEALTH_CHECK_INTERVAL=2 -echo "=== NextWorkspace Deploy ===" +# --- Mode detection --- +GREENFIELD=false +if [ "${1:-}" = "--destroy" ]; then + GREENFIELD=true + echo "[MODE] Greenfield deploy (--destroy)" +elif [ ! -d "$TARGET_DIR" ]; then + GREENFIELD=true + echo "[MODE] Greenfield deploy (target missing)" +else + echo "[MODE] Smart update (target exists)" +fi -# 1. Navigate to repo and pull latest +# --- Common: pull + build --- cd "$REPO_DIR" -echo "[1/9] Pulling latest code..." +echo "[1/8] Pulling latest code..." git pull -# 2. Build -echo "[2/9] Building binary..." +echo "[2/8] Building binary..." export PATH=$PATH:/usr/local/go/bin go build -o "$BINARY_NAME" . -# 3. Remove old deployment -echo "[3/9] Removing old deployment..." -rm -rf "$TARGET_DIR" +# --- Greenfield path --- +if [ "$GREENFIELD" = true ]; then + echo "[3/8] Removing old deployment..." + rm -rf "$TARGET_DIR" -# 4. Create target directory structure -echo "[4/9] Creating target directories..." -mkdir -p "$TARGET_DIR/configs/core/certs" + echo "[4/8] Creating target directories..." + mkdir -p "$TARGET_DIR/configs/core/certs" -# 5. Copy binary -echo "[5/9] Copying binary..." -cp "$BINARY_NAME" "$TARGET_DIR/$BINARY_NAME" + echo "[5/8] Copying binary..." + cp "$BINARY_NAME" "$TARGET_DIR/$BINARY_NAME" -# 6. Copy config files -echo "[6/9] Copying config files..." -cp configs/core/config.yaml "$TARGET_DIR/configs/core/config.yaml" -cp configs/core/proxies.yaml "$TARGET_DIR/configs/core/proxies.yaml" + echo "[6/8] Copying config files..." + cp configs/core/config.yaml "$TARGET_DIR/configs/core/config.yaml" + cp configs/core/proxies.yaml "$TARGET_DIR/configs/core/proxies.yaml" -# 7. Write systemd service -echo "[7/9] Writing systemd service..." -cat > /etc/systemd/system/$SERVICE_NAME.service < /etc/systemd/system/$SERVICE_NAME.service < /dev/null 2>&1; then - echo "[OK] NextWorkspace is serving on http://localhost:80/" - exit 0 - fi - echo " Attempt $i/$HEALTH_CHECK_RETRIES — not ready yet..." - sleep $HEALTH_CHECK_INTERVAL + if curl -sf http://localhost:80/ > /dev/null 2>&1; then + echo "[OK] NextWorkspace is serving on http://localhost:80/" + exit 0 + fi + echo " Attempt $i/$HEALTH_CHECK_RETRIES — not ready yet..." + sleep $HEALTH_CHECK_INTERVAL done echo "[FAIL] Health check failed — service did not respond on port 80" diff --git a/install.sh b/install.sh index 540cc2e..8a6d9e7 100755 --- a/install.sh +++ b/install.sh @@ -41,4 +41,4 @@ else fi echo "[DONE] Bootstrapping complete. Running first deploy..." -"$REPO_DIR/deploy.sh" +"$REPO_DIR/deploy.sh" --destroy