feat: desktop — connexion compte central + environnement prod/dev (#230)
Liaison d'appareil sur og/og-dev, validation du jeton draco et ouverture de la session de l'admin local. Sélecteur prod/dev (Configuration + premier lancement), admin local par défaut admin/chab30, sans impact sur le web Docker. Inclut BUG-126 (runtime python-embed/_pth + copie de backend/frontend + signature updater opt-in) et BUG-127 (retour /liaison même hôte).
This commit is contained in:
+137
-29
@@ -5,14 +5,26 @@ REM Prérequis : Rust, Tauri CLI, NSIS, Python 3.11 embed
|
||||
REM ============================================================
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Always run from the script directory, regardless of where the
|
||||
REM caller invoked us from. Without this, a call like
|
||||
REM `desktop\build-windows.bat` from the repo root would download into
|
||||
REM the repo root and, worse, delete the repo's backend/ and frontend/
|
||||
REM directories in the staging/cleanup steps.
|
||||
cd /d "%~dp0"
|
||||
|
||||
echo ========================================
|
||||
echo ObsiGate Desktop — Build Windows
|
||||
echo ========================================
|
||||
echo.
|
||||
|
||||
REM ── 0. Kill any leftover backend from a previous run ──────────
|
||||
echo [0/6] Killing leftover Python processes...
|
||||
taskkill /F /IM python.exe 2>nul
|
||||
REM ── 0. Close a running build so the exe can be replaced ───────
|
||||
REM Windows verrouille l'exécutable : sans cette étape, cargo échoue
|
||||
REM avec « Access is denied » si l'application tourne encore.
|
||||
echo [0/6] Closing running ObsiGate Desktop / embedded backend...
|
||||
taskkill /F /IM obsigate-desktop.exe >nul 2>&1
|
||||
REM Only target the python.exe shipped in python-embed/, never the
|
||||
REM user's own Python installs.
|
||||
powershell -NoProfile -Command "Get-Process python -ErrorAction SilentlyContinue | Where-Object { $_.Path -like '*\python-embed\python.exe' } | Stop-Process -Force -ErrorAction SilentlyContinue"
|
||||
echo.
|
||||
|
||||
REM ── 1. Vérifier les prérequis ─────────────────────────────────
|
||||
@@ -23,24 +35,82 @@ echo ✅ Rust + Tauri OK
|
||||
|
||||
REM ── 2. Préparer Python 3.11 embed ─────────────────────────────
|
||||
echo [2/6] Preparing Python embed...
|
||||
echo 📥 Downloading Python 3.11 embed...
|
||||
if exist "python-embed" rmdir /s /q "python-embed"
|
||||
curl -L -o python-embed.zip "https://www.python.org/ftp/python/3.11.9/python-3.11.9-embed-amd64.zip"
|
||||
powershell Expand-Archive -Path python-embed.zip -DestinationPath python-embed\
|
||||
del python-embed.zip
|
||||
if errorlevel 1 (
|
||||
echo ❌ Cannot remove python-embed - a process is still using it
|
||||
goto :fail
|
||||
)
|
||||
|
||||
REM Enable pip and site-packages + parent dir for 'import backend'
|
||||
echo import site >> python-embed\python311._pth
|
||||
echo ..>> python-embed\python311._pth
|
||||
echo 📥 Downloading Python 3.11 embed...
|
||||
curl -L --fail -o python-embed.zip "https://www.python.org/ftp/python/3.11.9/python-3.11.9-embed-amd64.zip"
|
||||
if errorlevel 1 (
|
||||
echo ❌ Python embed download failed
|
||||
goto :fail
|
||||
)
|
||||
REM Use the native bsdtar when available: Expand-Archive can fail when a
|
||||
REM PS7 PSModulePath is inherited by Windows PowerShell (overload error),
|
||||
REM and its failure is non-fatal (exit code 0), so we verify python.exe
|
||||
REM afterwards in all cases.
|
||||
if not exist "python-embed" mkdir "python-embed"
|
||||
where tar >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
tar -xf python-embed.zip -C python-embed
|
||||
) else (
|
||||
powershell -NoProfile -Command "Expand-Archive -Path 'python-embed.zip' -DestinationPath 'python-embed'"
|
||||
)
|
||||
if errorlevel 1 (
|
||||
echo ❌ Python embed extraction failed
|
||||
goto :fail
|
||||
)
|
||||
if not exist "python-embed\python.exe" (
|
||||
echo ❌ Python embed extraction failed - python.exe missing
|
||||
goto :fail
|
||||
)
|
||||
del /q python-embed.zip
|
||||
|
||||
REM Write the ._pth explicitly instead of appending to the archive's
|
||||
REM file. An embedded Python finds its standard library ONLY through
|
||||
REM this file: without python311.zip + '.' it cannot import `encodings`
|
||||
REM and the backend dies before serving a single request (the UI then
|
||||
REM stays on the unstyled Tauri splash — "CSS is broken").
|
||||
REM python311.zip → stdlib
|
||||
REM . → python-embed\ (DLLs, .pyd)
|
||||
REM import site → enables Lib\site-packages
|
||||
REM .. → exe dir (so `import backend` works next to the .exe)
|
||||
(
|
||||
echo python311.zip
|
||||
echo .
|
||||
echo import site
|
||||
echo ..
|
||||
) > python-embed\python311._pth
|
||||
|
||||
REM Download get-pip.py (embed Python doesn't include ensurepip)
|
||||
echo 📥 Downloading get-pip.py...
|
||||
curl -L -o get-pip.py "https://bootstrap.pypa.io/get-pip.py"
|
||||
curl -L --fail -o get-pip.py "https://bootstrap.pypa.io/get-pip.py"
|
||||
if errorlevel 1 (
|
||||
echo ❌ get-pip.py download failed
|
||||
goto :fail
|
||||
)
|
||||
python-embed\python.exe get-pip.py --no-cache-dir
|
||||
del get-pip.py
|
||||
if errorlevel 1 (
|
||||
echo ❌ pip bootstrap failed
|
||||
goto :fail
|
||||
)
|
||||
del /q get-pip.py
|
||||
|
||||
REM Install dependencies
|
||||
python-embed\python.exe -m pip install --no-cache-dir -r ..\backend\requirements.txt
|
||||
if errorlevel 1 (
|
||||
echo ❌ Python dependencies installation failed
|
||||
goto :fail
|
||||
)
|
||||
|
||||
REM Fail fast if the runtime is unusable (missing stdlib / deps).
|
||||
python-embed\python.exe -c "import encodings, uvicorn, fastapi, pyotp"
|
||||
if errorlevel 1 (
|
||||
echo ❌ python-embed sanity check failed ^(stdlib or deps missing^)
|
||||
goto :fail
|
||||
)
|
||||
echo ✅ Python embed ready
|
||||
|
||||
REM ── 2b. Copier backend + frontend localement pour le bundle ────
|
||||
@@ -52,10 +122,24 @@ xcopy /E /I /Q /Y "..\frontend" "frontend"
|
||||
echo ✅ Staged
|
||||
|
||||
REM ── 2c. Clé de signature des mises à jour (updater Tauri) ──────
|
||||
REM La clé privée peut être protégée par mot de passe. Tauri CLI
|
||||
REM demande alors ce mot de passe de façon interactive (une fois par
|
||||
REM invocation, donc deux fois à cause du repli NSIS) — impossible à
|
||||
REM fournir dans un script non surveillé. On ne signe donc que si le
|
||||
REM mot de passe est explicitement fourni dans l'environnement :
|
||||
REM set TAURI_SIGNING_PRIVATE_KEY_PASSWORD=*** & build-windows.bat
|
||||
REM Sinon les artefacts .sig sont désactivés, sans aucune invite.
|
||||
set "SIGN_CONFIG="
|
||||
if exist "obsigate-updater.key" (
|
||||
set /p TAURI_SIGNING_PRIVATE_KEY=<obsigate-updater.key
|
||||
echo [2c/6] Cle updater trouvee - artefacts .sig actives
|
||||
if defined TAURI_SIGNING_PRIVATE_KEY_PASSWORD (
|
||||
set "TAURI_SIGNING_PRIVATE_KEY_PATH=obsigate-updater.key"
|
||||
echo [2c/6] Cle updater + mot de passe fournis - artefacts .sig actives
|
||||
) else (
|
||||
> updater-off.json echo {"bundle":{"createUpdaterArtifacts":false}}
|
||||
set "SIGN_CONFIG=--config updater-off.json"
|
||||
echo [2c/6] Cle updater presente mais TAURI_SIGNING_PRIVATE_KEY_PASSWORD non defini
|
||||
echo [2c/6] Build sans artefacts .sig ^(aucune invite de mot de passe^)
|
||||
)
|
||||
) else (
|
||||
> updater-off.json echo {"bundle":{"createUpdaterArtifacts":false}}
|
||||
set "SIGN_CONFIG=--config updater-off.json"
|
||||
@@ -64,32 +148,39 @@ if exist "obsigate-updater.key" (
|
||||
|
||||
REM ── 3. Build Tauri ────────────────────────────────────────────
|
||||
echo [3/6] Building Tauri application (NSIS + MSI installers)...
|
||||
cargo tauri build --target x86_64-pc-windows-msvc --bundles nsis,msi %SIGN_CONFIG%
|
||||
REM `--ci` interdit toute invite interactive (dont le mot de passe de
|
||||
REM la clé updater) : en cas de valeur manquante, le build échoue
|
||||
REM proprement au lieu de bloquer le terminal.
|
||||
cargo tauri build --ci --target x86_64-pc-windows-msvc --bundles nsis,msi %SIGN_CONFIG%
|
||||
if errorlevel 1 (
|
||||
echo ⚠️ Standard bundle build failed, trying fallback to NSIS only...
|
||||
cargo tauri build --target x86_64-pc-windows-msvc --bundles nsis %SIGN_CONFIG%
|
||||
cargo tauri build --ci --target x86_64-pc-windows-msvc --bundles nsis %SIGN_CONFIG%
|
||||
if errorlevel 1 (
|
||||
echo ❌ Build failed!
|
||||
goto :cleanup
|
||||
goto :fail
|
||||
)
|
||||
)
|
||||
echo ✅ Build successful
|
||||
|
||||
REM ── 4. Copier python-embed vers output dir (dev local) ─────────
|
||||
echo [4/6] Copying python-embed to output dir...
|
||||
REM ── 4. Copier le runtime vers l'output dir (exe lancé sur place) ─
|
||||
REM L'exe résout `python-embed/python.exe`, `backend/` (PYTHONPATH) et
|
||||
REM `frontend/` (fichiers statiques servis par FastAPI) *à côté de lui*.
|
||||
REM Sans ces trois dossiers, l'exe ne démarre aucun backend : la fenêtre
|
||||
REM reste sur le HTML embarqué par Tauri, dont les liens /static/* ne
|
||||
REM résolvent pas → interface sans CSS.
|
||||
echo [4/6] Copying runtime (python-embed, backend, frontend)...
|
||||
set "OUTDIR=target\x86_64-pc-windows-msvc\release"
|
||||
if exist "%OUTDIR%\python-embed" rmdir /s /q "%OUTDIR%\python-embed" 2>nul
|
||||
xcopy /E /I /Q /Y "python-embed" "%OUTDIR%\python-embed"
|
||||
echo ..>> "%OUTDIR%\python-embed\python311._pth"
|
||||
for %%D in (python-embed backend frontend) do (
|
||||
if exist "%OUTDIR%\%%D" rmdir /s /q "%OUTDIR%\%%D"
|
||||
xcopy /E /I /Q /Y "%%D" "%OUTDIR%\%%D" >nul
|
||||
if errorlevel 1 (
|
||||
echo ❌ Copy of %%D to %OUTDIR% failed
|
||||
goto :fail
|
||||
)
|
||||
)
|
||||
echo ✅ Dev runtime ready
|
||||
|
||||
:cleanup
|
||||
REM ── 5. Nettoyer les dossiers stagés ───────────────────────────
|
||||
echo [5/6] Cleaning up staged dirs...
|
||||
if exist "backend" rmdir /s /q "backend"
|
||||
if exist "frontend" rmdir /s /q "frontend"
|
||||
if exist "updater-off.json" del /q "updater-off.json"
|
||||
echo ✅ Cleaned
|
||||
call :cleanup
|
||||
|
||||
REM ── 6. Résultats ───────────────────────────────────────────────
|
||||
echo [6/6] Binaries generated:
|
||||
@@ -98,3 +189,20 @@ dir /b "%OUTDIR%\bundle\msi\*.msi" 2>nul
|
||||
echo.
|
||||
echo ✅ Done! Installers generated in: %OUTDIR%\bundle\
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:cleanup
|
||||
REM ── 5. Nettoyer les dossiers stagés ───────────────────────────
|
||||
echo [5/6] Cleaning up staged dirs...
|
||||
if exist "backend" rmdir /s /q "backend"
|
||||
if exist "frontend" rmdir /s /q "frontend"
|
||||
if exist "updater-off.json" del /q "updater-off.json"
|
||||
echo ✅ Cleaned
|
||||
goto :eof
|
||||
|
||||
:fail
|
||||
echo.
|
||||
echo ❌ Build failed - see messages above.
|
||||
call :cleanup
|
||||
endlocal
|
||||
exit /b 1
|
||||
|
||||
Reference in New Issue
Block a user