# Docker build and run script for CMPE343 Competition #!/bin/bash set -e echo "🐳 CMPE343 Competition Docker Setup" echo "==================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' 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" } # Check if Docker is installed if ! command -v docker &> /dev/null; then print_error "Docker is not installed. Please install Docker first." exit 1 fi # Check if Docker Compose is installed if ! command -v docker-compose &> /dev/null; then print_error "Docker Compose is not installed. Please install Docker Compose first." exit 1 fi # Create necessary directories print_status "Creating necessary directories..." mkdir -p state anonymized_teams monitoring # Make entrypoint script executable chmod +x docker-entrypoint.sh # Build the Docker image print_status "Building Docker image..." docker build -t cmpe343-competition . if [ $? -eq 0 ]; then print_success "Docker image built successfully!" else print_error "Failed to build Docker image" exit 1 fi # Check if we should run with docker-compose if [ "$1" = "--compose" ]; then print_status "Starting with Docker Compose..." docker-compose up -d if [ $? -eq 0 ]; then print_success "Competition is running!" print_status "Access the application at: http://localhost:7860" print_status "To view logs: docker-compose logs -f" print_status "To stop: docker-compose down" else print_error "Failed to start with Docker Compose" exit 1 fi else # Run with regular docker command print_status "Starting competition container..." docker run -d \ --name cmpe343-competition \ -p 7860:7860 \ -v "$(pwd)/state:/app/state" \ -v "$(pwd)/anonymized_teams:/app/anonymized_teams" \ -v "$(pwd)/models.yaml:/app/models.yaml" \ -v "$(pwd)/tracks.csv:/app/tracks.csv" \ cmpe343-competition if [ $? -eq 0 ]; then print_success "Competition is running!" print_status "Access the application at: http://localhost:7860" print_status "To view logs: docker logs -f cmpe343-competition" print_status "To stop: docker stop cmpe343-competition" else print_error "Failed to start competition container" exit 1 fi fi print_success "Setup complete! 🎉"