74 lines
2.5 KiB
YAML
74 lines
2.5 KiB
YAML
name: Deploy to Production (Minified)
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Deploy to production server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.PROD_HOST }}
|
|
username: ${{ secrets.PROD_USERNAME }}
|
|
key: ${{ secrets.PROD_SSH_KEY }}
|
|
port: ${{ secrets.PROD_PORT || 22 }}
|
|
script: |
|
|
# Navigate to project directory
|
|
cd ${{ secrets.PROD_PROJECT_PATH || '/var/www/portal' }}
|
|
|
|
# Backup current deployment
|
|
echo "💾 Creating backup..."
|
|
cp -r . ../portal-backup-$(date +%Y%m%d_%H%M%S) || true
|
|
|
|
# Pull latest code
|
|
echo "🔄 Pulling latest code..."
|
|
git pull origin ${{ github.ref_name }}
|
|
|
|
# Install/Update Composer dependencies for production
|
|
echo "📦 Installing Composer dependencies..."
|
|
composer install --no-dev --optimize-autoloader --no-interaction
|
|
|
|
# Install/Update NPM dependencies
|
|
echo "📦 Installing NPM dependencies..."
|
|
npm ci --only=production
|
|
|
|
# Build and minify assets
|
|
echo "🏗️ Building and minifying assets..."
|
|
npm run minify-all
|
|
|
|
# Run database migrations (if needed)
|
|
echo "🗃️ Running database migrations..."
|
|
php artisan migrate --force
|
|
|
|
# Laravel optimizations for production
|
|
echo "⚡ Optimizing Laravel for production..."
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
php artisan optimize
|
|
|
|
# Clear all caches
|
|
echo "🧹 Clearing caches..."
|
|
php artisan cache:clear
|
|
php artisan view:clear
|
|
php artisan config:clear
|
|
|
|
# Queue restart (if using queues)
|
|
echo "🔄 Restarting queues..."
|
|
php artisan queue:restart || true
|
|
|
|
# Set proper permissions
|
|
echo "🔐 Setting permissions..."
|
|
chmod -R 755 storage bootstrap/cache public/uploads
|
|
chown -R www-data:www-data storage bootstrap/cache public/uploads
|
|
|
|
# Cleanup old backups (keep last 5)
|
|
echo "🧹 Cleaning up old backups..."
|
|
find ../portal-backup-* -maxdepth 0 -type d | sort | head -n -5 | xargs rm -rf || true
|
|
|
|
echo "✅ Production deployment completed successfully!" |