#!/bin/bash # KidsAI Explorer - Docker Development Setup Script # This script sets up the development environment with Docker Bake + Compose v2 support set -e echo "๐Ÿš€ KidsAI Explorer - Docker Bake + Compose v2 Setup" echo "===================================================" # Check if Docker is running if ! docker info > /dev/null 2>&1; then echo "โŒ Docker is not running. Please start Docker first." exit 1 fi # Check for Docker Compose v2 if docker compose version > /dev/null 2>&1; then COMPOSE_CMD="docker compose" echo "โœ… Docker Compose v2 detected" elif command -v docker-compose &> /dev/null; then COMPOSE_CMD="docker-compose" echo "โš ๏ธ Using Docker Compose v1 (consider upgrading to v2)" else echo "โŒ Docker Compose is not installed. Please install Docker Compose v2." exit 1 fi # Check if Docker Buildx is available for Bake support if docker buildx version > /dev/null 2>&1; then BUILDX_AVAILABLE=true echo "โœ… Docker Buildx available - Bake support enabled" else BUILDX_AVAILABLE=false echo "โš ๏ธ Docker Buildx not available - falling back to standard builds" fi # Create .env file if it doesn't exist if [ ! -f .env ]; then echo "๐Ÿ“ Creating .env file from template..." cp .env.example .env echo "โš ๏ธ Please edit .env file and add your API keys before running the application." fi # Check if COMPOSE_BAKE is enabled if [ -f .env ] && grep -q "COMPOSE_BAKE=true" .env && [ "$BUILDX_AVAILABLE" = true ]; then BAKE_ENABLED=true echo "๐Ÿ”ฅ Docker Bake integration ENABLED" else BAKE_ENABLED=false echo "๐Ÿ“ฆ Using standard Docker builds" fi # Function to build with Bake if available, otherwise use Compose build_images() { local target=${1:-development} if [ "$BAKE_ENABLED" = true ]; then echo "๐Ÿ”ฅ Building with Docker Bake (target: $target)..." docker buildx bake --load $target else echo "๐Ÿ“ฆ Building with Docker Compose..." $COMPOSE_CMD build app fi } # Function to show available commands show_help() { echo "" echo "Available commands:" echo " dev - Start development environment" echo " prod - Start production environment" echo " build - Build images with Bake (or fallback to Compose)" echo " build-dev - Build development image" echo " build-prod - Build production image" echo " bake-all - Build all targets with Bake" echo " stop - Stop all services" echo " clean - Clean up containers and images" echo " logs - Show application logs" echo " shell - Open shell in running container" echo " help - Show this help" } # Parse command line arguments case "${1:-help}" in "dev") echo "๐Ÿ”ง Starting development environment..." build_images development $COMPOSE_CMD up app ;; "prod") echo "๐Ÿš€ Starting production environment..." build_images production $COMPOSE_CMD --profile production up app-prod ;; "build") echo "๐Ÿ—๏ธ Building default images..." build_images development ;; "build-dev") echo "๐Ÿ—๏ธ Building development image..." build_images development ;; "build-prod") echo "๐Ÿ—๏ธ Building production image..." build_images production ;; "bake-all") if [ "$BAKE_ENABLED" = true ]; then echo "๐Ÿ”ฅ Building all targets with Docker Bake..." docker buildx bake all --load else echo "โŒ Docker Bake is not available. Use 'build' instead." exit 1 fi ;; "stop") echo "๐Ÿ›‘ Stopping all services..." $COMPOSE_CMD down ;; "clean") echo "๐Ÿงน Cleaning up containers and images..." $COMPOSE_CMD down --rmi all --volumes --remove-orphans docker system prune -f ;; "logs") echo "๐Ÿ“‹ Showing application logs..." $COMPOSE_CMD logs -f app ;; "shell") echo "๐Ÿš Opening shell in running development container..." $COMPOSE_CMD exec app sh ;; "help"|*) show_help ;; esac echo "" echo "โœ… Done! Your KidsAI Explorer is ready." if [ "$BAKE_ENABLED" = true ]; then echo "๐Ÿ”ฅ Docker Bake integration is ACTIVE for faster builds!" fi echo "๐ŸŒ Access your app at: http://localhost:3444"