Some checks failed
CI/CD Pipeline / Backend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Frontend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Build Backend (push) Has been cancelled
CI/CD Pipeline / Build Frontend (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Performance Tests (push) Has been cancelled
CI/CD Pipeline / Dependency Updates (push) Has been cancelled
- Updated Anthropic API to latest version (2024-01-01) - Set Claude 3.7 Sonnet Latest as primary model - Removed deprecated Opus 3.5 references - Fixed LLM response validation and JSON parsing - Improved error handling and logging - Updated model configurations and pricing - Enhanced document processing reliability - Fixed TypeScript type issues - Updated environment configuration
417 lines
13 KiB
Bash
Executable File
417 lines
13 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 🏭 **Production Migration & Deployment Script**
|
|
# Safely migrates tested features from testing to production environment
|
|
|
|
set -e # Exit on any error
|
|
|
|
echo "🏭 Starting Production Migration & Deployment..."
|
|
echo "📅 Migration Date: $(date)"
|
|
echo "🔒 Production Environment: cim-summarizer"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
PURPLE='\033[0;35m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_step() {
|
|
echo -e "${PURPLE}[STEP]${NC} $1"
|
|
}
|
|
|
|
# Configuration
|
|
PRODUCTION_PROJECT_ID="cim-summarizer"
|
|
TESTING_PROJECT_ID="cim-summarizer-testing"
|
|
BACKEND_DIR="backend"
|
|
FRONTEND_DIR="frontend"
|
|
|
|
print_status "Configuration:"
|
|
echo " - Production Project ID: $PRODUCTION_PROJECT_ID"
|
|
echo " - Testing Project ID: $TESTING_PROJECT_ID"
|
|
echo " - Backend Directory: $BACKEND_DIR"
|
|
echo " - Frontend Directory: $FRONTEND_DIR"
|
|
|
|
# Check if we're in the right directory
|
|
if [ ! -f "IMPROVEMENT_ROADMAP.md" ]; then
|
|
print_error "Please run this script from the project root directory"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Firebase CLI is installed
|
|
if ! command -v firebase &> /dev/null; then
|
|
print_error "Firebase CLI is not installed. Please install it first:"
|
|
echo " npm install -g firebase-tools"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if we're logged into Firebase
|
|
if ! firebase projects:list &> /dev/null; then
|
|
print_error "Not logged into Firebase. Please login first:"
|
|
echo " firebase login"
|
|
exit 1
|
|
fi
|
|
|
|
# Function to run pre-migration checks
|
|
run_pre_migration_checks() {
|
|
print_step "Running Pre-Migration Checks..."
|
|
|
|
# Check if testing environment is working
|
|
print_status "Checking testing environment health..."
|
|
TESTING_HEALTH=$(curl -s "https://$TESTING_PROJECT_ID.web.app/health" || echo "Failed")
|
|
|
|
if [[ $TESTING_HEALTH == *"healthy"* ]] || [[ $TESTING_HEALTH == *"ok"* ]]; then
|
|
print_success "Testing environment is healthy"
|
|
else
|
|
print_warning "Testing environment health check failed: $TESTING_HEALTH"
|
|
read -p "Continue anyway? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
print_error "Migration cancelled"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Check if production environment files exist
|
|
print_status "Checking production environment files..."
|
|
|
|
if [ ! -f "$BACKEND_DIR/.env.production" ]; then
|
|
print_error "Production environment file not found: $BACKEND_DIR/.env.production"
|
|
echo "Please create it based on your production configuration"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$FRONTEND_DIR/.env.production" ]; then
|
|
print_error "Production environment file not found: $FRONTEND_DIR/.env.production"
|
|
echo "Please create it based on your production configuration"
|
|
exit 1
|
|
fi
|
|
|
|
print_success "Production environment files found"
|
|
|
|
# Check if we can access production Firebase project
|
|
print_status "Checking production Firebase project access..."
|
|
if firebase projects:list | grep -q "$PRODUCTION_PROJECT_ID"; then
|
|
print_success "Production Firebase project accessible"
|
|
else
|
|
print_error "Cannot access production Firebase project: $PRODUCTION_PROJECT_ID"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to backup current production
|
|
backup_production() {
|
|
print_step "Creating Production Backup..."
|
|
|
|
# Create backup branch
|
|
BACKUP_BRANCH="backup-production-$(date +%Y%m%d-%H%M%S)"
|
|
print_status "Creating backup branch: $BACKUP_BRANCH"
|
|
|
|
git checkout -b "$BACKUP_BRANCH"
|
|
git add .
|
|
git commit -m "Backup: Production state before migration $(date)"
|
|
|
|
print_success "Production backup created in branch: $BACKUP_BRANCH"
|
|
|
|
# Return to main branch
|
|
git checkout preview-capabilities-phase1-2
|
|
}
|
|
|
|
# Function to switch to production environment
|
|
switch_to_production() {
|
|
print_step "Switching to Production Environment..."
|
|
|
|
# Switch backend to production
|
|
cd $BACKEND_DIR
|
|
if [ -f .env.production ]; then
|
|
cp .env.production .env
|
|
print_success "Backend environment switched to production"
|
|
else
|
|
print_error "Backend .env.production file not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Switch Firebase project to production
|
|
if firebase use production &> /dev/null; then
|
|
print_success "Firebase project switched to production"
|
|
else
|
|
print_error "Failed to switch to production Firebase project"
|
|
exit 1
|
|
fi
|
|
cd ..
|
|
|
|
# Switch frontend to production
|
|
cd $FRONTEND_DIR
|
|
if [ -f .env.production ]; then
|
|
cp .env.production .env
|
|
print_success "Frontend environment switched to production"
|
|
else
|
|
print_error "Frontend .env.production file not found"
|
|
exit 1
|
|
fi
|
|
|
|
# Switch Firebase project to production
|
|
if firebase use production &> /dev/null; then
|
|
print_success "Firebase project switched to production"
|
|
else
|
|
print_error "Failed to switch to production Firebase project"
|
|
exit 1
|
|
fi
|
|
cd ..
|
|
}
|
|
|
|
# Function to run production tests
|
|
run_production_tests() {
|
|
print_step "Running Production Tests..."
|
|
|
|
# Backend tests
|
|
print_status "Running backend tests..."
|
|
cd $BACKEND_DIR
|
|
npm test
|
|
cd ..
|
|
|
|
# Frontend tests
|
|
print_status "Running frontend tests..."
|
|
cd $FRONTEND_DIR
|
|
npm test
|
|
cd ..
|
|
|
|
print_success "All tests passed"
|
|
}
|
|
|
|
# Function to build for production
|
|
build_for_production() {
|
|
print_step "Building for Production..."
|
|
|
|
# Install dependencies
|
|
print_status "Installing backend dependencies..."
|
|
cd $BACKEND_DIR
|
|
npm install --production
|
|
print_success "Backend dependencies installed"
|
|
|
|
print_status "Installing frontend dependencies..."
|
|
cd ../$FRONTEND_DIR
|
|
npm install --production
|
|
print_success "Frontend dependencies installed"
|
|
cd ..
|
|
|
|
# Build backend
|
|
print_status "Building backend..."
|
|
cd $BACKEND_DIR
|
|
npm run build
|
|
print_success "Backend built successfully"
|
|
cd ..
|
|
|
|
# Build frontend
|
|
print_status "Building frontend..."
|
|
cd $FRONTEND_DIR
|
|
npm run build
|
|
print_success "Frontend built successfully"
|
|
cd ..
|
|
}
|
|
|
|
# Function to run database migrations
|
|
run_production_migrations() {
|
|
print_step "Running Production Database Migrations..."
|
|
|
|
cd $BACKEND_DIR
|
|
|
|
# Set environment to production
|
|
export NODE_ENV=production
|
|
|
|
# Run migrations
|
|
print_status "Running database migrations..."
|
|
npm run db:migrate
|
|
print_success "Database migrations completed"
|
|
|
|
cd ..
|
|
}
|
|
|
|
# Function to deploy to production
|
|
deploy_to_production() {
|
|
print_step "Deploying to Production..."
|
|
|
|
# Deploy Firebase Functions
|
|
print_status "Deploying Firebase Functions..."
|
|
firebase deploy --only functions --project $PRODUCTION_PROJECT_ID
|
|
print_success "Firebase Functions deployed"
|
|
|
|
# Deploy Firebase Hosting
|
|
print_status "Deploying Firebase Hosting..."
|
|
firebase deploy --only hosting --project $PRODUCTION_PROJECT_ID
|
|
print_success "Firebase Hosting deployed"
|
|
|
|
# Deploy Firebase Storage rules
|
|
print_status "Deploying Firebase Storage rules..."
|
|
firebase deploy --only storage --project $PRODUCTION_PROJECT_ID
|
|
print_success "Firebase Storage rules deployed"
|
|
}
|
|
|
|
# Function to verify production deployment
|
|
verify_production_deployment() {
|
|
print_step "Verifying Production Deployment..."
|
|
|
|
# Wait a moment for deployment to settle
|
|
sleep 10
|
|
|
|
# Test production health endpoint
|
|
print_status "Testing production health endpoint..."
|
|
PROD_HEALTH=$(curl -s "https://$PRODUCTION_PROJECT_ID.web.app/health" || echo "Failed")
|
|
|
|
if [[ $PROD_HEALTH == *"healthy"* ]] || [[ $PROD_HEALTH == *"ok"* ]]; then
|
|
print_success "Production health endpoint is working"
|
|
else
|
|
print_error "Production health endpoint test failed: $PROD_HEALTH"
|
|
return 1
|
|
fi
|
|
|
|
# Test production API endpoints
|
|
print_status "Testing production API endpoints..."
|
|
|
|
# Test cost monitoring endpoint (should require auth)
|
|
COST_RESPONSE=$(curl -s "https://$PRODUCTION_PROJECT_ID.web.app/api/cost/user-metrics" || echo "Failed")
|
|
if [[ $COST_RESPONSE == *"error"* ]] && [[ $COST_RESPONSE == *"not authenticated"* ]]; then
|
|
print_success "Production cost monitoring endpoint is working"
|
|
else
|
|
print_warning "Production cost monitoring endpoint test: $COST_RESPONSE"
|
|
fi
|
|
|
|
# Test cache management endpoint (should require auth)
|
|
CACHE_RESPONSE=$(curl -s "https://$PRODUCTION_PROJECT_ID.web.app/api/cache/stats" || echo "Failed")
|
|
if [[ $CACHE_RESPONSE == *"error"* ]] && [[ $CACHE_RESPONSE == *"not authenticated"* ]]; then
|
|
print_success "Production cache management endpoint is working"
|
|
else
|
|
print_warning "Production cache management endpoint test: $CACHE_RESPONSE"
|
|
fi
|
|
|
|
# Test microservice endpoint (should require auth)
|
|
MICROSERVICE_RESPONSE=$(curl -s "https://$PRODUCTION_PROJECT_ID.web.app/api/processing/health" || echo "Failed")
|
|
if [[ $MICROSERVICE_RESPONSE == *"error"* ]] && [[ $MICROSERVICE_RESPONSE == *"not authenticated"* ]]; then
|
|
print_success "Production microservice endpoint is working"
|
|
else
|
|
print_warning "Production microservice endpoint test: $MICROSERVICE_RESPONSE"
|
|
fi
|
|
}
|
|
|
|
# Function to show rollback instructions
|
|
show_rollback_instructions() {
|
|
print_step "Rollback Instructions..."
|
|
|
|
echo ""
|
|
print_warning "If you need to rollback to the previous production version:"
|
|
echo ""
|
|
echo "1. Switch to the backup branch:"
|
|
echo " git checkout $BACKUP_BRANCH"
|
|
echo ""
|
|
echo "2. Switch to production environment:"
|
|
echo " ./scripts/switch-environment.sh production"
|
|
echo ""
|
|
echo "3. Deploy the backup version:"
|
|
echo " firebase deploy --only functions,hosting,storage --project $PRODUCTION_PROJECT_ID"
|
|
echo ""
|
|
echo "4. Return to main branch:"
|
|
echo " git checkout preview-capabilities-phase1-2"
|
|
echo ""
|
|
}
|
|
|
|
# Main migration process
|
|
main() {
|
|
print_status "Starting Production Migration Process..."
|
|
|
|
# Confirm migration
|
|
echo ""
|
|
print_warning "This will deploy the current codebase to PRODUCTION environment."
|
|
print_warning "Make sure you have thoroughly tested in the testing environment."
|
|
echo ""
|
|
read -p "Are you sure you want to proceed with production deployment? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
print_error "Migration cancelled"
|
|
exit 1
|
|
fi
|
|
|
|
# Run pre-migration checks
|
|
run_pre_migration_checks
|
|
|
|
# Create production backup
|
|
backup_production
|
|
|
|
# Switch to production environment
|
|
switch_to_production
|
|
|
|
# Run production tests
|
|
run_production_tests
|
|
|
|
# Build for production
|
|
build_for_production
|
|
|
|
# Run database migrations
|
|
run_production_migrations
|
|
|
|
# Deploy to production
|
|
deploy_to_production
|
|
|
|
# Verify production deployment
|
|
if verify_production_deployment; then
|
|
print_success "Production deployment verified successfully!"
|
|
else
|
|
print_error "Production deployment verification failed!"
|
|
show_rollback_instructions
|
|
exit 1
|
|
fi
|
|
|
|
# Show rollback instructions
|
|
show_rollback_instructions
|
|
|
|
# Display final summary
|
|
echo ""
|
|
print_success "🎉 Production Migration Completed Successfully!"
|
|
echo ""
|
|
echo "📋 Migration Summary:"
|
|
echo " - Production Project ID: $PRODUCTION_PROJECT_ID"
|
|
echo " - Frontend URL: https://$PRODUCTION_PROJECT_ID.web.app"
|
|
echo " - API Base URL: https://$PRODUCTION_PROJECT_ID.web.app"
|
|
echo " - Backup Branch: $BACKUP_BRANCH"
|
|
echo ""
|
|
echo "🔧 Features Deployed:"
|
|
echo " ✅ Document Analysis Caching System"
|
|
echo " ✅ Real-time Cost Monitoring"
|
|
echo " ✅ Document Processing Microservice"
|
|
echo " ✅ Enhanced Security & Performance"
|
|
echo " ✅ Database Schema Updates"
|
|
echo ""
|
|
echo "📊 Monitoring:"
|
|
echo " - Firebase Console: https://console.firebase.google.com/project/$PRODUCTION_PROJECT_ID"
|
|
echo " - Functions Logs: firebase functions:log --project $PRODUCTION_PROJECT_ID"
|
|
echo " - Hosting Analytics: Available in Firebase Console"
|
|
echo ""
|
|
echo "🔍 Troubleshooting:"
|
|
echo " - Check logs: firebase functions:log --project $PRODUCTION_PROJECT_ID"
|
|
echo " - View functions: firebase functions:list --project $PRODUCTION_PROJECT_ID"
|
|
echo " - Rollback if needed: git checkout $BACKUP_BRANCH"
|
|
echo ""
|
|
|
|
print_success "Production migration completed successfully! 🚀"
|
|
}
|
|
|
|
# Run main function
|
|
main "$@"
|