|
1 | 1 | @echo off |
2 | | -REM deploy.bat — Docker-based bootstrapper for Coral TPU Detection Skill (Windows) |
| 2 | +REM deploy.bat — Native local bootstrapper for Coral TPU Detection Skill (Windows) |
3 | 3 | REM |
4 | | -REM Builds the Docker image locally and verifies Edge TPU connectivity. |
5 | | -REM Called by Aegis skill-runtime-manager during installation. |
| 4 | +REM Builds a local Python virtual environment and installs the Google Coral Edge TPU |
| 5 | +REM natively on the host OS. Safely triggers UAC elevation for driver installation. |
6 | 6 | REM |
7 | | -REM Requires: Docker Desktop 4.35+ with USB/IP support |
| 7 | +REM Exit codes: |
| 8 | +REM 0 = success |
| 9 | +REM 1 = fatal error (Python/pip not found or UAC denied) |
| 10 | +REM 2 = partial success (no TPU detected, will use CPU fallback) |
8 | 11 |
|
9 | 12 | setlocal enabledelayedexpansion |
10 | 13 |
|
11 | 14 | set "SKILL_DIR=%~dp0" |
12 | | -set "IMAGE_NAME=aegis-coral-tpu" |
13 | | -set "IMAGE_TAG=latest" |
14 | 15 | set "LOG_PREFIX=[coral-tpu-deploy]" |
15 | 16 |
|
16 | | -REM ─── Step 1: Check Docker ──────────────────────────────────────────────── |
| 17 | +REM Ensure we run inside the correct folder |
| 18 | +cd /d "%SKILL_DIR%" |
17 | 19 |
|
18 | | -where docker >nul 2>&1 |
| 20 | +echo %LOG_PREFIX% Platform: Windows 1>&2 |
| 21 | +echo {"event": "progress", "stage": "platform", "message": "Windows native environment detected"} |
| 22 | + |
| 23 | +REM ─── Step 1: Install Native OS TPU Drivers (UAC Promoted) ─────────────── |
| 24 | + |
| 25 | +echo %LOG_PREFIX% Downloading Google official x64 Windows installer... 1>&2 |
| 26 | + |
| 27 | +set "TMP_DIR=%TEMP%\coral_tpu_install" |
| 28 | +if not exist "%TMP_DIR%" mkdir "%TMP_DIR%" |
| 29 | +cd /d "%TMP_DIR%" |
| 30 | + |
| 31 | +powershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip'" |
19 | 32 | if %errorlevel% neq 0 ( |
20 | | - echo %LOG_PREFIX% ERROR: Docker not found. Install Docker Desktop 4.35+ 1>&2 |
21 | | - echo {"event": "error", "stage": "docker", "message": "Docker not found. Install Docker Desktop 4.35+"} |
| 33 | + echo %LOG_PREFIX% ERROR: Failed to download Edge TPU runtime. 1>&2 |
22 | 34 | exit /b 1 |
23 | 35 | ) |
24 | 36 |
|
25 | | -docker info >nul 2>&1 |
| 37 | +powershell -Command "Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.' -Force" |
| 38 | +cd edgetpu_runtime |
| 39 | + |
| 40 | +echo %LOG_PREFIX% Prompting for Administrator rights to install drivers... 1>&2 |
| 41 | +echo {"event": "progress", "stage": "platform", "message": "UAC required: Install Google Coral Edge TPU Windows Runtime"} |
| 42 | + |
| 43 | +REM Start the official install script elevated. Wait for it to finish. |
| 44 | +powershell -Command "Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'install.bat < nul' -Verb RunAs -Wait" |
| 45 | + |
26 | 46 | if %errorlevel% neq 0 ( |
27 | | - echo %LOG_PREFIX% ERROR: Docker daemon not running. Start Docker Desktop. 1>&2 |
28 | | - echo {"event": "error", "stage": "docker", "message": "Docker daemon not running"} |
| 47 | + echo. |
| 48 | + echo [91m[MANUAL SETUP REQUIRED][0m UAC prompt was skipped or user aborted. |
| 49 | + echo Please execute the following fragile instructions manually in an Administrator console: |
| 50 | + echo. |
| 51 | + echo [96mpowershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip'"[0m |
| 52 | + echo [96mpowershell -Command "Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.'"[0m |
| 53 | + echo [96mcd edgetpu_runtime[0m |
| 54 | + echo [96minstall.bat[0m |
| 55 | + echo. |
| 56 | + echo Once completed, re-run this deployment. |
| 57 | + echo {"event": "error", "stage": "platform", "message": "Manual OS setup required (UAC skipped)"} |
| 58 | + cd /d "%SKILL_DIR%" |
| 59 | + rmdir /S /Q "%TMP_DIR%" |
29 | 60 | exit /b 1 |
30 | 61 | ) |
31 | 62 |
|
32 | | -for /f "tokens=*" %%v in ('docker version --format "{{.Server.Version}}" 2^>nul') do set "DOCKER_VER=%%v" |
33 | | -echo %LOG_PREFIX% Using Docker (version: %DOCKER_VER%) 1>&2 |
34 | | -echo {"event": "progress", "stage": "docker", "message": "Docker ready (%DOCKER_VER%)"} |
| 63 | +cd /d "%SKILL_DIR%" |
| 64 | +rmdir /S /Q "%TMP_DIR%" |
35 | 65 |
|
36 | | -REM ─── Step 2: Build Docker image ────────────────────────────────────────── |
| 66 | +REM ─── Step 2: Ensure Python 3 ────────────────────────────────────────────── |
37 | 67 |
|
38 | | -echo %LOG_PREFIX% Building Docker image: %IMAGE_NAME%:%IMAGE_TAG% ... 1>&2 |
39 | | -echo {"event": "progress", "stage": "build", "message": "Building Docker image..."} |
| 68 | +set "PYTHON_CMD=python" |
| 69 | +python --version >nul 2>&1 |
| 70 | +if %errorlevel% neq 0 ( |
| 71 | + python3 --version >nul 2>&1 |
| 72 | + if !errorlevel! equ 0 ( |
| 73 | + set "PYTHON_CMD=python3" |
| 74 | + ) else ( |
| 75 | + echo %LOG_PREFIX% ERROR: Python not found. 1>&2 |
| 76 | + echo {"event": "error", "stage": "python", "message": "Python not found"} |
| 77 | + exit /b 1 |
| 78 | + ) |
| 79 | +) |
| 80 | + |
| 81 | +echo %LOG_PREFIX% Using Python: !PYTHON_CMD! 1>&2 |
| 82 | + |
| 83 | +REM ─── Step 3: Create Virtual Environment ─────────────────────────────────── |
40 | 84 |
|
41 | | -docker build -t %IMAGE_NAME%:%IMAGE_TAG% "%SKILL_DIR%" |
| 85 | +set "VENV_DIR=%SKILL_DIR%venv" |
| 86 | +echo %LOG_PREFIX% Setting up virtual environment in %VENV_DIR%... 1>&2 |
| 87 | +echo {"event": "progress", "stage": "build", "message": "Creating Python virtual environment..."} |
| 88 | + |
| 89 | +!PYTHON_CMD! -m venv "%VENV_DIR%" |
| 90 | + |
| 91 | +if not exist "%VENV_DIR%\Scripts\python.exe" ( |
| 92 | + echo %LOG_PREFIX% ERROR: Failed to create virtual environment. 1>&2 |
| 93 | + echo {"event": "error", "stage": "build", "message": "Failed to create venv"} |
| 94 | + exit /b 1 |
| 95 | +) |
| 96 | + |
| 97 | +REM ─── Step 4: Install PyCoral & Dependencies ─────────────────────────────── |
| 98 | + |
| 99 | +echo %LOG_PREFIX% Installing Python dependencies (including pycoral)... 1>&2 |
| 100 | +echo {"event": "progress", "stage": "build", "message": "Fetching pycoral specific wheels..."} |
| 101 | + |
| 102 | +"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip >nul 2>&1 |
| 103 | + |
| 104 | +"%VENV_DIR%\Scripts\python.exe" -m pip install --extra-index-url https://google-coral.github.io/py-repo/ pycoral~=2.0 |
42 | 105 | if %errorlevel% neq 0 ( |
43 | | - echo %LOG_PREFIX% ERROR: Docker build failed 1>&2 |
44 | | - echo {"event": "error", "stage": "build", "message": "Docker image build failed"} |
| 106 | + echo %LOG_PREFIX% WARNING: pip install pycoral failed. Will attempt to install standard requirements anyway. 1>&2 |
| 107 | +) |
| 108 | + |
| 109 | +"%VENV_DIR%\Scripts\python.exe" -m pip install -r "%SKILL_DIR%requirements.txt" |
| 110 | +if %errorlevel% neq 0 ( |
| 111 | + echo %LOG_PREFIX% ERROR: Failed to install Python dependencies. 1>&2 |
| 112 | + echo {"event": "error", "stage": "build", "message": "pip install failed"} |
45 | 113 | exit /b 1 |
46 | 114 | ) |
47 | 115 |
|
48 | | -echo {"event": "progress", "stage": "build", "message": "Docker image ready"} |
| 116 | +echo %LOG_PREFIX% Dependencies installed successfully. 1>&2 |
| 117 | + |
| 118 | +REM ─── Step 5: Probe for Edge TPU devices ──────────────────────────────────── |
| 119 | + |
| 120 | +echo %LOG_PREFIX% Probing for Edge TPU devices natively... 1>&2 |
| 121 | +echo {"event": "progress", "stage": "probe", "message": "Checking for physical Edge TPU..."} |
49 | 122 |
|
50 | | -REM ─── Step 3: Probe for Edge TPU ────────────────────────────────────────── |
| 123 | +set "TPU_FOUND=false" |
| 124 | +set "TPU_COUNT=?" |
51 | 125 |
|
52 | | -echo %LOG_PREFIX% Probing for Edge TPU devices... 1>&2 |
53 | | -echo {"event": "progress", "stage": "probe", "message": "Checking for Edge TPU devices..."} |
| 126 | +for /f "delims=" %%I in ('"%VENV_DIR%\Scripts\python.exe" "%SKILL_DIR%scripts\tpu_probe.py" 2^>nul') do ( |
| 127 | + set "PROBE_OUTPUT=%%I" |
| 128 | +) |
54 | 129 |
|
55 | | -docker run --rm --privileged %IMAGE_NAME%:%IMAGE_TAG% python3 scripts/tpu_probe.py >nul 2>&1 |
| 130 | +echo !PROBE_OUTPUT! | findstr /C:"\"available\": true" >nul |
56 | 131 | if %errorlevel% equ 0 ( |
57 | | - echo %LOG_PREFIX% Edge TPU detected 1>&2 |
58 | | - echo {"event": "progress", "stage": "probe", "message": "Edge TPU detected"} |
| 132 | + set "TPU_FOUND=true" |
| 133 | + REM Approximate counts natively |
| 134 | + echo {"event": "progress", "stage": "probe", "message": "Edge TPU device natively registered"} |
59 | 135 | ) else ( |
60 | | - echo %LOG_PREFIX% WARNING: No Edge TPU detected - CPU fallback 1>&2 |
61 | | - echo {"event": "progress", "stage": "probe", "message": "No Edge TPU detected - CPU fallback"} |
| 136 | + echo {"event": "progress", "stage": "probe", "message": "No Edge TPU detected -- CPU fallback available"} |
62 | 137 | ) |
63 | 138 |
|
64 | | -echo {"event": "complete", "status": "success", "message": "Coral TPU skill installed"} |
| 139 | +REM ─── Step 6: Complete ────────────────────────────────────────────────────── |
65 | 140 |
|
66 | | -echo %LOG_PREFIX% Done! 1>&2 |
67 | | -exit /b 0 |
| 141 | +if "!TPU_FOUND!"=="true" ( |
| 142 | + echo {"event": "complete", "status": "success", "tpu_found": true, "message": "Native Coral TPU skill installed -- Edge TPU ready"} |
| 143 | + exit /b 0 |
| 144 | +) else ( |
| 145 | + echo {"event": "complete", "status": "partial", "tpu_found": false, "message": "Native Coral TPU skill installed -- no TPU detected (CPU fallback)"} |
| 146 | + exit /b 2 |
| 147 | +) |
0 commit comments