<# .SYNOPSIS Construit l'image Docker avec toutes les dépendances requises via PowerShell et WSL (Debian). .DESCRIPTION Ce script prépare les dépendances et construit l'image Docker sous WSL (Debian). .PARAMETRES -full : Si présent, effectue une construction complète de l'image Docker (équivalent à --no-cache). .EXEMPLE .\build-img.ps1 # Construction rapide (avec cache) .\build-img.ps1 -full # Construction complète sans cache .RETOURNE Affiche le succès ou les erreurs pendant la construction de l'image Docker. #> param( [switch]$full ) $ErrorActionPreference = 'Stop' try { # Determine paths $scriptDir = $PSScriptRoot $projectRoot = (Get-Item (Join-Path $scriptDir '..')).FullName # Convert Windows path to WSL path (manual, no wslpath) $wslProjectRoot = $projectRoot -replace '^([A-Za-z]):\\','/mnt/$1/' -replace '\\','/' $wslProjectRoot = $wslProjectRoot.ToLower() # Check if Docker is available in WSL Debian Write-Host "Vérification de Docker dans WSL Debian..." -ForegroundColor Cyan $dockerCheck = wsl -d Debian bash -c "docker --version" 2>&1 if ($LASTEXITCODE -ne 0) { Write-Error "Docker n'est pas disponible dans WSL Debian : $dockerCheck" exit 1 } Write-Host "Docker détecté : $dockerCheck" -ForegroundColor Green # Check if the Dockerfile exists $dockerfilePath = Join-Path $scriptDir "Dockerfile" if (-not (Test-Path $dockerfilePath)) { Write-Error "Le fichier Dockerfile n'existe pas dans $scriptDir" exit 1 } # Compose build command $noCache = if ($full) { '--no-cache' } else { '' } $innerCmd = "cd '$wslProjectRoot' && docker build $noCache -t obsiviewer-angular:latest -f docker/Dockerfile ." # Run build inside WSL Debian to use Linux Docker daemon Write-Host "Construction de l'image Docker obsiviewer-angular:latest..." -ForegroundColor Cyan $buildResult = wsl -d Debian bash -lc $innerCmd 2>&1 if ($LASTEXITCODE -ne 0) { Write-Error "Erreur lors de la construction de l'image Docker : $buildResult" exit 1 } # Verify the image was built successfully $verifyCmd = "docker image inspect obsiviewer-angular:latest" Write-Host "Vérification de l'image construite..." -ForegroundColor Cyan $verifyResult = wsl -d Debian bash -lc $verifyCmd 2>&1 if ($LASTEXITCODE -ne 0) { Write-Error "L'image Docker n'a pas été construite correctement : $verifyResult" exit 1 } Write-Host "Image Docker obsiviewer-angular:latest construite avec succès via WSL Debian." -ForegroundColor Green } catch { Write-Error "Erreur lors de la construction de l'image Docker : $_" exit 1 }