Add run script
This commit is contained in:
parent
1bcc2fb4f0
commit
0859bd5625
56
run.ps1
Normal file
56
run.ps1
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# run.ps1 — script d'installation et de démarrage
|
||||||
|
|
||||||
|
Param()
|
||||||
|
|
||||||
|
# 1. Detection de la CLI Docker (docker vs docker-compose)
|
||||||
|
Write-Host "=== Verification de Docker CLI ==="
|
||||||
|
$dockerCmd = $null
|
||||||
|
try {
|
||||||
|
docker version --format '{{.Client.Version}}' > $null 2>&1
|
||||||
|
$dockerCmd = 'docker'
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
docker-compose version > $null 2>&1
|
||||||
|
$dockerCmd = 'docker-compose'
|
||||||
|
} catch {
|
||||||
|
$dockerCmd = $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dockerCmd) {
|
||||||
|
Write-Host "Docker CLI detectee : $dockerCmd"
|
||||||
|
} else {
|
||||||
|
Write-Host "Docker non trouve. Installation de Docker Desktop..."
|
||||||
|
$installerUrl = 'https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe'
|
||||||
|
$installerPath = Join-Path -Path $PSScriptRoot -ChildPath 'docker-installer.exe'
|
||||||
|
Invoke-WebRequest -UseBasicParsing -Uri $installerUrl -OutFile $installerPath
|
||||||
|
Start-Process -FilePath $installerPath -ArgumentList '/quiet' -Wait
|
||||||
|
Remove-Item -Path $installerPath -Force
|
||||||
|
Write-Host "Installation de Docker Desktop terminee."
|
||||||
|
$dockerCmd = 'docker'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 2. Se placer dans le repertoire contenant docker-compose.yml
|
||||||
|
Push-Location
|
||||||
|
$installRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
|
||||||
|
Set-Location $installRoot
|
||||||
|
|
||||||
|
# 3. Creation du dossier de logs
|
||||||
|
$logDir = Join-Path -Path $installRoot -ChildPath 'logs'
|
||||||
|
if (-not (Test-Path $logDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $logDir | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# 4. Demarrage de la stack et redirection des logs
|
||||||
|
$composeCmd = if ($dockerCmd -eq 'docker') { 'docker compose' } else { 'docker-compose' }
|
||||||
|
Write-Host "Lancement de '$composeCmd up -d'..."
|
||||||
|
$runLog = Join-Path -Path $logDir -ChildPath 'run.log'
|
||||||
|
# On passe par cmd.exe pour que > et 2>&1 fonctionnent correctement
|
||||||
|
& cmd.exe /c "$composeCmd up -d > `"$runLog`" 2>&1"
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "Erreur lors du demarrage. Voir le log : $runLog"
|
||||||
|
} else {
|
||||||
|
Write-Host "Stack demarree. Logs disponibles dans : $runLog"
|
||||||
|
}
|
||||||
|
|
||||||
|
Pop-Location
|
Loading…
x
Reference in New Issue
Block a user