Skip to content

Commit

Permalink
fix: Update deployment script to handle sudo password via environment…
Browse files Browse the repository at this point in the history
… variable
  • Loading branch information
sudoshi committed Feb 22, 2025
1 parent 4488cb6 commit 3fe7f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ jobs:
git stash --include-untracked
git pull origin main
chmod +x deploy-production.sh
SUDO_ASKPASS=/bin/echo ./deploy-production.sh
export SUDO_PASSWORD="${{ secrets.SUDO_PASSWORD }}"
./deploy-production.sh
19 changes: 15 additions & 4 deletions deploy-production.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

# 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

Expand Down Expand Up @@ -34,7 +45,7 @@ npm install

# Build assets with proper permissions
log "Building assets..."
sudo -S chown -R www-data:www-data /var/www/Zephyrus/public/build
sudo_cmd chown -R www-data:www-data /var/www/Zephyrus/public/build
npm run build

# Clear caches
Expand All @@ -52,11 +63,11 @@ php artisan view:cache

# Update permissions
log "Updating permissions..."
sudo -S chown -R www-data:www-data /var/www/Zephyrus/storage
sudo -S chown -R www-data:www-data /var/www/Zephyrus/bootstrap/cache
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 -S systemctl restart php8.2-fpm
sudo_cmd systemctl restart php8.2-fpm

log "Deployment completed successfully!"

0 comments on commit 3fe7f5f

Please sign in to comment.