-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·80 lines (66 loc) · 1.96 KB
/
deploy.sh
File metadata and controls
executable file
·80 lines (66 loc) · 1.96 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
#!/bin/bash
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
else
echo "Error: .env file not found!"
exit 1
fi
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "🚀 Starting Hugo deployment..."
# Clean old builds and cache
echo "🧹 Cleaning old builds and cache..."
rm -rf public resources .hugo_build.lock
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Cache cleared${NC}"
else
echo -e "${RED}⚠️ Warning: Could not clear cache${NC}"
fi
# Build Hugo site
echo "📦 Building Hugo site..."
# Create temporary config with GitHub token if available
HUGO_CONFIGS="hugo.toml"
if [ ! -z "$GITHUB_TOKEN" ]; then
echo "[params]" > .hugo_temp.toml
echo " githubToken = '$GITHUB_TOKEN'" >> .hugo_temp.toml
HUGO_CONFIGS="hugo.toml,.hugo_temp.toml"
echo "🔑 Using GitHub token for API access"
fi
hugo --config "$HUGO_CONFIGS" --environment $HUGO_ENV --minify --gc --cleanDestinationDir --buildFuture --buildDrafts -D
# Clean up temporary config
rm -f .hugo_temp.toml
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Hugo build failed!${NC}"
exit 1
fi
echo -e "${GREEN}✅ Hugo build successful${NC}"
# Deploy with rsync
echo "📤 Deploying to server..."
if [ ! -z "$SSH_KEY_PATH" ]; then
# Deploy using SSH key (recommended)
rsync -avz --delete \
-e "ssh -i $SSH_KEY_PATH -p $PORT" \
public/ \
$USER@$SERVER:$REMOTE_PATH
else
# Deploy using password (requires sshpass)
if [ ! -z "$PASSWORD" ]; then
rsync -avz --delete \
-e "sshpass -p '$PASSWORD' ssh -p $PORT" \
public/ \
$USER@$SERVER:$REMOTE_PATH
else
echo -e "${RED}❌ No authentication method specified!${NC}"
exit 1
fi
fi
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ Deployment successful!${NC}"
echo "🌐 Your site is live at: http://$SERVER"
else
echo -e "${RED}❌ Deployment failed!${NC}"
exit 1
fi