forked from syntaxbullet/aurorabot
feat: Introduce production Docker and CI/CD setup, removing internal documentation and agent workflows.
This commit is contained in:
131
shared/scripts/deploy.sh
Normal file
131
shared/scripts/deploy.sh
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Aurora Production Deployment Script
|
||||
# =============================================================================
|
||||
# Run this script to deploy the latest version of Aurora
|
||||
# Usage: bash deploy.sh
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
echo -e "${GREEN}╔══════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║ Aurora Deployment Script ║${NC}"
|
||||
echo -e "${GREEN}╚══════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
# =============================================================================
|
||||
# Pre-flight Checks
|
||||
# =============================================================================
|
||||
echo -e "${YELLOW}[1/5] Running pre-flight checks...${NC}"
|
||||
|
||||
# Check if .env exists
|
||||
if [ ! -f .env ]; then
|
||||
echo -e "${RED}Error: .env file not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Docker is running
|
||||
if ! docker info &>/dev/null; then
|
||||
echo -e "${RED}Error: Docker is not running${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Pre-flight checks passed"
|
||||
|
||||
# =============================================================================
|
||||
# Backup Database (optional but recommended)
|
||||
# =============================================================================
|
||||
echo -e "${YELLOW}[2/5] Creating database backup...${NC}"
|
||||
|
||||
BACKUP_DIR="$PROJECT_DIR/shared/db/backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
if docker ps | grep -q aurora_db; then
|
||||
BACKUP_FILE="$BACKUP_DIR/backup_$(date +%Y%m%d_%H%M%S).sql"
|
||||
docker exec aurora_db pg_dump -U "${DB_USER:-auroradev}" "${DB_NAME:-auroradev}" > "$BACKUP_FILE" 2>/dev/null || true
|
||||
if [ -f "$BACKUP_FILE" ] && [ -s "$BACKUP_FILE" ]; then
|
||||
echo -e " ${GREEN}✓${NC} Database backed up to: $BACKUP_FILE"
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} Database backup skipped (container not running or empty)"
|
||||
rm -f "$BACKUP_FILE"
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} Database backup skipped (container not running)"
|
||||
fi
|
||||
|
||||
# =============================================================================
|
||||
# Pull Latest Code (if using git)
|
||||
# =============================================================================
|
||||
echo -e "${YELLOW}[3/5] Pulling latest code...${NC}"
|
||||
|
||||
if [ -d .git ]; then
|
||||
git pull origin main 2>/dev/null || git pull origin master 2>/dev/null || echo " Skipping git pull"
|
||||
echo -e " ${GREEN}✓${NC} Code updated"
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} Not a git repository, skipping pull"
|
||||
fi
|
||||
|
||||
# =============================================================================
|
||||
# Build and Deploy
|
||||
# =============================================================================
|
||||
echo -e "${YELLOW}[4/5] Building and deploying containers...${NC}"
|
||||
|
||||
# Build the new image
|
||||
docker compose -f docker-compose.prod.yml build --no-cache
|
||||
|
||||
# Stop and remove old containers, start new ones
|
||||
docker compose -f docker-compose.prod.yml down
|
||||
docker compose -f docker-compose.prod.yml up -d
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Containers deployed"
|
||||
|
||||
# =============================================================================
|
||||
# Health Check
|
||||
# =============================================================================
|
||||
echo -e "${YELLOW}[5/5] Waiting for health checks...${NC}"
|
||||
|
||||
sleep 10
|
||||
|
||||
# Check container status
|
||||
if docker ps | grep -q "aurora_app.*healthy"; then
|
||||
echo -e " ${GREEN}✓${NC} aurora_app is healthy"
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} aurora_app health check pending (may take up to 60s)"
|
||||
fi
|
||||
|
||||
if docker ps | grep -q "aurora_db.*healthy"; then
|
||||
echo -e " ${GREEN}✓${NC} aurora_db is healthy"
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} aurora_db health check pending"
|
||||
fi
|
||||
|
||||
# =============================================================================
|
||||
# Cleanup
|
||||
# =============================================================================
|
||||
echo ""
|
||||
echo -e "${YELLOW}Cleaning up old Docker images...${NC}"
|
||||
docker image prune -f
|
||||
|
||||
# =============================================================================
|
||||
# Summary
|
||||
# =============================================================================
|
||||
echo ""
|
||||
echo -e "${GREEN}╔══════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║ Deployment Complete! 🚀 ║${NC}"
|
||||
echo -e "${GREEN}╚══════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
echo -e "Container Status:"
|
||||
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep aurora
|
||||
echo ""
|
||||
echo -e "View logs with: ${YELLOW}docker logs -f aurora_app${NC}"
|
||||
Reference in New Issue
Block a user