templave v1
This commit is contained in:
75
deploy/scripts/deploy.sh
Normal file
75
deploy/scripts/deploy.sh
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Laravel Deployment Script
|
||||
# Usage: ./deploy.sh /var/www/your-app [branch]
|
||||
|
||||
set -e
|
||||
|
||||
APP_PATH="${1:-/var/www/laravel}"
|
||||
BRANCH="${2:-main}"
|
||||
|
||||
if [ ! -d "$APP_PATH" ]; then
|
||||
echo "Error: Directory $APP_PATH does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$APP_PATH"
|
||||
|
||||
echo "=========================================="
|
||||
echo "Deploying Laravel Application"
|
||||
echo "Path: $APP_PATH"
|
||||
echo "Branch: $BRANCH"
|
||||
echo "=========================================="
|
||||
|
||||
# Enable maintenance mode
|
||||
echo "[1/9] Enabling maintenance mode..."
|
||||
php artisan down --retry=60 || true
|
||||
|
||||
# Pull latest code
|
||||
echo "[2/9] Pulling latest changes..."
|
||||
git fetch origin
|
||||
git reset --hard origin/$BRANCH
|
||||
|
||||
# Install PHP dependencies
|
||||
echo "[3/9] Installing Composer dependencies..."
|
||||
composer install --no-dev --optimize-autoloader --no-interaction
|
||||
|
||||
# Install and build frontend assets
|
||||
echo "[4/9] Installing Node dependencies..."
|
||||
npm ci --production=false
|
||||
|
||||
echo "[5/9] Building frontend assets..."
|
||||
npm run build
|
||||
|
||||
# Run migrations
|
||||
echo "[6/9] Running database migrations..."
|
||||
php artisan migrate --force
|
||||
|
||||
# Clear and optimize
|
||||
echo "[7/9] Optimizing application..."
|
||||
php artisan config:cache
|
||||
php artisan route:cache
|
||||
php artisan view:cache
|
||||
php artisan event:cache
|
||||
|
||||
# Fix permissions
|
||||
echo "[8/9] Fixing permissions..."
|
||||
sudo chown -R www-data:www-data storage bootstrap/cache
|
||||
sudo chmod -R 775 storage bootstrap/cache
|
||||
|
||||
# Restart services
|
||||
echo "[9/9] Restarting services..."
|
||||
sudo systemctl restart php8.3-fpm
|
||||
|
||||
# Restart queue workers if using Supervisor
|
||||
if [ -f /etc/supervisor/conf.d/laravel-worker.conf ]; then
|
||||
sudo supervisorctl restart laravel-worker:*
|
||||
fi
|
||||
|
||||
# Disable maintenance mode
|
||||
php artisan up
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "Deployment complete!"
|
||||
echo "=========================================="
|
||||
Reference in New Issue
Block a user