|
1 | 1 | @echo off |
2 | | -REM deploy.bat — Native bootstrapper for Coral TPU Detection Skill (Windows) |
| 2 | +REM deploy.bat — Docker-based bootstrapper for Coral TPU Detection Skill (Windows) |
3 | 3 | REM |
4 | | -REM Installs ai-edge-litert in a Python venv and verifies Edge TPU connectivity. |
| 4 | +REM Builds the Docker image locally and verifies Edge TPU connectivity. |
5 | 5 | REM Called by Aegis skill-runtime-manager during installation. |
6 | 6 | REM |
7 | | -REM Prerequisites: |
8 | | -REM - Python 3.9+ installed and on PATH |
9 | | -REM - libedgetpu installed (https://github.com/google-coral/libedgetpu/releases) |
10 | | -REM |
11 | | -REM Exit codes: |
12 | | -REM 0 = success (Edge TPU detected) |
13 | | -REM 1 = fatal error |
14 | | -REM 2 = partial success (no TPU, CPU fallback) |
15 | | - |
16 | | -setlocal EnableDelayedExpansion |
| 7 | +REM Requires: Docker Desktop 4.35+ with USB/IP support |
17 | 8 |
|
18 | | -set SKILL_DIR=%~dp0 |
19 | | -set VENV_DIR=%SKILL_DIR%.venv |
20 | | -set LOG_PREFIX=[coral-tpu-deploy] |
| 9 | +setlocal enabledelayedexpansion |
21 | 10 |
|
22 | | -REM ─── Step 1: Find Python ─────────────────────────────────────────────────── |
| 11 | +set "SKILL_DIR=%~dp0" |
| 12 | +set "IMAGE_NAME=aegis-coral-tpu" |
| 13 | +set "IMAGE_TAG=latest" |
| 14 | +set "LOG_PREFIX=[coral-tpu-deploy]" |
23 | 15 |
|
24 | | -echo %LOG_PREFIX% Checking for Python 3.9+... >&2 |
| 16 | +REM ─── Step 1: Check Docker ──────────────────────────────────────────────── |
25 | 17 |
|
26 | | -where python >nul 2>&1 |
27 | | -if errorlevel 1 ( |
28 | | - echo {"event": "error", "stage": "python", "message": "Python not found. Install Python 3.9+"} |
| 18 | +where docker >nul 2>&1 |
| 19 | +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+"} |
29 | 22 | exit /b 1 |
30 | 23 | ) |
31 | 24 |
|
32 | | -for /f "tokens=2" %%v in ('python --version 2^>^&1') do set PY_VER=%%v |
33 | | -echo %LOG_PREFIX% Found Python %PY_VER% >&2 |
34 | | - |
35 | | -REM ─── Step 2: Create virtual environment ──────────────────────────────────── |
36 | | - |
37 | | -if not exist "%VENV_DIR%\Scripts\python.exe" ( |
38 | | - echo {"event": "progress", "stage": "venv", "message": "Creating virtual environment..."} |
39 | | - python -m venv "%VENV_DIR%" |
40 | | - if errorlevel 1 ( |
41 | | - echo {"event": "error", "stage": "venv", "message": "Failed to create virtual environment"} |
42 | | - exit /b 1 |
43 | | - ) |
| 25 | +docker info >nul 2>&1 |
| 26 | +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"} |
| 29 | + exit /b 1 |
44 | 30 | ) |
45 | 31 |
|
46 | | -set VENV_PIP=%VENV_DIR%\Scripts\pip.exe |
47 | | -set VENV_PYTHON=%VENV_DIR%\Scripts\python.exe |
48 | | - |
49 | | -echo %LOG_PREFIX% Virtual environment ready >&2 |
50 | | - |
51 | | -REM ─── Step 3: Install dependencies ───────────────────────────────────────── |
52 | | - |
53 | | -echo {"event": "progress", "stage": "install", "message": "Installing ai-edge-litert and dependencies..."} |
54 | | -"%VENV_PIP%" install --upgrade pip -q 2>&1 |
55 | | -"%VENV_PIP%" install -r "%SKILL_DIR%requirements.txt" -q 2>&1 |
| 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%)"} |
56 | 35 |
|
57 | | -echo %LOG_PREFIX% Dependencies installed >&2 |
58 | | -echo {"event": "progress", "stage": "install", "message": "Dependencies installed"} |
| 36 | +REM ─── Step 2: Build Docker image ────────────────────────────────────────── |
59 | 37 |
|
60 | | -REM ─── Step 4: Check libedgetpu ────────────────────────────────────────────── |
| 38 | +echo %LOG_PREFIX% Building Docker image: %IMAGE_NAME%:%IMAGE_TAG% ... 1>&2 |
| 39 | +echo {"event": "progress", "stage": "build", "message": "Building Docker image..."} |
61 | 40 |
|
62 | | -echo %LOG_PREFIX% Checking for libedgetpu... >&2 |
63 | | -echo {"event": "progress", "stage": "driver", "message": "Checking for Edge TPU driver..."} |
64 | | - |
65 | | -where edgetpu.dll >nul 2>&1 |
66 | | -if errorlevel 1 ( |
67 | | - echo %LOG_PREFIX% WARNING: edgetpu.dll not found. >&2 |
68 | | - echo %LOG_PREFIX% Download the runtime from: >&2 |
69 | | - echo %LOG_PREFIX% https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip >&2 |
70 | | - echo %LOG_PREFIX% Extract and run install.bat >&2 |
71 | | - echo {"event": "progress", "stage": "driver", "message": "libedgetpu not found — install from Google releases"} |
| 41 | +docker build -t %IMAGE_NAME%:%IMAGE_TAG% "%SKILL_DIR%" |
| 42 | +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"} |
| 45 | + exit /b 1 |
72 | 46 | ) |
73 | 47 |
|
74 | | -REM ─── Step 5: Probe for Edge TPU ─────────────────────────────────────────── |
| 48 | +echo {"event": "progress", "stage": "build", "message": "Docker image ready"} |
75 | 49 |
|
| 50 | +REM ─── Step 3: Probe for Edge TPU ────────────────────────────────────────── |
| 51 | + |
| 52 | +echo %LOG_PREFIX% Probing for Edge TPU devices... 1>&2 |
76 | 53 | echo {"event": "progress", "stage": "probe", "message": "Checking for Edge TPU devices..."} |
77 | 54 |
|
78 | | -set TPU_FOUND=false |
79 | | -"%VENV_PYTHON%" "%SKILL_DIR%scripts\tpu_probe.py" > "%TEMP%\tpu_probe_result.json" 2>nul |
80 | | -if not errorlevel 1 ( |
81 | | - set TPU_FOUND=true |
| 55 | +docker run --rm --privileged %IMAGE_NAME%:%IMAGE_TAG% python3 scripts/tpu_probe.py >nul 2>&1 |
| 56 | +if %errorlevel% equ 0 ( |
| 57 | + echo %LOG_PREFIX% Edge TPU detected 1>&2 |
| 58 | + echo {"event": "progress", "stage": "probe", "message": "Edge TPU detected"} |
| 59 | +) 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"} |
82 | 62 | ) |
83 | 63 |
|
84 | | -REM ─── Step 6: Complete ────────────────────────────────────────────────────── |
| 64 | +REM ─── Step 4: Set run command ────────────────────────────────────────────── |
85 | 65 |
|
86 | | -set RUN_CMD=%VENV_PYTHON% %SKILL_DIR%scripts\detect.py |
| 66 | +set "RUN_CMD=docker run -i --rm --privileged -v /tmp/aegis_detection:/tmp/aegis_detection --env AEGIS_SKILL_ID --env AEGIS_SKILL_PARAMS --env PYTHONUNBUFFERED=1 %IMAGE_NAME%:%IMAGE_TAG%" |
87 | 67 |
|
88 | | -if "%TPU_FOUND%"=="true" ( |
89 | | - echo {"event": "complete", "status": "success", "accelerator_found": true, "run_command": "%RUN_CMD%", "message": "Coral TPU skill installed — Edge TPU ready"} |
90 | | - echo %LOG_PREFIX% Done! Edge TPU ready. >&2 |
91 | | - exit /b 0 |
92 | | -) else ( |
93 | | - echo {"event": "complete", "status": "partial", "accelerator_found": false, "run_command": "%RUN_CMD%", "message": "Coral TPU skill installed — no TPU detected (CPU fallback)"} |
94 | | - echo %LOG_PREFIX% Done with warning: no TPU detected. >&2 |
95 | | - exit /b 2 |
96 | | -) |
| 68 | +echo {"event": "complete", "status": "success", "run_command": "%RUN_CMD%", "message": "Coral TPU skill installed"} |
| 69 | + |
| 70 | +echo %LOG_PREFIX% Done! 1>&2 |
| 71 | +exit /b 0 |
0 commit comments