-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio-build-deploy.sh
More file actions
82 lines (69 loc) · 2.54 KB
/
portfolio-build-deploy.sh
File metadata and controls
82 lines (69 loc) · 2.54 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
#!/bin/bash
# 11jon.com Portfolio - Build & Deploy Script
# Nginx Static Build für React/Vite
set -e
echo "🚀 Starting 11jon.com Portfolio Build & Deployment"
echo "=================================================="
# Variables
DOMAIN="11jon.com"
WEBROOT="/var/www/11jon.com/html"
PROJECT_DIR="$(pwd)"
BUILD_DIR="$PROJECT_DIR/dist"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Step 1: Install Dependencies
echo -e "${BLUE}[1/6]${NC} Installing dependencies..."
npm install
echo -e "${GREEN}✓ Dependencies installed${NC}\n"
# Step 2: Build Vite Project
echo -e "${BLUE}[2/6]${NC} Building React/Vite project..."
npm run build
echo -e "${GREEN}✓ Build complete (dist/ created)${NC}\n"
# Step 3: Backup existing site
if [ -d "$WEBROOT" ] && [ "$(ls -A $WEBROOT)" ]; then
echo -e "${BLUE}[3/6]${NC} Backing up current site..."
BACKUP_DIR="$WEBROOT.backup.$(date +%Y%m%d_%H%M%S)"
cp -r "$WEBROOT" "$BACKUP_DIR"
echo -e "${GREEN}✓ Backup created: $BACKUP_DIR${NC}\n"
else
echo -e "${BLUE}[3/6]${NC} Creating webroot directory..."
mkdir -p "$WEBROOT"
echo -e "${GREEN}✓ Directory created${NC}\n"
fi
# Step 4: Deploy to Nginx
echo -e "${BLUE}[4/6]${NC} Deploying to $WEBROOT..."
rm -rf "$WEBROOT"/*
cp -r "$BUILD_DIR"/* "$WEBROOT/"
echo -e "${GREEN}✓ Files deployed${NC}\n"
# Step 5: Set permissions
echo -e "${BLUE}[5/6]${NC} Setting permissions..."
chown -R www-data:www-data "$WEBROOT"
chmod -R 755 "$WEBROOT"
echo -e "${GREEN}✓ Permissions set${NC}\n"
# Step 6: Verify and test
echo -e "${BLUE}[6/6]${NC} Verifying deployment..."
if [ -f "$WEBROOT/index.html" ]; then
echo -e "${GREEN}✓ index.html found${NC}"
echo -e "${GREEN}✓ Build complete and deployed!${NC}\n"
# Show site info
echo -e "${YELLOW}📍 Portfolio Live at: https://$DOMAIN${NC}"
echo -e "${YELLOW}📁 Web Root: $WEBROOT${NC}"
echo -e "${YELLOW}🔄 Backup: $BACKUP_DIR${NC}\n"
# Test with curl
echo -e "${BLUE}Testing homepage...${NC}"
if command -v curl &> /dev/null; then
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$DOMAIN)
echo -e "${GREEN}✓ HTTP Status: $STATUS${NC}"
fi
else
echo -e "\033[0;31m✗ Deployment failed! index.html not found.${NC}"
exit 1
fi
echo -e "\n${GREEN}=== Deployment Complete ===${NC}"
echo -e "Next steps:"
echo -e "1. Test: ${BLUE}curl https://$DOMAIN${NC}"
echo -e "2. Monitor: ${BLUE}tail -f /var/log/nginx/access.log${NC}"
echo -e "3. Reload Nginx (if needed): ${BLUE}sudo systemctl reload nginx${NC}"