# clean-slate.ps1 # Wipes all Aspire-managed containers, volumes, and local state for a full clean provision. # clarity-net is preserved — it was created manually and is permanent. # # Usage: .\scripts\clean-slate.ps1 # Add -KeepVolumes to stop/remove containers but leave postgres/vault data intact. param( [switch]$KeepVolumes ) $repoRoot = Split-Path -Parent $PSScriptRoot Write-Host "`n=== Clarity Clean Slate ===" -ForegroundColor Cyan # ── 1. Containers ──────────────────────────────────────────────────────────── Write-Host "`n[1/4] Stopping and removing containers..." -ForegroundColor Yellow $containers = docker ps -a --format "{{.Names}}" | Where-Object { $_ -notmatch "^\s*$" } if ($containers) { foreach ($c in $containers) { Write-Host " Removing $c" docker stop $c --time 5 2>$null | Out-Null docker rm $c 2>$null | Out-Null } } else { Write-Host " No containers found." } # ── 2. Volumes ──────────────────────────────────────────────────────────────── if ($KeepVolumes) { Write-Host "`n[2/4] Skipping volume wipe (-KeepVolumes set)." -ForegroundColor DarkYellow } else { Write-Host "`n[2/4] Removing anonymous and dangling volumes..." -ForegroundColor Yellow docker volume prune -f 2>$null | Out-Null Write-Host " Done." } # ── 3. Stale Docker networks (keep clarity-net) ──────────────────────────── Write-Host "`n[3/4] Pruning stale networks (clarity-net preserved)..." -ForegroundColor Yellow docker network prune -f 2>$null | Out-Null Write-Host " Done." # ── 4. Local state on disk ──────────────────────────────────────────────────── Write-Host "`n[4/4] Cleaning local disk state..." -ForegroundColor Yellow # VaultData — remove init.json and raft data so Vault re-initializes fresh $vaultData = Join-Path $repoRoot "ControlPlane.AppHost\VaultData" if (Test-Path $vaultData) { Get-ChildItem $vaultData -Recurse -File | ForEach-Object { Write-Host " Removing $_" Remove-Item $_.FullName -Force } } else { Write-Host " VaultData folder not found, skipping." } # ClientAssets XMLs — provisioning records for old tenants $clientAssets = Join-Path $repoRoot "ClientAssets" if (Test-Path $clientAssets) { $xmlFiles = Get-ChildItem $clientAssets -Filter "*.xml" if ($xmlFiles) { foreach ($f in $xmlFiles) { Write-Host " Removing $($f.Name)" Remove-Item $f.FullName -Force } } else { Write-Host " No XML files found in ClientAssets." } } else { Write-Host " ClientAssets folder not found, skipping." } # nginx conf.d — per-tenant route configs from previous provisioning runs $nginxConfD = Join-Path $repoRoot "ControlPlane.AppHost\NginxConfig\conf.d" if (Test-Path $nginxConfD) { $confFiles = Get-ChildItem $nginxConfD -Filter "*.conf" if ($confFiles) { foreach ($f in $confFiles) { Write-Host " Removing $($f.Name)" Remove-Item $f.FullName -Force } } else { Write-Host " No .conf files found in nginx conf.d." } } else { Write-Host " NginxConfig/conf.d folder not found, skipping." } # ── Done ───────────────────────────────────────────────────────────────────── Write-Host "`n=== Clean slate complete ===" -ForegroundColor Green Write-Host "clarity-net is still present: $(docker network ls --format '{{.Name}}' | Where-Object { $_ -eq 'clarity-net' })" -ForegroundColor Green Write-Host "`nNext steps:" Write-Host " 1. Start ControlPlane.AppHost in Visual Studio" Write-Host " 2. Wait for all containers to be healthy" Write-Host " 3. Submit a provisioning job"