#!/bin/bash # Development script for running the STUPA PDF API with Docker Compose watch mode set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}Starting STUPA PDF API in development mode with watch...${NC}" # Check if Docker is running if ! docker info > /dev/null 2>&1; then echo -e "${RED}Docker is not running. Please start Docker first.${NC}" exit 1 fi # Check if docker compose supports watch if ! docker compose version | grep -q "2\.[2-9][0-9]\|2\.[1-9][0-9][0-9]"; then echo -e "${YELLOW}Warning: Docker Compose watch requires version 2.22.0 or higher${NC}" echo -e "${YELLOW}Your version: $(docker compose version)${NC}" fi # Create .env file if it doesn't exist if [ ! -f .env ]; then echo -e "${YELLOW}Creating .env file with default values...${NC}" cat > .env << EOF # MySQL Configuration MYSQL_DB=stupa MYSQL_USER=stupa MYSQL_PASSWORD=secret MYSQL_ROOT_PASSWORD=rootsecret # Application Configuration MASTER_KEY=change_me_in_production RATE_IP_PER_MIN=60 RATE_KEY_PER_MIN=30 # Timezone TZ=Europe/Berlin EOF echo -e "${GREEN}.env file created. Please update the MASTER_KEY for production use.${NC}" fi # Build the development image echo -e "${GREEN}Building development image...${NC}" docker compose -f docker-compose.watch.yml build # Start services with watch echo -e "${GREEN}Starting services with file watching enabled...${NC}" echo -e "${YELLOW}Changes to files in ./src will automatically reload the API${NC}" echo -e "${YELLOW}Changes to requirements.txt will rebuild the container${NC}" echo -e "${YELLOW}Changes to assets will be synced immediately${NC}" echo "" echo -e "${GREEN}Services:${NC}" echo -e " - API: http://localhost:8000" echo -e " - API Docs: http://localhost:8000/docs" echo -e " - Adminer: http://localhost:8080" echo "" echo -e "${YELLOW}Press Ctrl+C to stop${NC}" # Run docker compose with watch exec docker compose -f docker-compose.watch.yml up --watch