# local-dev.ps1 — Build and run any app locally with docker compose # Usage: .\local-dev.ps1 [-Path ] [-Down] [-Logs] [-Build] # # Examples: # .\local-dev.ps1 -Path C:\.bucket\repos.gitea\actual.budget.report # .\local-dev.ps1 -Path C:\.bucket\repos.gitea\dotrepo.audiosphere\Projects\AudioSphere -Build # .\local-dev.ps1 -Path C:\.bucket\repos.gitea\dotrepo.audioevents\AudioEvents -Logs # .\local-dev.ps1 -Path C:\.bucket\repos.gitea\dotrepo.audioevents\AudioEvents -Down param( [Parameter(Mandatory=$true)] [string]$Path, [switch]$Build, [switch]$Down, [switch]$Logs ) $ErrorActionPreference = "Stop" # Resolve and validate path $ProjectDir = Resolve-Path $Path -ErrorAction Stop $ComposePath = Join-Path $ProjectDir "docker-compose.yml" if (-not (Test-Path $ComposePath)) { Write-Host "ERROR: No docker-compose.yml found in $ProjectDir" -ForegroundColor Red exit 1 } Write-Host "Project: $ProjectDir" -ForegroundColor Cyan Push-Location $ProjectDir try { if ($Down) { Write-Host "`nStopping containers..." -ForegroundColor Yellow docker compose down Write-Host "Done." -ForegroundColor Green exit 0 } if ($Logs) { Write-Host "`nShowing logs (Ctrl+C to stop)..." -ForegroundColor Yellow docker compose logs -f exit 0 } # Build and start Write-Host "`nBuilding and starting..." -ForegroundColor Yellow if ($Build) { docker compose build --no-cache } docker compose up -d --build --force-recreate Write-Host "`nContainers:" -ForegroundColor Cyan docker compose ps # Extract port from docker-compose.yml $portLine = Select-String -Path $ComposePath -Pattern '(\d+):(\d+)' | Select-Object -First 1 if ($portLine -match '"?\$\{HOST_PORT:-(\d+)\}:(\d+)"?') { $hostPort = $Matches[1] Write-Host "`nApp running at: http://localhost:$hostPort" -ForegroundColor Green } elseif ($portLine -match '"?(\d+):(\d+)"?') { $hostPort = $Matches[1] Write-Host "`nApp running at: http://localhost:$hostPort" -ForegroundColor Green } Write-Host "`nUseful commands:" -ForegroundColor DarkGray Write-Host " Logs: .\local-dev.ps1 -Path '$Path' -Logs" -ForegroundColor DarkGray Write-Host " Stop: .\local-dev.ps1 -Path '$Path' -Down" -ForegroundColor DarkGray Write-Host " Rebuild: .\local-dev.ps1 -Path '$Path' -Build" -ForegroundColor DarkGray } finally { Pop-Location }