-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-production.sh
executable file
·88 lines (69 loc) · 2.17 KB
/
deploy-production.sh
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
#!/bin/bash
# Deployment script for Zephyrus production environment
# Check if SUDO_PASSWORD is set
if [ -z "$SUDO_PASSWORD" ]; then
echo "Error: SUDO_PASSWORD environment variable is not set"
exit 1
fi
# Function to run sudo commands with password
sudo_cmd() {
echo "$SUDO_PASSWORD" | sudo -S $@
}
# Exit on error
set -e
# Function to log messages
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
}
# Check if we're in the correct directory
if [ ! -d "/var/www/Zephyrus" ]; then
log "Error: /var/www/Zephyrus directory not found"
exit 1
fi
cd /var/www/Zephyrus
# Stash any local changes
log "Stashing local changes..."
git stash --include-untracked
# Pull latest changes
log "Pulling latest changes..."
git pull origin main
# Ensure bootstrap/cache directory exists with correct permissions
log "Setting up bootstrap/cache directory..."
mkdir -p /var/www/Zephyrus/bootstrap/cache
sudo_cmd chown -R www-data:www-data /var/www/Zephyrus/bootstrap/cache
sudo_cmd chmod -R 775 /var/www/Zephyrus/bootstrap/cache
# Install/update PHP dependencies
log "Installing PHP dependencies..."
composer install --no-interaction --prefer-dist --optimize-autoloader
# Install/update Node dependencies
log "Installing Node dependencies..."
npm install
# Build assets with proper permissions
log "Setting up build directory..."
# Create build directory if it doesn't exist
mkdir -p /var/www/Zephyrus/public/build
# Set permissions before building
sudo_cmd chown -R $(whoami):$(whoami) /var/www/Zephyrus/public/build
log "Building assets..."
npm run build
# Reset permissions after build
sudo_cmd chown -R www-data:www-data /var/www/Zephyrus/public/build
# Clear caches
log "Clearing caches..."
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
# Optimize
log "Optimizing..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Update permissions
log "Updating permissions..."
sudo_cmd chown -R www-data:www-data /var/www/Zephyrus/storage
sudo_cmd chown -R www-data:www-data /var/www/Zephyrus/bootstrap/cache
# Restart PHP-FPM
log "Restarting PHP-FPM..."
sudo_cmd systemctl restart php8.2-fpm
log "Deployment completed successfully!"