-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·53 lines (41 loc) · 1.44 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·53 lines (41 loc) · 1.44 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
#!/bin/bash
set -euo pipefail
REPO_DIR="/var/www/LizardMorph"
LOG_FILE="/var/log/lizardmorph/deploy.log"
FRONTEND_DIR="$REPO_DIR/frontend"
NODE_BIN="/home/yloh30/.nvm/versions/node/v20.19.5/bin"
UV_BIN="/home/yloh30/.local/bin"
export PATH="$UV_BIN:$NODE_BIN:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
mkdir -p "$(dirname "$LOG_FILE")"
touch "$LOG_FILE"
cd "$REPO_DIR"
log "========== Deployment started =========="
# Stash uncommitted changes if any
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
log "Stashing uncommitted changes..."
git stash push -m "auto-deploy-stash-$(date +%s)"
fi
log "Fetching and resetting to origin/main..."
git fetch origin
git reset --hard origin/main
log "Git pull complete: $(git log --oneline -1)"
# Rebuild frontend
if [ -f "$FRONTEND_DIR/package.json" ]; then
log "Installing frontend dependencies..."
cd "$FRONTEND_DIR"
npm ci --prefer-offline 2>>"$LOG_FILE" || npm install 2>>"$LOG_FILE"
log "Building frontend..."
npm run build 2>>"$LOG_FILE"
log "Frontend build complete"
cd "$REPO_DIR"
fi
# Restart backend via systemd
log "Restarting lizardmorph-backend service..."
sudo /bin/systemctl restart lizardmorph-backend
# Reload nginx to pick up any new static files
log "Reloading nginx..."
sudo /usr/sbin/nginx -s reload 2>>"$LOG_FILE" || true
log "========== Deployment finished =========="