-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·122 lines (100 loc) · 3.48 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·122 lines (100 loc) · 3.48 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# deploy.sh - Deploy blst.upleb.uk to your server
# Usage: ./deploy.sh
set -e
# ============================================
# CONFIGURATION - Edit these values
# ============================================
SERVER="[email protected]" # <-- CHANGE THIS: your SSH user@hostname
REMOTE_PATH="/var/www/blst.upleb.uk" # <-- CHANGE THIS if different on your server
SSH_PORT="2121" # <-- CHANGE THIS if using non-standard SSH port
# Local paths
LOCAL_DIST="./dist"
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_ROOT"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🚀 Starting deployment of blst.upleb.uk${NC}"
echo "=========================================="
# ============================================
# STEP 1: Build
# ============================================
echo -e "${YELLOW}📦 Building project...${NC}"
if [ ! -f "package.json" ]; then
echo -e "${RED}❌ Error: package.json not found. Are you in the right directory?${NC}"
exit 1
fi
echo "Installing dependencies..."
npm ci --silent
echo "Building..."
npm run build
if [ ! -d "$LOCAL_DIST" ]; then
echo -e "${RED}❌ Error: dist/ folder not found after build${NC}"
exit 1
fi
if [ ! -f "$LOCAL_DIST/index.html" ]; then
echo -e "${RED}❌ Error: index.html not found in dist/${NC}"
exit 1
fi
echo -e "${GREEN}✅ Build successful${NC}"
# ============================================
# STEP 2: Deploy
# ============================================
echo -e "${YELLOW}🚀 Deploying to server...${NC}"
echo "Server: $SERVER"
echo "Remote path: $REMOTE_PATH"
echo ""
# Check if we can connect
echo "Testing SSH connection..."
if ! ssh -p "$SSH_PORT" -o ConnectTimeout=5 "$SERVER" "echo 'SSH OK'" > /dev/null 2>&1; then
echo -e "${RED}❌ Error: Cannot connect to server via SSH${NC}"
echo "Please check:"
echo " - SERVER variable is set correctly (current: $SERVER)"
echo " - SSH key is configured: ssh-copy-id $SERVER"
echo " - SSH port is correct (current: $SSH_PORT)"
exit 1
fi
# Use rsync to deploy
echo "Syncing files..."
rsync -avz --delete \
-e "ssh -p $SSH_PORT" \
--exclude='.DS_Store' \
--exclude='*.log' \
--exclude='.git' \
"$LOCAL_DIST/" \
"$SERVER:$REMOTE_PATH/"
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Error: rsync failed${NC}"
exit 1
fi
# ============================================
# STEP 3: Fix Permissions
# ============================================
echo -e "${YELLOW}🔧 Setting permissions...${NC}"
ssh -p "$SSH_PORT" "$SERVER" "sudo chown -R www-data:www-data $REMOTE_PATH && sudo chmod -R 755 $REMOTE_PATH"
if [ $? -ne 0 ]; then
echo -e "${YELLOW}⚠️ Warning: Could not set permissions automatically${NC}"
echo "You may need to run manually on server:"
echo " sudo chown -R www-data:www-data $REMOTE_PATH"
fi
# ============================================
# STEP 4: Verify
# ============================================
echo ""
echo -e "${GREEN}✅ Deployment complete!${NC}"
echo "=========================================="
echo ""
echo "🌐 Your site should be live at:"
echo " https://blst.upleb.uk"
echo ""
echo "🧪 Quick checks:"
echo " curl -I https://blst.upleb.uk"
echo ""
echo "📋 If you see 403 errors, check permissions:"
echo " ssh $SERVER 'sudo chown -R www-data:www-data $REMOTE_PATH'"
echo ""
echo "🔄 To reload Nginx (if needed):"
echo " ssh $SERVER 'sudo systemctl reload nginx'"