Add initial project files for Soil Water Balance Model including Docker setup, deployment scripts, API implementation, and data files
This commit is contained in:
117
deploy.bat
Normal file
117
deploy.bat
Normal file
@@ -0,0 +1,117 @@
|
||||
@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
|
||||
)
|
||||
Reference in New Issue
Block a user