83 lines
2.9 KiB
PowerShell
83 lines
2.9 KiB
PowerShell
# Nettoyage complet DevOps Stack
|
||
Write-Host "🧹 NETTOYAGE DEVOPS STACK" -ForegroundColor Yellow
|
||
Write-Host "==========================" -ForegroundColor Yellow
|
||
Write-Host ""
|
||
|
||
# 1. Arrêter Docker Compose
|
||
Write-Host "[1/4] Arrêt Docker Compose..." -ForegroundColor Yellow
|
||
try {
|
||
if (Test-Path "..\docker\docker-compose.yml") {
|
||
Set-Location "..\docker"
|
||
docker-compose down -v # -v pour supprimer les volumes
|
||
Write-Host " ✅ Docker Compose arrêté" -ForegroundColor Green
|
||
Set-Location $PSScriptRoot
|
||
}
|
||
} catch {
|
||
Write-Host " ⚠️ Aucun service Docker Compose en cours" -ForegroundColor Gray
|
||
}
|
||
|
||
# 2. Nettoyer Kubernetes
|
||
Write-Host "[2/4] Nettoyage Kubernetes..." -ForegroundColor Yellow
|
||
try {
|
||
# Supprimer le namespace (supprime tout à l'intérieur)
|
||
kubectl delete namespace devops-demo --ignore-not-found=true
|
||
kubectl delete namespace terraform-ns --ignore-not-found=true
|
||
|
||
# Désinstaller Helm
|
||
helm uninstall devops-release --namespace devops-demo --ignore-not-found=true
|
||
|
||
Write-Host " ✅ Kubernetes nettoyé" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host " ⚠️ Kubernetes non configuré ou déjà nettoyé" -ForegroundColor Gray
|
||
}
|
||
|
||
# 3. Nettoyer Docker
|
||
Write-Host "[3/4] Nettoyage Docker..." -ForegroundColor Yellow
|
||
try {
|
||
# Arrêter tous les conteneurs
|
||
docker stop $(docker ps -aq) 2>$null
|
||
|
||
# Supprimer tous les conteneurs
|
||
docker rm $(docker ps -aq) 2>$null
|
||
|
||
# Supprimer toutes les images
|
||
docker rmi $(docker images -q) -f 2>$null
|
||
|
||
# Nettoyer le système
|
||
docker system prune -a -f --volumes
|
||
|
||
Write-Host " ✅ Docker nettoyé" -ForegroundColor Green
|
||
} catch {
|
||
Write-Host " ℹ️ Aucune ressource Docker à nettoyer" -ForegroundColor Gray
|
||
}
|
||
|
||
# 4. Nettoyer Terraform
|
||
Write-Host "[4/4] Nettoyage Terraform..." -ForegroundColor Yellow
|
||
try {
|
||
if (Test-Path "..\terraform") {
|
||
Set-Location "..\terraform"
|
||
|
||
# Détruire l'infrastructure si terraform.tfstate existe
|
||
if (Test-Path "terraform.tfstate") {
|
||
terraform destroy -auto-approve 2>$null
|
||
}
|
||
|
||
# Supprimer les fichiers temporaires
|
||
Remove-Item -Path "*.tfstate*", ".terraform*", "terraform.tfstate.backup" -Force -ErrorAction SilentlyContinue
|
||
|
||
Write-Host " ✅ Terraform nettoyé" -ForegroundColor Green
|
||
Set-Location $PSScriptRoot
|
||
}
|
||
} catch {
|
||
Write-Host " ℹ️ Terraform non configuré" -ForegroundColor Gray
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "========================================" -ForegroundColor Green
|
||
Write-Host " NETTOYAGE TERMINÉ !" -ForegroundColor Green
|
||
Write-Host "========================================" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "✅ Toutes les ressources ont été nettoyées" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "Pour recommencer :" -ForegroundColor Cyan
|
||
Write-Host " .\setup.ps1" -ForegroundColor Gray |