param( [switch]$Build ) $ErrorActionPreference = "Stop" $projectRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path Set-Location -LiteralPath $projectRoot $imageInputFiles = @( "Dockerfile", "requirements.txt", ".dockerignore", "compose.yaml", "compose.dev.yaml" ) $fingerprintLines = foreach ($relativePath in $imageInputFiles) { $filePath = Join-Path $projectRoot $relativePath if (Test-Path -LiteralPath $filePath) { "$relativePath=$((Get-FileHash -Algorithm SHA256 -LiteralPath $filePath).Hash)" } else { "$relativePath=MISSING" } } $fingerprintText = $fingerprintLines -join "`n" $hashAlgorithm = [System.Security.Cryptography.SHA256]::Create() try { $fingerprintBytes = [System.Text.Encoding]::UTF8.GetBytes($fingerprintText) $currentFingerprint = ([System.BitConverter]::ToString($hashAlgorithm.ComputeHash($fingerprintBytes))).Replace("-", "").ToLowerInvariant() } finally { $hashAlgorithm.Dispose() } $stateDir = Join-Path $projectRoot ".dev-state" $stateFile = Join-Path $stateDir "docker-image-inputs.sha256" $previousFingerprint = if (Test-Path -LiteralPath $stateFile) { (Get-Content -LiteralPath $stateFile -Raw).Trim() } else { "" } $inputsChanged = -not $previousFingerprint -or $previousFingerprint -ne $currentFingerprint $shouldBuild = $Build -or $inputsChanged $composeArgs = @("-f", "compose.yaml", "-f", "compose.dev.yaml", "up", "-d") if ($shouldBuild) { $composeArgs += "--build" } if ($Build) { Write-Host "Image rebuild requested explicitly with -Build." } elseif ($inputsChanged) { Write-Host "Docker image inputs changed or were not recorded yet; rebuilding automatically." } else { Write-Host "Docker image inputs are unchanged; starting without rebuild." } docker compose @composeArgs New-Item -ItemType Directory -Force -Path $stateDir | Out-Null Set-Content -LiteralPath $stateFile -Value $currentFingerprint -NoNewline docker compose -f compose.yaml -f compose.dev.yaml ps Write-Host "" Write-Host "Development server: http://127.0.0.1:8010" Write-Host "Source edits reload automatically." Write-Host "Dependency and Docker image-setting changes are detected and rebuilt automatically." Write-Host "Use -Build only when you intentionally want to force a clean image check."