#!/bin/bash # Quick Deploy Script for Datacenter Documentation System # Usage: ./quick-deploy.sh [local|docker|kubernetes] set -e COLOR_GREEN='\033[0;32m' COLOR_BLUE='\033[0;34m' COLOR_RED='\033[0;31m' COLOR_YELLOW='\033[1;33m' COLOR_NC='\033[0m' print_info() { echo -e "${COLOR_BLUE}[INFO]${COLOR_NC} $1" } print_success() { echo -e "${COLOR_GREEN}[SUCCESS]${COLOR_NC} $1" } print_error() { echo -e "${COLOR_RED}[ERROR]${COLOR_NC} $1" } print_warning() { echo -e "${COLOR_YELLOW}[WARNING]${COLOR_NC} $1" } print_header() { echo "" echo -e "${COLOR_GREEN}================================================${COLOR_NC}" echo -e "${COLOR_GREEN}$1${COLOR_NC}" echo -e "${COLOR_GREEN}================================================${COLOR_NC}" echo "" } check_requirements() { print_header "Checking Requirements" local missing_deps=0 # Check Python if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 --version | cut -d' ' -f2) print_success "Python: $PYTHON_VERSION" else print_error "Python 3.10+ required" missing_deps=1 fi # Check Poetry if command -v poetry &> /dev/null; then POETRY_VERSION=$(poetry --version | cut -d' ' -f3) print_success "Poetry: $POETRY_VERSION" else print_warning "Poetry not found. Installing..." curl -sSL https://install.python-poetry.org | python3 - export PATH="$HOME/.local/bin:$PATH" fi # Check Docker (if docker mode) if [[ "$1" == "docker" || "$1" == "kubernetes" ]]; then if command -v docker &> /dev/null; then DOCKER_VERSION=$(docker --version | cut -d' ' -f3) print_success "Docker: $DOCKER_VERSION" else print_error "Docker required for docker/kubernetes deployment" missing_deps=1 fi fi # Check kubectl (if kubernetes mode) if [[ "$1" == "kubernetes" ]]; then if command -v kubectl &> /dev/null; then KUBECTL_VERSION=$(kubectl version --client --short 2>/dev/null) print_success "kubectl: $KUBECTL_VERSION" else print_error "kubectl required for kubernetes deployment" missing_deps=1 fi fi if [[ $missing_deps -eq 1 ]]; then print_error "Missing required dependencies. Please install them first." exit 1 fi } setup_environment() { print_header "Setting Up Environment" if [[ ! -f .env ]]; then print_info "Creating .env from template..." cp .env.example .env print_warning "Please edit .env file with your credentials:" echo " - MCP_SERVER_URL" echo " - MCP_API_KEY" echo " - ANTHROPIC_API_KEY" echo " - Database passwords" echo "" read -p "Press Enter after editing .env file..." else print_success ".env file already exists" fi } deploy_local() { print_header "Deploying Locally (Development Mode)" # Install dependencies print_info "Installing Python dependencies..." poetry install # Start dependencies with Docker print_info "Starting MongoDB and Redis..." docker-compose up -d mongodb redis # Wait for services print_info "Waiting for services to be ready..." sleep 10 # Run migrations print_info "Running database migrations..." poetry run echo "MongoDB - no migrations needed" # Index documentation print_info "Indexing documentation..." if [[ -d ./output ]]; then poetry run python -m datacenter_docs.cli index-docs --path ./output else print_warning "No documentation found in ./output, skipping indexing" fi print_success "Local deployment complete!" echo "" print_info "Start services:" echo " API: poetry run uvicorn datacenter_docs.api.main:app --reload" echo " Chat: poetry run python -m datacenter_docs.chat.server" echo " Worker: poetry run celery -A datacenter_docs.workers.celery_app worker --loglevel=info" } deploy_docker() { print_header "Deploying with Docker Compose" # Build and start all services print_info "Building Docker images..." docker-compose build print_info "Starting all services..." docker-compose up -d # Wait for services print_info "Waiting for services to be ready..." sleep 30 # Check health print_info "Checking API health..." for i in {1..10}; do if curl -f http://localhost:8000/health &> /dev/null; then print_success "API is healthy!" break fi if [[ $i -eq 10 ]]; then print_error "API failed to start. Check logs: docker-compose logs api" exit 1 fi sleep 3 done # Run migrations print_info "Running database migrations..." docker-compose exec -T api poetry run echo "MongoDB - no migrations needed" print_success "Docker deployment complete!" echo "" print_info "Services available at:" echo " API: http://localhost:8000/api/docs" echo " Chat: http://localhost:8001" echo " Frontend: http://localhost" echo " Flower: http://localhost:5555" echo "" print_info "View logs: docker-compose logs -f" } deploy_kubernetes() { print_header "Deploying to Kubernetes" # Check if namespace exists if kubectl get namespace datacenter-docs &> /dev/null; then print_info "Namespace datacenter-docs already exists" else print_info "Creating namespace..." kubectl apply -f deploy/kubernetes/namespace.yaml fi # Check if secrets exist if kubectl get secret datacenter-secrets -n datacenter-docs &> /dev/null; then print_info "Secrets already exist" else print_warning "Creating secrets..." print_info "You need to provide:" read -p " Database URL: " DB_URL read -s -p " Redis URL: " REDIS_URL echo "" read -s -p " MCP API Key: " MCP_KEY echo "" read -s -p " Anthropic API Key: " ANTHROPIC_KEY echo "" kubectl create secret generic datacenter-secrets \ --from-literal=database-url="$DB_URL" \ --from-literal=redis-url="$REDIS_URL" \ --from-literal=mcp-api-key="$MCP_KEY" \ --from-literal=anthropic-api-key="$ANTHROPIC_KEY" \ -n datacenter-docs fi # Apply manifests print_info "Applying Kubernetes manifests..." kubectl apply -f deploy/kubernetes/deployment.yaml kubectl apply -f deploy/kubernetes/service.yaml kubectl apply -f deploy/kubernetes/ingress.yaml # Wait for deployment print_info "Waiting for deployments to be ready..." kubectl rollout status deployment/api -n datacenter-docs --timeout=5m kubectl rollout status deployment/chat -n datacenter-docs --timeout=5m kubectl rollout status deployment/worker -n datacenter-docs --timeout=5m print_success "Kubernetes deployment complete!" echo "" print_info "Check status:" echo " kubectl get pods -n datacenter-docs" echo " kubectl logs -n datacenter-docs deployment/api" } show_usage() { echo "Usage: $0 [local|docker|kubernetes]" echo "" echo "Deployment modes:" echo " local - Local development with Poetry (recommended for dev)" echo " docker - Docker Compose (recommended for testing/staging)" echo " kubernetes - Kubernetes cluster (recommended for production)" echo "" echo "Examples:" echo " $0 local # Deploy locally for development" echo " $0 docker # Deploy with Docker Compose" echo " $0 kubernetes # Deploy to Kubernetes" } # Main script if [[ $# -eq 0 ]]; then show_usage exit 1 fi MODE=$1 case $MODE in local) check_requirements local setup_environment deploy_local ;; docker) check_requirements docker setup_environment deploy_docker ;; kubernetes) check_requirements kubernetes deploy_kubernetes ;; *) print_error "Unknown deployment mode: $MODE" show_usage exit 1 ;; esac print_header "Deployment Complete! 🚀" print_success "System is ready to use" echo "" print_info "Next steps:" echo " 1. Test API: curl http://localhost:8000/health" echo " 2. Access documentation: http://localhost:8000/api/docs" echo " 3. Start using the chat interface" echo " 4. Submit test tickets via API" echo "" print_info "For support: automation-team@company.local"