ai_qc/backend/scripts/deploy-to-prod.sh
nickviljoen 3fec052c12 Create frontend and backend folder structure for deployment
Organized the application into separate frontend and backend directories for cleaner deployment and better separation of concerns.

Frontend Directory (frontend/):
- index.html: Single-page web interface (renamed from web_ui.html)
- README.md: Frontend deployment guide
- Total size: ~113 KB (self-contained)
- Smart base path detection (works at / or /ai_qc/)
- No configuration changes required

Backend Directory (backend/):
- All Python files (api_server.py, llm_config.py, etc.)
- visual_qc_apps/: 33 QC check modules
- profiles/: 6 QC profile configurations
- brand_guidelines/: Reference asset storage
- config/: Environment configurations
- scripts/: Deployment automation
- uploads/, output/: Data directories
- requirements.txt, ai_qc.service, apache_config.conf
- Complete documentation

New Documentation:
- FOLDER_STRUCTURE.md: Comprehensive guide to new structure
- frontend/README.md: Frontend deployment instructions
- backend/BACKEND_README.md: Backend deployment guide

Deployment Mapping:
- frontend/ → /var/www/html/ai_qc/ (web root)
- backend/ → /opt/ai_qc/ (application directory)

Benefits:
- Clear separation of concerns
- Backend code not in web-accessible directory
- Independent frontend/backend updates
- Matches server's existing patterns (/opt/veo3, /opt/voice2text)
- Industry-standard architecture
- Easy to deploy and maintain

Original files preserved in root directory for reference.
Ready for production deployment following MIGRATION_GUIDE.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 11:55:53 +02:00

117 lines
No EOL
3.4 KiB
Bash
Executable file

#!/bin/bash
# Script to deploy Visual AI QC application to production server
set -e # Exit on any error
echo "==========================================="
echo " Visual AI QC - Production Deployment"
echo "==========================================="
# Configuration - UPDATE THESE VALUES FOR YOUR SERVER
PROD_SERVER="your-server-ip-or-domain"
PROD_USER="your-username"
PROD_PATH="/path/to/production/ai_qc"
BACKUP_PATH="/path/to/backups"
# Get the script directory and app root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="$(dirname "$SCRIPT_DIR")"
echo "Local app directory: $APP_DIR"
echo "Production server: $PROD_USER@$PROD_SERVER:$PROD_PATH"
# Change to app directory
cd "$APP_DIR"
# Run pre-deployment tests
echo ""
echo "Step 1: Running pre-deployment tests..."
if [ -f "scripts/test-system.sh" ]; then
bash scripts/test-system.sh
if [ $? -ne 0 ]; then
echo "ERROR: Pre-deployment tests failed!"
exit 1
fi
echo "✅ All tests passed"
else
echo "Warning: No test script found, skipping tests"
fi
# Confirm deployment
echo ""
echo "Step 2: Deployment confirmation"
echo "This will deploy to: $PROD_USER@$PROD_SERVER:$PROD_PATH"
read -p "Continue with deployment? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
echo "Deployment cancelled"
exit 0
fi
# Create backup of production
echo ""
echo "Step 3: Creating production backup..."
BACKUP_NAME="backup_$(date +%Y%m%d_%H%M%S)"
ssh "$PROD_USER@$PROD_SERVER" "mkdir -p $BACKUP_PATH && cp -r $PROD_PATH $BACKUP_PATH/$BACKUP_NAME"
echo "✅ Backup created: $BACKUP_PATH/$BACKUP_NAME"
# Sync files to production (excluding development-specific files)
echo ""
echo "Step 4: Syncing files to production..."
rsync -avz --progress \
--exclude="uploads-dev/" \
--exclude="output-dev/" \
--exclude="config/development.env" \
--exclude="scripts/run-local.sh" \
--exclude="venv/" \
--exclude=".git/" \
--exclude="__pycache__/" \
--exclude="*.pyc" \
--exclude=".DS_Store" \
./ "$PROD_USER@$PROD_SERVER:$PROD_PATH/"
echo "✅ Files synced to production"
# Set production environment and restart service
echo ""
echo "Step 5: Configuring production environment..."
ssh "$PROD_USER@$PROD_SERVER" << 'EOF'
cd /path/to/production/ai_qc
# Set production environment
export ENVIRONMENT=production
# Ensure production folders exist
mkdir -p uploads output
# Install/update requirements
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
# Restart the service (adapt this command for your setup)
# Option 1: If using systemd
# sudo systemctl restart ai-qc
# Option 2: If using PM2
# pm2 restart ai-qc
# Option 3: If running directly (kill and restart)
# pkill -f "python.*api_server.py" || true
# nohup python api_server.py > server.log 2>&1 &
echo "Production service restarted"
EOF
# Verify deployment
echo ""
echo "Step 6: Verifying deployment..."
# Add health check here - ping the production server
# curl -f http://your-production-domain.com/api/health || echo "Warning: Health check failed"
echo ""
echo "🎉 Deployment completed successfully!"
echo "Backup location: $PROD_USER@$PROD_SERVER:$BACKUP_PATH/$BACKUP_NAME"
echo "Production URL: http://$PROD_SERVER"
echo ""
echo "If anything goes wrong, you can rollback with:"
echo "ssh $PROD_USER@$PROD_SERVER 'rm -rf $PROD_PATH && mv $BACKUP_PATH/$BACKUP_NAME $PROD_PATH'"