Spaces:
Paused
Paused
Download scripts/deploy.sh from VAH6002/ai_data_scientist: direct link, hf CLI and curl.
- Browser
- Download file 5.48 kB
-
https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/deploy.sh
- Command line
-
hf download hf://spaces/VAH6002/ai_data_scientist/scripts/deploy.sh
-
curl -L -o deploy.sh https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/deploy.sh
5.48 kB
| # MCP AI Data Scientist Deployment Script | |
| # Usage: ./scripts/deploy.sh [environment] [action] | |
| # Environment: dev, staging, prod | |
| # Action: build, up, down, restart, logs, health | |
| set -e | |
| # Configuration | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | |
| ENVIRONMENT=${1:-dev} | |
| ACTION=${2:-up} | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| # Logging functions | |
| log_info() { | |
| echo -e "${BLUE}[INFO]${NC} $1" | |
| } | |
| log_success() { | |
| echo -e "${GREEN}[SUCCESS]${NC} $1" | |
| } | |
| log_warning() { | |
| echo -e "${YELLOW}[WARNING]${NC} $1" | |
| } | |
| log_error() { | |
| echo -e "${RED}[ERROR]${NC} $1" | |
| } | |
| # Validate environment | |
| validate_environment() { | |
| case $ENVIRONMENT in | |
| dev|staging|prod) | |
| log_info "Deploying to $ENVIRONMENT environment" | |
| ;; | |
| *) | |
| log_error "Invalid environment: $ENVIRONMENT. Use dev, staging, or prod" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| # Check prerequisites | |
| check_prerequisites() { | |
| log_info "Checking prerequisites..." | |
| # Check Docker | |
| if ! command -v docker &> /dev/null; then | |
| log_error "Docker is not installed" | |
| exit 1 | |
| fi | |
| # Check Docker Compose | |
| if ! command -v docker-compose &> /dev/null; then | |
| log_error "Docker Compose is not installed" | |
| exit 1 | |
| fi | |
| # Check .env file | |
| if [ ! -f "$PROJECT_DIR/.env" ]; then | |
| log_error ".env file not found. Please create it from .env.example" | |
| exit 1 | |
| fi | |
| log_success "Prerequisites check passed" | |
| } | |
| # Build images | |
| build_images() { | |
| log_info "Building Docker images..." | |
| cd "$PROJECT_DIR" | |
| if [ "$ENVIRONMENT" = "dev" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.dev.yml build | |
| elif [ "$ENVIRONMENT" = "prod" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml build | |
| else | |
| docker-compose build | |
| fi | |
| log_success "Images built successfully" | |
| } | |
| # Start services | |
| start_services() { | |
| log_info "Starting services..." | |
| cd "$PROJECT_DIR" | |
| if [ "$ENVIRONMENT" = "dev" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d | |
| elif [ "$ENVIRONMENT" = "prod" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d | |
| else | |
| docker-compose up -d | |
| fi | |
| log_success "Services started successfully" | |
| } | |
| # Stop services | |
| stop_services() { | |
| log_info "Stopping services..." | |
| cd "$PROJECT_DIR" | |
| if [ "$ENVIRONMENT" = "dev" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.dev.yml down | |
| elif [ "$ENVIRONMENT" = "prod" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml down | |
| else | |
| docker-compose down | |
| fi | |
| log_success "Services stopped successfully" | |
| } | |
| # Restart services | |
| restart_services() { | |
| log_info "Restarting services..." | |
| stop_services | |
| start_services | |
| log_success "Services restarted successfully" | |
| } | |
| # Show logs | |
| show_logs() { | |
| log_info "Showing logs..." | |
| cd "$PROJECT_DIR" | |
| if [ "$ENVIRONMENT" = "dev" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.dev.yml logs -f | |
| elif [ "$ENVIRONMENT" = "prod" ]; then | |
| docker-compose -f docker-compose.yml -f docker-compose.prod.yml logs -f | |
| else | |
| docker-compose logs -f | |
| fi | |
| } | |
| # Health check | |
| health_check() { | |
| log_info "Performing health check..." | |
| # Wait for services to start | |
| sleep 10 | |
| # Check orchestrator | |
| if curl -f http://localhost:8000/health > /dev/null 2>&1; then | |
| log_success "Orchestrator is healthy" | |
| else | |
| log_error "Orchestrator health check failed" | |
| return 1 | |
| fi | |
| # Check Streamlit | |
| if curl -f http://localhost:8501/_stcore/health > /dev/null 2>&1; then | |
| log_success "Streamlit UI is healthy" | |
| else | |
| log_error "Streamlit UI health check failed" | |
| return 1 | |
| fi | |
| # Check MCP servers | |
| local mcp_ports=(3001 3002 3003 3004 3005 3006) | |
| local mcp_names=("data-cleaning" "hypothesis-testing" "preprocessing" "feature-engineering" "model-training" "action-generation") | |
| for i in "${!mcp_ports[@]}"; do | |
| local port=${mcp_ports[$i]} | |
| local name=${mcp_names[$i]} | |
| if python3 -c "import socket; s=socket.socket(); s.connect(('localhost', $port)); s.close()" 2>/dev/null; then | |
| log_success "$name MCP server is healthy" | |
| else | |
| log_error "$name MCP server health check failed" | |
| return 1 | |
| fi | |
| done | |
| log_success "All services are healthy" | |
| } | |
| # Main execution | |
| main() { | |
| validate_environment | |
| check_prerequisites | |
| cd "$PROJECT_DIR" | |
| case $ACTION in | |
| build) | |
| build_images | |
| ;; | |
| up) | |
| build_images | |
| start_services | |
| health_check | |
| ;; | |
| down) | |
| stop_services | |
| ;; | |
| restart) | |
| restart_services | |
| health_check | |
| ;; | |
| logs) | |
| show_logs | |
| ;; | |
| health) | |
| health_check | |
| ;; | |
| *) | |
| log_error "Invalid action: $ACTION. Use build, up, down, restart, logs, or health" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| # Run main function | |
| main "$@" |