rackham-meeting-analyzer/deploy.sh
2025-11-03 16:02:54 -06:00

269 lines
7.9 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
print_header() {
echo -e "\n${BLUE}===================================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}===================================================${NC}\n"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
print_info() {
echo -e "${BLUE} $1${NC}"
}
# Main deployment script
print_header "BTG Rackham Video Sales Coach - Deployment Script v2.0"
# 1. Check prerequisites
print_header "Step 1: Checking Prerequisites"
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
echo "Visit: https://docs.docker.com/get-docker/"
exit 1
fi
print_success "Docker is installed: $(docker --version)"
# Check for docker compose (modern) or docker-compose (legacy)
if docker compose version &> /dev/null; then
DOCKER_COMPOSE="docker compose"
print_success "Docker Compose is installed: $(docker compose version)"
elif command -v docker-compose &> /dev/null; then
DOCKER_COMPOSE="docker-compose"
print_success "Docker Compose is installed: $(docker-compose --version)"
else
print_error "Docker Compose is not installed. Please install Docker Compose first."
echo "Visit: https://docs.docker.com/compose/install/"
exit 1
fi
# 2. Get deployment directory
print_header "Step 2: Deployment Location"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
print_info "Application directory: $SCRIPT_DIR"
# 3. Check if .env exists
print_header "Step 3: Environment Configuration"
ENV_FILE="$SCRIPT_DIR/infra/.env"
if [ -f "$ENV_FILE" ]; then
print_warning "Environment file already exists at: $ENV_FILE"
read -p "Do you want to reconfigure it? (y/N): " RECONFIGURE
if [[ ! $RECONFIGURE =~ ^[Yy]$ ]]; then
print_info "Keeping existing .env file"
SKIP_ENV_SETUP=true
fi
fi
if [ "$SKIP_ENV_SETUP" != true ]; then
# Copy example if it doesn't exist
if [ ! -f "$ENV_FILE" ]; then
if [ -f "$SCRIPT_DIR/infra/.env.example" ]; then
cp "$SCRIPT_DIR/infra/.env.example" "$ENV_FILE"
print_success "Created .env file from template"
else
print_error ".env.example not found. Creating basic .env file..."
cat > "$ENV_FILE" << 'EOF'
MONGO_URL=mongodb://mongo:27017/btg
GEMINI_API_KEY=
GEMINI_MODEL=gemini-2.5-pro
JWT_SECRET=
CORS_ORIGINS=http://localhost:3000,http://localhost:8080
MAX_UPLOAD_SIZE_GB=2
CHUNK_SIZE_MB=10
DATA_RETENTION_DAYS=90
EOF
print_success "Created basic .env file"
fi
fi
# Prompt for required values
echo ""
print_info "Please provide the following required values:"
echo ""
# Get Gemini API Key
read -p "Enter your Gemini API Key: " GEMINI_KEY
if [ -z "$GEMINI_KEY" ]; then
print_error "Gemini API Key is required!"
echo "Get one at: https://aistudio.google.com/app/apikey"
exit 1
fi
# Generate JWT Secret
print_info "Generating secure JWT secret..."
JWT_SECRET=$(openssl rand -base64 32)
print_success "Generated JWT secret"
# Get server hostname for CORS
HOSTNAME=$(hostname -f 2>/dev/null || hostname)
read -p "Enter your server domain/hostname (default: $HOSTNAME): " DOMAIN
DOMAIN=${DOMAIN:-$HOSTNAME}
# Update .env file
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s|GEMINI_API_KEY=.*|GEMINI_API_KEY=$GEMINI_KEY|" "$ENV_FILE"
sed -i '' "s|JWT_SECRET=.*|JWT_SECRET=$JWT_SECRET|" "$ENV_FILE"
sed -i '' "s|CORS_ORIGINS=.*|CORS_ORIGINS=http://localhost:3000,http://$DOMAIN,https://$DOMAIN|" "$ENV_FILE"
else
# Linux
sed -i "s|GEMINI_API_KEY=.*|GEMINI_API_KEY=$GEMINI_KEY|" "$ENV_FILE"
sed -i "s|JWT_SECRET=.*|JWT_SECRET=$JWT_SECRET|" "$ENV_FILE"
sed -i "s|CORS_ORIGINS=.*|CORS_ORIGINS=http://localhost:3000,http://$DOMAIN,https://$DOMAIN|" "$ENV_FILE"
fi
print_success "Environment file configured"
echo ""
print_info "Configuration saved to: $ENV_FILE"
fi
# 4. Create data directories
print_header "Step 4: Creating Data Directories"
sudo mkdir -p /data/videos
sudo mkdir -p /tmp/chunks
sudo chown -R $USER:$USER /data/videos /tmp/chunks
print_success "Data directories created and permissions set"
# 5. Stop any existing containers
print_header "Step 5: Stopping Existing Containers"
cd "$SCRIPT_DIR/infra"
if $DOCKER_COMPOSE ps | grep -q "Up"; then
print_info "Stopping existing containers..."
$DOCKER_COMPOSE down
print_success "Existing containers stopped"
else
print_info "No existing containers running"
fi
# 6. Build containers
print_header "Step 6: Building Docker Containers"
print_info "This may take 5-10 minutes on first build..."
$DOCKER_COMPOSE build
if [ $? -eq 0 ]; then
print_success "Docker containers built successfully"
else
print_error "Docker build failed. Check the output above for errors."
exit 1
fi
# 7. Start containers
print_header "Step 7: Starting Services"
$DOCKER_COMPOSE up -d
if [ $? -eq 0 ]; then
print_success "Services started successfully"
else
print_error "Failed to start services. Check logs with: $DOCKER_COMPOSE logs"
exit 1
fi
# 8. Wait for services to be ready
print_header "Step 8: Waiting for Services to Initialize"
print_info "Waiting 15 seconds for services to start..."
sleep 15
# 9. Verify deployment
print_header "Step 9: Verifying Deployment"
# Check container status
echo ""
print_info "Container Status:"
$DOCKER_COMPOSE ps
echo ""
# Check backend
if curl -s http://localhost:8080/docs > /dev/null 2>&1; then
print_success "Backend is responding on port 8080"
else
print_warning "Backend may not be ready yet. Check logs: docker-compose logs backend"
fi
# Check frontend
if curl -s http://localhost:3000 > /dev/null 2>&1; then
print_success "Frontend is responding on port 3000"
else
print_warning "Frontend may not be ready yet. Check logs: docker-compose logs frontend"
fi
# Check MongoDB
if docker exec infra-mongo-1 mongosh btg --quiet --eval "db.runCommand({ ping: 1 }).ok" 2>/dev/null | grep -q "1"; then
print_success "MongoDB is running and accessible"
else
print_warning "MongoDB may not be ready yet. Check logs: docker-compose logs mongo"
fi
# 10. Display summary
print_header "🎉 Deployment Complete!"
echo ""
echo -e "${GREEN}The BTG Rackham Video Sales Coach is now running!${NC}"
echo ""
echo "Access URLs:"
echo " - Frontend: http://localhost:3000"
echo " - Backend: http://localhost:8080"
echo " - API Docs: http://localhost:8080/docs"
echo ""
if [ -n "$DOMAIN" ] && [ "$DOMAIN" != "localhost" ]; then
echo "Once you configure Apache proxy, access via:"
echo " - http://$DOMAIN"
echo " - https://$DOMAIN (if SSL configured)"
echo ""
fi
echo "Useful Commands:"
echo " - View all logs: cd $SCRIPT_DIR/infra && $DOCKER_COMPOSE logs -f"
echo " - View backend logs: cd $SCRIPT_DIR/infra && $DOCKER_COMPOSE logs -f backend"
echo " - Restart services: cd $SCRIPT_DIR/infra && $DOCKER_COMPOSE restart"
echo " - Stop services: cd $SCRIPT_DIR/infra && $DOCKER_COMPOSE down"
echo ""
print_info "Next Steps:"
echo " 1. Open http://localhost:3000 in your browser"
echo " 2. Create your first user account"
echo " 3. Upload a test video (5-10 min recommended)"
echo " 4. Review the analysis results"
echo " 5. Configure Apache proxy for production access (optional)"
echo ""
print_warning "IMPORTANT: Make sure to backup your .env file - it contains sensitive credentials!"
echo ""
# Create a backup of .env
ENV_BACKUP="$SCRIPT_DIR/infra/.env.backup-$(date +%Y%m%d-%H%M%S)"
cp "$ENV_FILE" "$ENV_BACKUP"
print_success "Backup of .env created at: $ENV_BACKUP"
echo ""
print_success "Deployment completed successfully! 🚀"
echo ""