302 lines
8.3 KiB
Batchfile
302 lines
8.3 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
echo === DMS Compliance Tool Windows Final Version ===
|
|
echo.
|
|
|
|
REM Set defaults to avoid input issues
|
|
set "SELECTED_SERVICE_ARCH=dual"
|
|
set "SELECTED_PORTS=5050,5051"
|
|
set "SERVICE_DESC=Dual Service - FastAPI Server and History Viewer"
|
|
set "TARGET_PLATFORM=linux/amd64"
|
|
set "TARGET_PLATFORM_NAME=AMD64 - Auto-detected"
|
|
|
|
REM Configuration
|
|
set "TIMESTAMP=%date:~10,4%%date:~4,2%%date:~7,2%-%time:~0,2%%time:~3,2%%time:~6,2%"
|
|
set "TIMESTAMP=%TIMESTAMP: =0%"
|
|
set "platform_suffix=amd64"
|
|
set "EXPORT_DIR=dms-compliance-dual-amd64-windows-%TIMESTAMP%"
|
|
set "IMAGE_NAME=compliance-dms-windows"
|
|
|
|
echo [INFO] Using default configuration:
|
|
echo [INFO] Architecture: %SERVICE_DESC%
|
|
echo [INFO] Ports: %SELECTED_PORTS%
|
|
echo [INFO] Platform: %TARGET_PLATFORM_NAME%
|
|
echo.
|
|
|
|
REM Check Docker
|
|
docker --version >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERROR] Docker not installed
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
docker info >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERROR] Docker not running
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo [SUCCESS] Docker environment OK
|
|
echo.
|
|
|
|
echo === Starting Build Process ===
|
|
|
|
REM Create directories
|
|
if exist "%EXPORT_DIR%" rmdir /s /q "%EXPORT_DIR%"
|
|
mkdir "%EXPORT_DIR%"
|
|
|
|
set "TEMP_BUILD_DIR=%TEMP%\dms-build-%RANDOM%"
|
|
mkdir "%TEMP_BUILD_DIR%"
|
|
|
|
REM Copy files
|
|
echo [Step 1/6] Copying project files...
|
|
if exist "ddms_compliance_suite" robocopy "ddms_compliance_suite" "%TEMP_BUILD_DIR%\ddms_compliance_suite" /E /XD __pycache__ /XF *.pyc >nul 2>&1
|
|
if exist "custom_stages" robocopy "custom_stages" "%TEMP_BUILD_DIR%\custom_stages" /E /XD __pycache__ /XF *.pyc >nul 2>&1
|
|
if exist "custom_testcases" robocopy "custom_testcases" "%TEMP_BUILD_DIR%\custom_testcases" /E /XD __pycache__ /XF *.pyc >nul 2>&1
|
|
if exist "templates" robocopy "templates" "%TEMP_BUILD_DIR%\templates" /E >nul 2>&1
|
|
if exist "static" robocopy "static" "%TEMP_BUILD_DIR%\static" /E >nul 2>&1
|
|
if exist "assets" robocopy "assets" "%TEMP_BUILD_DIR%\assets" /E >nul 2>&1
|
|
|
|
for %%f in (fastapi_server.py history_viewer.py flask_app.py web_interface.py requirements.txt) do (
|
|
if exist "%%f" copy "%%f" "%TEMP_BUILD_DIR%\" >nul
|
|
)
|
|
|
|
echo [SUCCESS] Files copied
|
|
echo.
|
|
|
|
REM Create Dockerfile
|
|
echo [Step 2/6] Creating Dockerfile...
|
|
cd /d "%TEMP_BUILD_DIR%"
|
|
|
|
(
|
|
echo FROM python:3.11-alpine
|
|
echo WORKDIR /app
|
|
echo COPY requirements.txt .
|
|
echo RUN pip install --no-cache-dir -r requirements.txt
|
|
echo RUN pip install --no-cache-dir fastapi uvicorn[standard]
|
|
echo RUN apk add --no-cache supervisor curl bash
|
|
echo COPY . .
|
|
echo RUN mkdir -p /var/log/supervisor
|
|
echo COPY supervisord.conf /etc/supervisor/conf.d/
|
|
echo EXPOSE 5050 5051
|
|
echo CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
|
) > Dockerfile
|
|
|
|
(
|
|
echo [supervisord]
|
|
echo nodaemon=true
|
|
echo logfile=/var/log/supervisor/supervisord.log
|
|
echo user=root
|
|
echo.
|
|
echo [program:api_server]
|
|
echo command=python -m uvicorn fastapi_server:app --host 0.0.0.0 --port 5050
|
|
echo directory=/app
|
|
echo autostart=true
|
|
echo autorestart=true
|
|
echo redirect_stderr=true
|
|
echo stdout_logfile=/var/log/supervisor/api_server.log
|
|
echo.
|
|
echo [program:history_viewer]
|
|
echo command=python history_viewer.py
|
|
echo directory=/app
|
|
echo autostart=true
|
|
echo autorestart=true
|
|
echo redirect_stderr=true
|
|
echo stdout_logfile=/var/log/supervisor/history_viewer.log
|
|
) > supervisord.conf
|
|
|
|
cd /d "%~dp0"
|
|
echo [SUCCESS] Dockerfile created
|
|
echo.
|
|
|
|
REM Copy to final directory
|
|
echo [Step 3/6] Copying build files...
|
|
robocopy "%TEMP_BUILD_DIR%" "%EXPORT_DIR%" /E >nul 2>&1
|
|
echo [SUCCESS] Build files copied
|
|
echo.
|
|
|
|
REM Create Docker Compose
|
|
echo [Step 4/6] Creating Docker Compose...
|
|
(
|
|
echo services:
|
|
echo dms-compliance:
|
|
echo image: %IMAGE_NAME%:latest
|
|
echo container_name: dms-compliance-tool
|
|
echo ports:
|
|
echo - "5050:5050"
|
|
echo - "5051:5051"
|
|
echo volumes:
|
|
echo - ./uploads:/app/uploads
|
|
echo - ./logs:/app/logs
|
|
echo restart: unless-stopped
|
|
echo healthcheck:
|
|
echo test: ["CMD", "curl", "-f", "http://localhost:5050/health"]
|
|
echo interval: 30s
|
|
echo timeout: 10s
|
|
echo retries: 3
|
|
echo start_period: 40s
|
|
) > "%EXPORT_DIR%\docker-compose.yml"
|
|
echo [SUCCESS] Docker Compose created
|
|
echo.
|
|
|
|
REM Create scripts
|
|
echo [Step 5/6] Creating cross-platform management scripts...
|
|
|
|
REM Windows batch scripts
|
|
(
|
|
echo @echo off
|
|
echo echo Starting DMS Compliance Tool...
|
|
echo echo Loading pre-built Docker image...
|
|
echo docker load -i docker-image.tar
|
|
echo echo Starting services...
|
|
echo docker compose up -d
|
|
echo echo Services started!
|
|
echo echo FastAPI Server: http://localhost:5050
|
|
echo echo History Viewer: http://localhost:5051
|
|
echo pause
|
|
) > "%EXPORT_DIR%\start.bat"
|
|
|
|
(
|
|
echo @echo off
|
|
echo docker compose down
|
|
echo echo Services stopped.
|
|
echo pause
|
|
) > "%EXPORT_DIR%\stop.bat"
|
|
|
|
(
|
|
echo @echo off
|
|
echo docker compose logs -f
|
|
) > "%EXPORT_DIR%\logs.bat"
|
|
|
|
REM Linux shell scripts
|
|
(
|
|
echo #!/bin/bash
|
|
echo.
|
|
echo echo "Starting DMS Compliance Tool..."
|
|
echo echo "Loading pre-built Docker image..."
|
|
echo docker load -i docker-image.tar
|
|
echo echo "Starting services..."
|
|
echo docker compose up -d
|
|
echo echo "Services started!"
|
|
echo echo "FastAPI Server: http://localhost:5050"
|
|
echo echo "History Viewer: http://localhost:5051"
|
|
) > "%EXPORT_DIR%\start.sh"
|
|
|
|
(
|
|
echo #!/bin/bash
|
|
echo.
|
|
echo echo "Stopping DMS Compliance Tool..."
|
|
echo docker compose down
|
|
echo echo "Services stopped."
|
|
) > "%EXPORT_DIR%\stop.sh"
|
|
|
|
(
|
|
echo #!/bin/bash
|
|
echo.
|
|
echo docker compose logs -f
|
|
) > "%EXPORT_DIR%\logs.sh"
|
|
|
|
REM Set permissions script for Linux
|
|
(
|
|
echo #!/bin/bash
|
|
echo chmod +x *.sh
|
|
echo echo "Permissions set for shell scripts"
|
|
) > "%EXPORT_DIR%\set-permissions.sh"
|
|
|
|
(
|
|
echo # DMS Compliance Tool - Cross-Platform Version
|
|
echo.
|
|
echo ## Quick Start
|
|
echo.
|
|
echo ### Windows:
|
|
echo 1. Run start.bat
|
|
echo 2. Access web interface
|
|
echo 3. Use stop.bat to stop
|
|
echo.
|
|
echo ### Linux/macOS:
|
|
echo 1. chmod +x *.sh ^(or run ./set-permissions.sh^)
|
|
echo 2. ./start.sh
|
|
echo 3. Access web interface
|
|
echo 4. ./stop.sh to stop
|
|
echo.
|
|
echo ## Architecture
|
|
echo - FastAPI Server: http://localhost:5050
|
|
echo - History Viewer: http://localhost:5051
|
|
echo - Dual service architecture with supervisor
|
|
echo.
|
|
echo ## Management Commands
|
|
echo Windows: start.bat, stop.bat, logs.bat
|
|
echo Linux: start.sh, stop.sh, logs.sh
|
|
echo.
|
|
echo ## Package Contents
|
|
echo - docker-compose.yml: Service configuration ^(uses pre-built image^)
|
|
echo - Dockerfile: Container build instructions ^(for reference^)
|
|
echo - docker-image.tar: Pre-built Docker image ^(fast startup^)
|
|
echo - Cross-platform management scripts ^(auto-load image^)
|
|
) > "%EXPORT_DIR%\README.md"
|
|
|
|
echo [SUCCESS] Cross-platform scripts created
|
|
echo.
|
|
|
|
REM Build image
|
|
echo [Step 6/6] Building Docker image...
|
|
cd /d "%EXPORT_DIR%"
|
|
docker build -t "%IMAGE_NAME%:latest" .
|
|
if errorlevel 1 (
|
|
echo [ERROR] Build failed
|
|
cd /d "%~dp0"
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
docker save "%IMAGE_NAME%:latest" -o docker-image.tar
|
|
cd /d "%~dp0"
|
|
|
|
REM Clean up source files (like multiplatform script)
|
|
echo [INFO] Cleaning up source files...
|
|
cd /d "%EXPORT_DIR%"
|
|
|
|
REM Remove source code directories (keep only deployment files)
|
|
if exist "ddms_compliance_suite" rmdir /s /q "ddms_compliance_suite"
|
|
if exist "custom_stages" rmdir /s /q "custom_stages"
|
|
if exist "custom_testcases" rmdir /s /q "custom_testcases"
|
|
if exist "templates" rmdir /s /q "templates"
|
|
if exist "static" rmdir /s /q "static"
|
|
if exist "assets" rmdir /s /q "assets"
|
|
|
|
REM Remove unnecessary source Python files (keep fastapi_server.py and history_viewer.py for runtime)
|
|
for %%f in (flask_app.py web_interface.py) do (
|
|
if exist "%%f" del "%%f"
|
|
)
|
|
|
|
echo [SUCCESS] Source files cleaned up
|
|
cd /d "%~dp0"
|
|
|
|
REM Create archive (like multiplatform script)
|
|
echo [INFO] Creating archive...
|
|
powershell -command "Compress-Archive -Path '%EXPORT_DIR%' -DestinationPath '%EXPORT_DIR%.zip' -Force"
|
|
|
|
REM Clean up temporary directories (like multiplatform script)
|
|
if exist "%TEMP_BUILD_DIR%" rmdir /s /q "%TEMP_BUILD_DIR%"
|
|
if exist "%EXPORT_DIR%" rmdir /s /q "%EXPORT_DIR%"
|
|
|
|
echo.
|
|
echo === Build Complete ===
|
|
echo [SUCCESS] Package created: %EXPORT_DIR%.zip
|
|
echo [INFO] Architecture: Dual Service - FastAPI Server and History Viewer
|
|
echo [INFO] Ports: 5050,5051
|
|
echo [INFO] FastAPI Server: http://localhost:5050
|
|
echo [INFO] History Viewer: http://localhost:5051
|
|
echo.
|
|
echo Package contents:
|
|
echo - Cross-platform scripts ^(Windows .bat and Linux .sh^)
|
|
echo - Docker Compose configuration
|
|
echo - Pre-built Docker image
|
|
echo - Clean deployment package ^(no source code^)
|
|
echo.
|
|
echo Build complete!
|
|
pause
|