All checks were successful
Deploy to Production / test (push) Successful in 34s
The raw 'source .env' pattern breaks when values contain special bash characters like ) in passwords or database URLs. This caused deploy:remote to fail with 'syntax error near unexpected token )'. Changes: - Created shared/scripts/lib/load-env.sh: reads .env line-by-line with export instead of source, safely handling special characters - Updated db-backup.sh, db-restore.sh, deploy-remote.sh, remote.sh to use the shared loader - Reordered deploy-remote.sh: git pull now runs first (step 1) so the remote always has the latest scripts before running backup (step 2)
67 lines
2.3 KiB
Bash
Executable File
67 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# Aurora Remote Deployment Script
|
|
# =============================================================================
|
|
# Deploys the application to a remote VPS via SSH.
|
|
# Performs a database backup, pulls latest code, builds, and restarts services.
|
|
#
|
|
# Usage: ./deploy-remote.sh [--skip-backup]
|
|
# =============================================================================
|
|
|
|
set -e
|
|
|
|
# Load environment variables safely
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/lib/load-env.sh"
|
|
load_env
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
if [ -z "$VPS_HOST" ] || [ -z "$VPS_USER" ]; then
|
|
echo -e "${RED}Error: VPS_HOST and VPS_USER must be set in .env${NC}"
|
|
echo "Please add them to your .env file:"
|
|
echo "VPS_USER=your-username"
|
|
echo "VPS_HOST=your-ip-address"
|
|
exit 1
|
|
fi
|
|
|
|
# Default remote directory to ~/Aurora if not specified
|
|
REMOTE_DIR="${VPS_PROJECT_PATH:-~/Aurora}"
|
|
SKIP_BACKUP=false
|
|
|
|
if [[ "$1" == "--skip-backup" ]]; then
|
|
SKIP_BACKUP=true
|
|
fi
|
|
|
|
echo -e "${YELLOW}🚀 Deploying to $VPS_USER@$VPS_HOST:$REMOTE_DIR...${NC}"
|
|
|
|
# Step 1: Pull latest code (always first, so remote has the latest scripts)
|
|
echo -e "\n${YELLOW}⬇️ Step 1/4: Pulling latest changes...${NC}"
|
|
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && git pull"
|
|
|
|
# Step 2: Database backup (unless skipped)
|
|
if [ "$SKIP_BACKUP" = false ]; then
|
|
echo -e "\n${YELLOW}💾 Step 2/4: Backing up remote database...${NC}"
|
|
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && bash shared/scripts/db-backup.sh" || {
|
|
echo -e "${RED}⚠️ Backup failed. Aborting deployment.${NC}"
|
|
echo "Use --skip-backup to deploy without backing up."
|
|
exit 1
|
|
}
|
|
else
|
|
echo -e "\n${YELLOW}⏭️ Step 2/4: Skipping database backup (--skip-backup)${NC}"
|
|
fi
|
|
|
|
# Step 3: Build production containers
|
|
echo -e "\n${YELLOW}🏗️ Step 3/4: Building production containers...${NC}"
|
|
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && docker compose -f docker-compose.prod.yml build"
|
|
|
|
# Step 4: Restart services
|
|
echo -e "\n${YELLOW}🚀 Step 4/4: Starting services...${NC}"
|
|
ssh -t "$VPS_USER@$VPS_HOST" "cd $REMOTE_DIR && docker compose -f docker-compose.prod.yml up -d"
|
|
|
|
echo -e "\n${GREEN}✅ Deployment complete!${NC}"
|