sawa-control-panel/deploy.sh

49 lines
1.2 KiB
Bash

#!/bin/sh
# deploy.sh — Build and deploy Sawa Control Panel to the server
# Exit on any error
set -e
# Load environment variables from .env
if [ -f .env ]; then
set -a
. ./.env
set +a
else
echo "FAIL: .env file not found in project root."
exit 1
fi
if [ -z "$SERVER_IP" ]; then
echo "FAIL: SERVER_IP not set in .env."
exit 1
fi
echo "Step 1: Building frontend app..."
if (cd frontend && npm run build); then
echo "PASS: Frontend built successfully."
else
echo "FAIL: Frontend build failed."
exit 1
fi
echo "Step 2: Deploying static files to $SERVER_IP..."
# Note: This assumes SSH key-based auth to root is configured
if scp -r frontend/dist/* root@$SERVER_IP:/var/www/panel/; then
echo "PASS: Frontend deployed successfully."
else
echo "FAIL: Frontend deployment failed."
exit 1
fi
echo "Step 3: Restarting backend API via PM2..."
if ssh root@$SERVER_IP "pm2 restart panel-api"; then
echo "PASS: Backend API restarted successfully."
else
echo "FAIL: Backend API restart failed."
exit 1
fi
echo "--------------------------------------------------"
echo "DEPLOYMENT COMPLETE ✅"
echo "--------------------------------------------------"