$npx -y skills add DanWahlin/github-azure-agentic-journeys --skill container-apps-deploymentContainer Apps deployment gotchas and SPA frontend patterns for Azure. Supplements the official azure-prepare plugin skill with additional patterns for zone redundancy, azure.yaml configuration, and SPA frontend deployment (VITE_API_URL). USE FOR: Container Apps zone redundancy e
| 1 | # Container Apps Deployment Patterns |
| 2 | |
| 3 | Supplements the official `azure-prepare` plugin skill with additional gotchas for Container Apps deployments — zone redundancy, azure.yaml, and SPA frontend patterns. |
| 4 | |
| 5 | > **📖 ACR authentication:** Use a deterministic two-phase pattern. Provision Container Apps with a public placeholder image and system-assigned identity, grant `AcrPull`, then configure `configuration.registries` with the ACR login server and `identity: 'system'` before deploying private images. Some azd versions call `az containerapp registry set` automatically and some do not. Never assume that implicit step occurred; verify the registry configuration before the first private-image deployment. |
| 6 | |
| 7 | ## Region-Specific Gotchas |
| 8 | |
| 9 | ### Container Apps Environment `zoneRedundant` |
| 10 | |
| 11 | The AVM module `br/public:avm/res/app/managed-environment` may default `zoneRedundant` to true. Several regions (including `westus`) don't support it. |
| 12 | |
| 13 | ```bicep |
| 14 | module cae 'br/public:avm/res/app/managed-environment:0.8.1' = { |
| 15 | params: { |
| 16 | // ... |
| 17 | zoneRedundant: false // Required for westus and other regions without zone support |
| 18 | } |
| 19 | } |
| 20 | ``` |
| 21 | |
| 22 | **Without this:** `azd up` fails with "Zone redundancy is not currently supported in this region". |
| 23 | |
| 24 | ## azure.yaml Configuration |
| 25 | |
| 26 | ### Docker services require `language` field |
| 27 | |
| 28 | azd requires either `language` or `image` on each service, even when `docker.path` is specified: |
| 29 | |
| 30 | ```yaml |
| 31 | services: |
| 32 | api: |
| 33 | host: containerapp |
| 34 | language: ts # REQUIRED — azd won't infer from Dockerfile |
| 35 | docker: |
| 36 | path: api/Dockerfile |
| 37 | context: api |
| 38 | remoteBuild: true |
| 39 | ``` |
| 40 | |
| 41 | Declare each service whose image azd owns this way. AIMarket declares only `api`; Bicep creates its web Container App and the project postdeploy hook owns the storefront ACR build and update. **Without `language`:** `azd up` fails with "must specify language or image". **Without `remoteBuild: true`:** `azd` can require a local Docker daemon. |
| 42 | |
| 43 | ### Cross-platform hooks |
| 44 | |
| 45 | This repository requires `azd` 1.28.0 or later and Node.js 24 LTS or later. Use JavaScript or TypeScript hooks referenced directly from `azure.yaml`; `azd` detects the language from the extension. Do not generate Bash-only `.sh` or PowerShell-only `.ps1` lifecycle hooks. |
| 46 | |
| 47 | ```yaml |
| 48 | hooks: |
| 49 | postprovision: |
| 50 | run: infra/hooks/postprovision.js |
| 51 | postdeploy: |
| 52 | run: infra/hooks/postdeploy.js |
| 53 | ``` |
| 54 | |
| 55 | Use `postprovision` for steps that need infrastructure outputs, such as setting `WEBHOOK_URL`. Use `postdeploy` for steps that need deployed services, such as rebuilding a frontend with its API URL. Hook code must invoke `az` and `azd` through argument arrays, never interpolated shell command strings. On macOS and Linux, call the CLI executable directly. On Windows, `.cmd` shims cannot be launched with `execFileSync()` or `spawnSync()` alone. Invoke a static, non-interpolated `powershell.exe` runner and pass the command plus arguments as a JSON environment payload, then use PowerShell's call operator with array splatting. This supports both the Azure CLI shim and the `azd.exe` installation without exposing arguments to shell parsing. Build deployment images in Azure Container Registry so the host does not need Docker or Buildx. |
| 56 | |
| 57 | ## SPA Frontend Deployment (React/Vite) |
| 58 | |
| 59 | ### The VITE_API_URL Problem |
| 60 | |
| 61 | When deploying a React/Vite frontend and API as **separate Container Apps**, the frontend needs the API's URL baked in at build time. But the API URL isn't known until after provisioning. |
| 62 | |
| 63 | **Symptoms:** |
| 64 | - Frontend shows `Unexpected token '<', "<!doctype "... is not valid JSON` |
| 65 | - The React app calls `/api/products` on the web container (nginx), which returns `index.html` |
| 66 | |
| 67 | **Root Cause:** `VITE_API_URL` defaults to `/api` (the Vite dev proxy). In production, nginx has no `/api` route — it serves the SPA for all paths. |
| 68 | |
| 69 | ### Solution: Cross-platform post-deploy hook |
| 70 | |
| 71 | **Do not leave this as a manual learner step on first success.** Generate `infra/hooks/postdeploy.js` and reference it directly from `azure.yaml`: |
| 72 | |
| 73 | ```yaml |
| 74 | hooks: |
| 75 | postdeploy: |
| 76 | run: infra/hooks/postdeploy.js |
| 77 | ``` |
| 78 | |
| 79 | The JavaScript hook must: |
| 80 | |
| 81 | 1. Resolve the application root from CommonJS `__dirname` rather than assuming the current working directory. |
| 82 | 2. Read `API_URL`, `AZURE_CONTAINER_REGISTRY_ENDPOINT`, and `RESOURCE_GROUP_NAME` with `azd env get-value`. |
| 83 | 3. Find the web Contai |