Skip to content

fix: Avm post deployment - #673

Open
Prachig-Microsoft wants to merge 5 commits into
microsoft:devfrom
Prachig-Microsoft:avm-post-deployment
Open

fix: Avm post deployment#673
Prachig-Microsoft wants to merge 5 commits into
microsoft:devfrom
Prachig-Microsoft:avm-post-deployment

Conversation

@Prachig-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This PR fixed post deployment script to pass RG as paramter for AVM deployment

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

Prachig-Microsoft and others added 5 commits August 3, 2026 21:08
- Add -MaxApiRetries (default 20) and -ApiRetryIntervalSeconds (default 15)
  parameters, giving a 5-minute default wait budget instead of 2.5 minutes.
  This accounts for the container app pulling a freshly-built image right
  after acr_build_push.ps1 and passing its startup probe before schema
  registration is attempted.
- On readiness failure, print the last HTTP/connection error plus
  diagnostics (az containerapp revision list status/replicas and recent
  az containerapp logs show console output) instead of silently skipping,
  making failures actionable.
- Build the schema-upload multipart body as raw bytes (MemoryStream)
  instead of round-tripping file bytes through UTF8.GetString, avoiding
  potential corruption of non-ASCII schema content.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds pre-flight checks that detect and auto-correct known AVM deployment
issues before running schema registration, so the script works reliably
against AVM-deployed resource groups (deployed via the bicep-registry
ContentProcessingAVM fork) without requiring a .env file:

- Storage account publicNetworkAccess: detects Disabled with 0 private
  endpoints on Non-WAF deployments and re-enables it.
- Cosmos DB publicNetworkAccess: same self-healing check for Cosmos DB
  (real bug in the published avm/res/document-db/database-account module).
- Web container app ingressTargetPort: detects when it defaulted to 80
  instead of 3000 and corrects it.
- API Easy Auth: detects when anonymous schema registration calls are
  blocked and handles it.
- AI Services multi-account auto-selection when more than one aicu-*
  account exists in the resource group.

Also updated the script to accept -ResourceGroupName as a parameter
instead of requiring a .env file, since that workflow is needed for AVM
registry deployments.

Verified end-to-end against live resource groups (pgcp4, pgcp11) deployed
via the AVM fork: all pre-flight checks correctly no-op when resources are
already healthy, and correctly self-heal when the known AVM bugs are
present. Schema and schema set registration confirmed working after each
fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
docs/AVMPostDeploymentGuide.md was out of date - it described registering
schemas via a standalone Python script (register_schema.py) with no ACR
build/push step at all. Updated it to reflect the actual required sequence
after deploying via the AVM bicep registry module:

1. Build and push container images (infra/scripts/acr_build_push.ps1
   "<resource-group>") - the AVM module provisions ACR/Container Apps but
   does not build or push application images itself.
2. Run infra/scripts/post_deployment.ps1 -ResourceGroupName
   "<resource-group>" [-ApiBaseUrl "<url>"] to register schemas and create
   the schema set (replaces the old Python script; ApiBaseUrl is optional
   thanks to auto-discovery).
3. Configure authentication (unchanged).

Also documented the AVM-specific self-healing pre-flight checks the script
now runs (storage/Cosmos DB network access, web ingress port, API auth) so
users understand what they do.

Updated prerequisites to drop the Python/pip requirement (no longer used)
and added PowerShell as a requirement instead.

Added a short pointer in README.md's Getting Started section so users who
deploy via the AVM registry module (rather than azd up) know to follow the
AVM Post Deployment Guide instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the post_deployment.ps1 script to support AVM-style deployments by allowing the resource group (and related values) to be provided as parameters, while still supporting existing azd env-based deployments.

Changes:

  • Adds parameterized AVM deployment mode (resource group, optional subscription, optional API base URL, optional AI Services account).
  • Improves post-deployment robustness with pre-flight checks (network access, ingress port, auth), API readiness polling, and richer diagnostics.
  • Refactors schema registration multipart upload to send raw bytes (avoids string re-encoding/corruption).
Suppressed comments (3)

infra/scripts/post_deployment.ps1:92

  • az containerapp list ... | ConvertFrom-Json will throw if the Azure CLI command fails or returns an empty string (stderr is suppressed via 2>$null). That prevents the later $ContainerApps.Count -eq 0 check from running and hides the underlying az error.
    # Discover container apps in the resource group
    Write-Host "[Info] Discovering container apps in resource group..."
    $ContainerApps = @(az containerapp list -g $RESOURCE_GROUP --query "[].{name:name, fqdn:properties.configuration.ingress.fqdn}" -o json 2>$null | ConvertFrom-Json)

infra/scripts/post_deployment.ps1:145

  • In AZD mode $ApiBaseUrl is constructed even if CONTAINER_API_APP_FQDN is missing/empty in the azd environment, which will result in requests to https:///schemavault/ and a confusing readiness loop. It’s better to fail fast with a clear error when the env value is not set.
    $SUBSCRIPTION_ID = azd env get-value AZURE_SUBSCRIPTION_ID
    $RESOURCE_GROUP = azd env get-value AZURE_RESOURCE_GROUP

    $ApiBaseUrl = "https://$CONTAINER_API_APP_FQDN"
}

infra/scripts/post_deployment.ps1:320

  • The script temporarily relaxes the API container app auth setting, but restoration only happens in the two explicit call sites. If the script terminates early due to an unhandled exception (e.g., schema manifest parse error, missing schema_info.json, Ctrl+C), the original auth setting may not be restored. Consider guaranteeing cleanup via a top-level try { ... } finally { Restore-ApiAuthSetting } or a trap/exit handler once $ApiAuthOriginalAction is set.
        if ($AuthAction -and $AuthAction -ne 'AllowAnonymous') {
            Write-Host "  [Warn] API container app has authentication enabled (unauthenticatedClientAction=$AuthAction)."
            Write-Host "         Temporarily allowing anonymous access for schema registration; original setting will be restored afterwards..."
            az containerapp auth update -g $RESOURCE_GROUP -n $CONTAINER_API_APP_NAME --unauthenticated-client-action AllowAnonymous -o none 2>$null
            $ApiAuthOriginalAction = $AuthAction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +88
} else {
$SUBSCRIPTION_ID = $SubscriptionId
}

$RESOURCE_GROUP = $ResourceGroupName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants