@echo off REM Soil Water Balance Model Docker Deployment Script for Windows setlocal enabledelayedexpansion set IMAGE_NAME=soil-water-model set CONTAINER_NAME=soil-water-model-container set PORT=8000 echo ๐Ÿš€ Starting Soil Water Balance Model deployment... REM Function to check if container is running :check_container docker ps -q -f name=%CONTAINER_NAME% >nul 2>&1 if %errorlevel% equ 0 ( echo โš ๏ธ Container '%CONTAINER_NAME%' is already running. set /p choice="Do you want to stop and restart it? (y/N): " if /i "!choice!"=="y" ( echo ๐Ÿ›‘ Stopping existing container... docker stop %CONTAINER_NAME% docker rm %CONTAINER_NAME% ) else ( echo โŒ Deployment cancelled. exit /b 1 ) ) goto :eof REM Function to build image :build_image echo ๐Ÿ”จ Building Docker image... docker build -t %IMAGE_NAME% . if %errorlevel% neq 0 ( echo โŒ Failed to build image exit /b 1 ) echo โœ… Image built successfully! goto :eof REM Function to run container :run_container echo ๐Ÿƒ Running container... docker run -d --name %CONTAINER_NAME% -p %PORT%:8000 --restart unless-stopped %IMAGE_NAME% if %errorlevel% neq 0 ( echo โŒ Failed to start container exit /b 1 ) echo โœ… Container started successfully! goto :eof REM Function to show status :show_status echo ๐Ÿ“Š Container Status: docker ps -f name=%CONTAINER_NAME% --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" REM Wait a moment for container to start timeout /t 3 /nobreak >nul REM Test health endpoint echo ๐Ÿ” Testing health endpoint... curl -f http://localhost:%PORT%/health >nul 2>&1 if %errorlevel% equ 0 ( echo โœ… Health check passed! echo ๐ŸŒ API is available at: http://localhost:%PORT% echo ๐Ÿ“š API documentation: http://localhost:%PORT%/docs ) else ( echo โŒ Health check failed. Container might still be starting... echo Please wait a moment and check the logs: echo docker logs %CONTAINER_NAME% ) goto :eof REM Main deployment process :main call :check_container call :build_image call :run_container call :show_status echo. echo ๐ŸŽ‰ Deployment completed successfully! echo. echo Useful commands: echo View logs: docker logs %CONTAINER_NAME% echo Stop container: docker stop %CONTAINER_NAME% echo Restart container: docker restart %CONTAINER_NAME% echo Remove container: docker rm %CONTAINER_NAME% goto :eof REM Handle command line arguments if "%1"=="build" ( call :build_image ) else if "%1"=="run" ( call :check_container call :run_container call :show_status ) else if "%1"=="stop" ( echo ๐Ÿ›‘ Stopping container... docker stop %CONTAINER_NAME% 2>nul || echo Container not running ) else if "%1"=="restart" ( echo ๐Ÿ”„ Restarting container... docker restart %CONTAINER_NAME% 2>nul || (echo Container not running, starting new one... && call :run_container) call :show_status ) else if "%1"=="logs" ( echo ๐Ÿ“‹ Showing container logs... docker logs -f %CONTAINER_NAME% ) else if "%1"=="status" ( call :show_status ) else if "%1"=="clean" ( echo ๐Ÿงน Cleaning up... docker stop %CONTAINER_NAME% 2>nul || echo. docker rm %CONTAINER_NAME% 2>nul || echo. docker rmi %IMAGE_NAME% 2>nul || echo. echo โœ… Cleanup completed! ) else ( call :main )