Files
ObsiGate/build.ps1
T
bruno 84bda90065 fix(version): afficher 2.2.0 au lieu de 2.1.0 dans l'UI
Les 3 affichages (badge header, A propos, pied de l'aide) lisaient la version bakee dans l'image Docker, qui retombait sur l'ARG VERSION=2.1.0 car build.sh/build.ps1 ne transmettaient pas le tag git.

- Dockerfile / docker-compose.yml : defaut porte a 2.2.0
- build.sh : export VERSION pour substitution par docker compose
- build.ps1 : version derivee de git describe puis exportee
- CHANGELOG / ROADMAP alignes sur 2.2.0
2026-09-11 09:57:59 -04:00

166 lines
5.0 KiB
PowerShell

# =============================================================================
# ObsiGate — Script de build et déploiement Docker (Windows PowerShell)
# =============================================================================
#
# Usage :
# .\build.ps1 [-Prod | -Test] [OPTIONS]
#
# Environnements :
# -Prod Production (défaut) — docker-compose.yml
# -Test Test Windows (Docker Desktop) — docker-compose.test-win.yml
#
# Options :
# -BuildOnly Construit l'image sans démarrer le conteneur
# -NoCache Rebuild complet sans cache Docker (défaut)
# -UseCache Utilise le cache Docker (plus rapide si peu de changements)
# -Help Affiche cette aide
#
# Exemples :
# .\build.ps1 # Production
# .\build.ps1 -Test # Test Windows
# .\build.ps1 -Test -BuildOnly # Build test sans démarrer
# .\build.ps1 -Prod -UseCache # Production avec cache
# =============================================================================
param(
[switch]$Prod,
[switch]$Test,
[switch]$BuildOnly,
[switch]$NoCache,
[switch]$UseCache,
[switch]$Help
)
# ----- Helpers -----
function Write-Info { Write-Host "[INFO] $args" -ForegroundColor Cyan }
function Write-Ok { Write-Host "[OK] $args" -ForegroundColor Green }
function Write-Warn { Write-Host "[WARN] $args" -ForegroundColor Yellow }
function Write-Error { Write-Host "[ERR] $args" -ForegroundColor Red }
# ----- Help -----
if ($Help) {
Get-Help $PSCommandPath -Detailed
exit 0
}
# ----- Select environment -----
$EnvMode = "prod"
$ComposeEnvName = "production"
if ($Test) {
$EnvMode = "test-win"
$ComposeEnvName = "test Windows"
}
switch ($EnvMode) {
"prod" { $ComposeFile = "docker-compose.yml" }
"test-win" { $ComposeFile = "docker-compose.test-win.yml" }
}
# ----- Pre-flight checks -----
$dockerVersion = docker --version 2>$null
if (-not $dockerVersion) {
Write-Error "Docker est introuvable. Installez Docker Desktop avant de continuer."
exit 1
}
Write-Ok "Docker détecté"
$composeVersion = docker compose version 2>$null
if (-not $composeVersion) {
Write-Error "Docker Compose est introuvable (plugin docker compose requis)."
exit 1
}
Write-Ok $composeVersion.Trim()
# ----- Validate compose file -----
if (-not (Test-Path $ComposeFile)) {
Write-Error "$ComposeFile introuvable dans $(Get-Location)"
exit 1
}
Write-Host ""
Write-Info "=== ObsiGate — Build & Deploy ($ComposeEnvName) ==="
Write-Info "Fichier compose : $ComposeFile"
# ----- Test mode: create test directories -----
if ($EnvMode -eq "test-win") {
Write-Info "Création des dossiers de test..."
$testVault = "C:\dev\git\python\ObsiGate\test_vault"
$testDir = "C:\dev\git\python\ObsiGate\test_dir"
if (-not (Test-Path $testVault)) {
New-Item -ItemType Directory -Force -Path $testVault | Out-Null
}
if (-not (Test-Path $testDir)) {
New-Item -ItemType Directory -Force -Path $testDir | Out-Null
}
$welcomeFile = Join-Path $testVault "Accueil.md"
if (-not (Test-Path $welcomeFile)) {
@"
# Bienvenue dans le vault de test
Ce vault est utilisé pour les tests de développement d'ObsiGate.
"@ | Out-File -Encoding UTF8 -FilePath $welcomeFile
Write-Ok "Note de test créée : test_vault\Accueil.md"
}
}
# ----- Resolve version from git before Docker build -----
$Version = (git describe --tags --dirty 2>$null) -replace '^v',''
if (-not $Version) { $Version = "0.0.0" }
$Version | Out-File -Encoding ascii -NoNewline -FilePath "backend\VERSION"
# Export so docker compose substitutes ${VERSION} in the build arg
$env:VERSION = $Version
Write-Info "Version : $Version"
# ----- Build the image -----
$BuildArgs = @("-f", $ComposeFile)
if (-not $UseCache) {
$BuildArgs += "--no-cache"
Write-Info "Construction de l'image Docker (sans cache)..."
} else {
Write-Info "Construction de l'image Docker (avec cache)..."
}
docker compose @BuildArgs build
if ($LASTEXITCODE -ne 0) {
Write-Error "Échec de la construction de l'image Docker."
exit $LASTEXITCODE
}
Write-Ok "Image construite avec succès"
# ----- Stop if build-only -----
if ($BuildOnly) {
Write-Host ""
Write-Info "Mode build-only : conteneur non démarré."
Write-Info "Pour démarrer manuellement : docker compose -f $ComposeFile up -d"
exit 0
}
# ----- Start the container -----
Write-Info "Démarrage du conteneur..."
docker compose -f $ComposeFile up -d --remove-orphans
if ($LASTEXITCODE -ne 0) {
Write-Error "Échec du démarrage du conteneur."
exit $LASTEXITCODE
}
Write-Ok "Conteneur démarré"
# ----- Show status & tip -----
Write-Host ""
Write-Info "Statut du conteneur :"
docker compose -f $ComposeFile ps
Write-Host ""
Write-Info "Application accessible sur http://localhost:2020"
if ($EnvMode -eq "prod") {
Write-Info "Login : admin / (mot de passe dans .env)"
} else {
Write-Info "Login : admin / test123"
}
Write-Host ""
Write-Info "Logs (Ctrl+C pour quitter) :"
docker compose -f $ComposeFile logs --tail=20 -f