-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·86 lines (69 loc) · 2.24 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·86 lines (69 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -euo pipefail
# ServerCommander OS update helper
# - Pull latest code from origin/main
# - Rebuild and restart container
# - Keep persistent data (no volume deletion)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
RESET='\033[0m'
info() { echo -e "${CYAN}[INFO]${RESET} $*"; }
ok() { echo -e "${GREEN}[OK]${RESET} $*"; }
warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; }
fatal() { error "$*"; exit 1; }
require_cmd() {
command -v "$1" >/dev/null 2>&1 || fatal "Missing required command: $1"
}
require_cmd git
require_cmd docker
if docker compose version >/dev/null 2>&1; then
COMPOSE_CMD=(docker compose)
COMPOSE_LABEL="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE_CMD=(docker-compose)
COMPOSE_LABEL="docker-compose"
else
fatal "Neither docker compose nor docker-compose is available"
fi
if ! docker info >/dev/null 2>&1; then
fatal "Docker daemon is not running"
fi
if [[ ! -f .env ]]; then
fatal "Missing .env in project root. Run setup.sh first."
fi
if [[ ! -f docker-compose.yml ]]; then
fatal "Missing docker-compose.yml in project root."
fi
if [[ -n "$(git status --porcelain)" ]]; then
fatal "Working tree has local changes. Commit/stash first, then run update.sh again."
fi
backup_file=".env.backup.update.$(date +%Y%m%d%H%M%S)"
cp .env "$backup_file"
ok "Created .env backup: $backup_file"
info "Pulling latest changes from origin/main..."
git fetch origin main
git pull --no-rebase origin main
ok "Repository updated"
info "Rebuilding image..."
"${COMPOSE_CMD[@]}" build --pull
ok "Image rebuilt"
info "Restarting service (volumes are preserved)..."
"${COMPOSE_CMD[@]}" down
"${COMPOSE_CMD[@]}" up -d
ok "Service restarted"
if command -v curl >/dev/null 2>&1; then
info "Checking health endpoint..."
if curl -sf "http://localhost:${HOST_PORT:-3000}/login" >/dev/null 2>&1; then
ok "Health check passed"
else
warn "Health endpoint not ready yet. Check logs: ${COMPOSE_LABEL} logs -f"
fi
else
warn "curl not found; skipping health check"
fi
ok "Update completed. Existing data volume remains intact."