#!/bin/bash # Development script using Podman/Docker with hot reload support # This script builds and runs the development container set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Detect container runtime CONTAINER_RUNTIME="" COMPOSE_COMMAND="" # Check for podman first (preferred) if command -v podman &> /dev/null; then CONTAINER_RUNTIME="podman" # Check for podman-compose if command -v podman-compose &> /dev/null; then COMPOSE_COMMAND="podman-compose" # Check if docker-compose works with podman elif command -v docker-compose &> /dev/null; then # Test if docker-compose can work with podman if docker-compose version &> /dev/null; then COMPOSE_COMMAND="docker-compose" fi fi # Check for docker elif command -v docker &> /dev/null; then CONTAINER_RUNTIME="docker" if command -v docker-compose &> /dev/null; then COMPOSE_COMMAND="docker-compose" elif docker compose version &> /dev/null 2>&1; then COMPOSE_COMMAND="docker compose" fi else echo -e "${RED}❌ Neither Podman nor Docker found. Please install one of them.${NC}" exit 1 fi # Check if compose command was found if [ -z "$COMPOSE_COMMAND" ]; then echo -e "${RED}❌ No compose command found (podman-compose or docker-compose).${NC}" if [ "$CONTAINER_RUNTIME" = "podman" ]; then echo -e "${YELLOW}💡 Install podman-compose with: pip install podman-compose${NC}" fi exit 1 fi # Function to cleanup cleanup() { echo -e "\n${YELLOW}🛑 Shutting down development container...${NC}" $COMPOSE_COMMAND -f docker-compose.dev.yml down echo -e "${GREEN}✅ Development environment stopped${NC}" exit 0 } # Set up signal handlers trap cleanup SIGINT SIGTERM echo -e "${BLUE}🚀 Starting GoCheck development environment with ${CONTAINER_RUNTIME}...${NC}" echo -e "${GREEN}📋 Using: $COMPOSE_COMMAND${NC}" # Check if container runtime is running if [ "$CONTAINER_RUNTIME" = "podman" ]; then if ! podman info > /dev/null 2>&1; then echo -e "${RED}❌ Podman is not running or not properly configured.${NC}" echo -e "${YELLOW}💡 Try running: podman machine start${NC}" exit 1 fi else if ! docker info > /dev/null 2>&1; then echo -e "${RED}❌ Docker is not running. Please start Docker and try again.${NC}" exit 1 fi fi # For Podman, we might need to set DOCKER_HOST if not already set if [ "$CONTAINER_RUNTIME" = "podman" ] && [ -z "$DOCKER_HOST" ]; then # Check if podman machine is running and get socket path if podman machine list --format "{{.Name}}\t{{.VMType}}\t{{.Running}}" | grep -q "true"; then # Try to get the podman socket path PODMAN_SOCKET=$(podman machine inspect --format "{{.ConnectionInfo.PodmanSocket.Path}}" 2>/dev/null || echo "") if [ -n "$PODMAN_SOCKET" ]; then export DOCKER_HOST="unix://$PODMAN_SOCKET" echo -e "${YELLOW}📌 Set DOCKER_HOST=$DOCKER_HOST${NC}" fi fi fi # Build and start the development container echo -e "${YELLOW}📦 Building development container...${NC}" # Add platform flag for better compatibility PLATFORM_FLAG="" if [ "$CONTAINER_RUNTIME" = "podman" ]; then # Podman typically handles platform detection automatically PLATFORM_FLAG="" elif [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then # For Docker on ARM64 (M1/M2 Macs) PLATFORM_FLAG="--platform linux/amd64" fi # Run the compose command $COMPOSE_COMMAND -f docker-compose.dev.yml up --build $PLATFORM_FLAG # The container will keep running until interrupted # When interrupted, the cleanup function will be called