$ErrorActionPreference = "Stop" # Load .env from script directory $envFile = Join-Path $PSScriptRoot ".env" if (Test-Path $envFile) { Get-Content $envFile | Where-Object { $_ -match '^\s*[^#]\S+=\S' } | ForEach-Object { $k, $v = $_ -split '=', 2 [System.Environment]::SetEnvironmentVariable($k.Trim(), $v.Trim(), 'Process') } } $ACR = "koogleacr" $APP = "ka-note" $RG = "rg-koogle-prod" $IMAGE = "$ACR.azurecr.io/${APP}:latest" # Bump patch version in VERSION file $versionFile = Join-Path $PSScriptRoot "VERSION" $current = (Get-Content $versionFile -Raw).Trim() $parts = $current -split '\.' $parts[2] = [int]$parts[2] + 1 $VERSION = $parts -join '.' Set-Content $versionFile $VERSION -Encoding UTF8 -NoNewline Write-Host "=== Version: $VERSION ===" -ForegroundColor Yellow Write-Host "=== Generate migrations ===" -ForegroundColor Cyan Push-Location server npx drizzle-kit generate Pop-Location if ($LASTEXITCODE -ne 0) { throw "Migration generation failed" } Write-Host "=== Login to ACR ===" -ForegroundColor Cyan $token = (az acr login --name $ACR --expose-token --output tsv --query accessToken) if ($LASTEXITCODE -ne 0) { throw "ACR token fetch failed" } $token | docker login "$ACR.azurecr.io" --username 00000000-0000-0000-0000-000000000000 --password-stdin if ($LASTEXITCODE -ne 0) { throw "ACR login failed" } Write-Host "=== Build Docker image ===" -ForegroundColor Cyan docker build -t $IMAGE --no-cache ` --build-arg VITE_AZURE_CLIENT_ID=$env:AZURE_CLIENT_ID ` --build-arg VITE_AZURE_TENANT_ID=$env:AZURE_TENANT_ID ` --build-arg APP_VERSION=$VERSION ` . if ($LASTEXITCODE -ne 0) { throw "Docker build failed" } Write-Host "=== Push to ACR ===" -ForegroundColor Cyan docker push $IMAGE if ($LASTEXITCODE -ne 0) { throw "Docker push failed" } Write-Host "=== Set App Service environment ===" -ForegroundColor Cyan az webapp config appsettings set --name $APP --resource-group $RG --settings ` AZURE_CLIENT_ID=$env:AZURE_CLIENT_ID ` AZURE_TENANT_ID=$env:AZURE_TENANT_ID | Out-Null Write-Host "=== Restart App Service ===" -ForegroundColor Cyan az webapp restart --name $APP --resource-group $RG Write-Host "=== Done! $VERSION deployed ===" -ForegroundColor Green Write-Host "Check: https://$APP.azurewebsites.net"