-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlablink-update.sh
More file actions
executable file
·101 lines (87 loc) · 3.18 KB
/
lablink-update.sh
File metadata and controls
executable file
·101 lines (87 loc) · 3.18 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# LabLink Update Script
# Updates code from git and rebuilds containers
#
# Usage: sudo ./lablink-update.sh [branch]
# Example: sudo ./lablink-update.sh main
BRANCH="${1:-main}"
echo "╔═══════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ LabLink Update & Rebuild ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════╝"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run as root (use sudo)"
exit 1
fi
cd /opt/lablink || exit 1
echo "Step 1: Checking current version..."
CURRENT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
echo " Current branch: $CURRENT_BRANCH"
echo " Current commit: $CURRENT_COMMIT"
echo ""
echo "Step 2: Pulling latest code from git (branch: $BRANCH)..."
if git fetch origin "$BRANCH" && git checkout "$BRANCH" && git pull origin "$BRANCH"; then
NEW_COMMIT=$(git rev-parse --short HEAD)
echo " ✓ Code updated to: $NEW_COMMIT"
if [ "$CURRENT_COMMIT" = "$NEW_COMMIT" ]; then
echo " Already up to date!"
read -p "Rebuild anyway? (y/N): " rebuild
if [ "$rebuild" != "y" ] && [ "$rebuild" != "Y" ]; then
echo "No rebuild needed. Exiting."
exit 0
fi
fi
else
echo " ✗ Git pull failed"
echo " Continuing with rebuild anyway..."
fi
echo ""
echo "Step 3: Stopping containers..."
docker compose down
echo ""
echo "Step 4: Rebuilding containers (this may take 2-3 minutes)..."
if docker compose build --no-cache; then
echo " ✓ Rebuild successful"
else
echo " ✗ Rebuild failed"
echo " Check logs above for errors"
exit 1
fi
echo ""
echo "Step 5: Starting containers..."
if docker compose up -d; then
echo " ✓ Containers started"
else
echo " ✗ Failed to start containers"
exit 1
fi
echo ""
echo "Step 6: Waiting for services to be ready..."
sleep 5
# Wait for containers to be healthy
MAX_WAIT=30
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
if docker compose ps 2>/dev/null | grep -q "Up"; then
echo " ✓ Services are ready"
break
fi
sleep 2
WAITED=$((WAITED + 2))
done
echo ""
echo "╔═══════════════════════════════════════════════════════╗"
echo "║ Update Complete! ║"
echo "╚═══════════════════════════════════════════════════════╝"
echo ""
# Show final status if lablink-status exists
if command -v lablink-status &> /dev/null; then
lablink-status
else
echo "Container Status:"
docker compose ps
fi