Azure容器应用Agent部署
deploy-agent-aca-dev
由 AI 主导将本地 LLM 示例 agent(Ollama + Microsoft Entra Agent ID sidecar)部署到 Azure Container Apps。当用户想要将 sidecar/dev 部署到 ACA、在 Azure 上运行 agent 而不使用 AWS/GCP、在 Container Apps 上托管 Ollama、将 docker-compose 本地开发栈从 ClientSecret 升级为 SignedAssertionFromManagedIdentity(无密钥),或调试此特定部署中的 AADSTS65001/AADSTS50011/ImagePullBackOff/Ollama OOM 错误时使用。不适用于 AWS Bedrock(使用 deploy-agent-aca-aws),也不适用于笔记本电脑上的本地 docker-compose(直接使用 sidecar/dev)。链接到 entra-agent-id-setup 以设置 Blueprint + Agent Identity + Client SPA 对象。
- License 许可
- MIT
- 最近更新
- 2026-08-06
- Stars
- ★ 15
- Forks
- 8
01 前言 Front Matter
- name
- deploy-agent-aca-dev
- description
- AI-led deployment of the local-LLM sample agent (Ollama + Microsoft Entra Agent ID sidecar) to Azure Container Apps. Use when the user wants to deploy sidecar/dev to ACA, run the agent on Azure without AWS/GCP, host Ollama on Container Apps, promote the docker-compose local-dev stack from ClientSecret to SignedAssertionFromManagedIdentity (secretless), or debug AADSTS65001/AADSTS50011/ImagePullBackOff/Ollama OOM errors in this specific deployment. NOT for AWS Bedrock (use deploy-agent-aca-aws) and NOT for local docker-compose on a laptop (use sidecar/dev directly). Chains to entra-agent-id-setup for the Blueprint + Agent Identity + Client SPA objects.
02 资源文件 32
- 参考文档apply.md15.0 KB
- 参考文档attachments.md4.1 KB
- 参考文档backends/claude_ai_mcp.md1.1 KB
- 参考文档backends/mail-source-probe.md3.3 KB
- 参考文档backends/maildir.md587 B
- 参考文档backends/oauth_curl.md1.3 KB
- 参考文档candidate-listing.md9.7 KB
- 参考文档duplicate-search.md11.0 KB
- 参考文档existing-tracker-dedup.md7.4 KB
- 参考文档fix-already-public.md5.4 KB
- 参考文档outcomes/ack-auto.md915 B
- 参考文档outcomes/ack-manual.md793 B
- 参考文档outcomes/ack-none.md809 B
- 参考文档outcomes/bundle.md1.0 KB
- 参考文档outcomes/converged.md1.0 KB
- 参考文档outcomes/credit-field.md3.0 KB
- 参考文档outcomes/mailing-thread.md1.7 KB
- 参考文档outcomes/redact-before-extract.md4.0 KB
- 参考文档references/architecture.md1.3 KB
- 参考文档references/ollama-on-aca.md3.2 KB
- 参考文档references/post-deploy-manual-steps.md2.1 KB
- 参考文档references/sku-sizing.md5.3 KB
- 参考文档references/troubleshooting.md5.1 KB
- 参考文档screening-and-proposal.md23.2 KB
- 脚本scripts/add-spa-redirect-uri.sh1.1 KB
- 脚本scripts/build-ollama-image.sh1.9 KB
- 脚本scripts/containerapp.yaml.template2.8 KB
- 脚本scripts/deploy-aca-dev.sh8.4 KB
- 脚本scripts/deploy-vars.sh.template2.9 KB
- 脚本scripts/grant-agent-obo-consent.ps11.6 KB
- 脚本scripts/setup-obo-blueprint-for-aca.ps12.9 KB
- 参考文档tracker-backend.md2.7 KB
03 SKILL.md 正文
Deploy Local-LLM Agent to Azure Container Apps (AI-Led)
End-to-end, secretless deployment of sidecar/dev (Ollama + Entra Agent ID sidecar) to Azure Container Apps. One federation chain (MI → Entra Blueprint), no second cloud.
Canonical tutorial: sidecar/dev/deploy-local-llm-agent-sidecar-container-apps.md. This skill is the automated, fast-path counterpart.
When to Use
- User says: "deploy dev to ACA", "deploy the local LLM agent to Azure", "Ollama on Container Apps", "ship sidecar/dev to Azure"
- User wants a self-contained demo in a tenant where AWS/GCP aren't options (airgapped, regulated, customer-owned)
- User hits
AADSTS65001on OBO sign-in — see references/post-deploy-manual-steps.md - User hits
AADSTS50011: redirect URI mismatch— same reference - User hits Ollama
out of memoryorImagePullBackOff— see references/ollama-on-aca.md - User asks "can I run this without Bedrock / Vertex?"
Do NOT Use When
- AWS Bedrock deployment — use
deploy-agent-aca-aws - GCP Vertex AI deployment — pending skill
deploy-agent-aca-gcp - Local laptop docker-compose — use
sidecar/dev/directly withdocker compose up, no federation needed
Prerequisites (verify BEFORE running anything)
- Entra role on signing-in user — one of:
Global Administrator,Agent ID Administrator,Agent ID Developer. See entra-agent-id-setup. - Tooling:
az≥ 2.60,pwsh7.4+,Microsoft.Graph.*2.35+ (install:Install-Module Microsoft.Graph.Authentication, Microsoft.Graph.Beta.Applications -Scope CurrentUser), and one of:docker buildxforlinux/amd64ORaz acr build(no local Docker needed — see Step 4). - Tenant-confirmed preflight — ALWAYS confirm tenant ID + subscription ID with the user before any
azcommand that mutates resources. - Entra Agent ID base objects exist — Blueprint, Agent Identity, Client SPA. If not, run the entra-agent-id-setup skill first.
[!NOTE] Windows / PowerShell users: This skill's scripts and orchestrator are bash. If running from PowerShell without WSL or Git Bash:
source file→. fileor set$env:VARindividuallyenvsubst→ PowerShell-replaceoperators or(Get-Content template) -replace '\$\{VAR\}', $valuebash script.sh→ translate eachaz/pwshcommand into the PowerShell session directlydocker buildx build --push→az acr buildforllm-agentandweather-api(but not for baked Ollama — see Step 4)az ad app update --set spa='{...}'may fail with JSON escaping — useaz rest --method PATCHinstead (see Step 6)
SKU decisions — ask the user first
Before running any az command that provisions resources, confirm each SKU choice with the user. Do not silently default to the cheapest tier. The orchestrator requires each SKU variable to be set and fails hard if any is missing. Full tradeoff matrix: references/sku-sizing.md.
| Variable | Ask | Demo default | Silent-failure mode if chosen wrong |
|---|---|---|---|
ACR_SKU |
Basic / Standard / Premium |
Basic |
Ollama image ~1 GB; Basic fills up with 10 variants |
ACA_WORKLOAD_PROFILE |
Consumption / Dedicated-D4 / GPU |
Consumption |
1.5B model on Consumption CPU = 5–20 s per answer |
LOGS_DESTINATION |
none / log-analytics |
log-analytics |
none hides Ollama OOM crashes and sidecar auth errors |
MIN_REPLICAS / MAX_REPLICAS |
counts | 1 / 1 |
min=0 = model reloads into RAM on every cold start |
OLLAMA_MODEL |
qwen2.5:1.5b / qwen2.5:7b / llama3.2:1b |
qwen2.5:1.5b |
7B model on Consumption times out ACA ingress |
OLLAMA_IMAGE_STRATEGY |
baked / runtime-pull |
baked |
runtime-pull = 30 s first-request delay |
OLLAMA_CPU / OLLAMA_MEMORY |
see model-to-sizing table | 0.75 / 1.5Gi |
Undersized memory → Ollama OOM. qwen2.5:3b needs 2.5 Gi (requires Dedicated-D4+). See sku-sizing.md §7. |
When invoking this skill, explicitly state the defaults to the user and ask them to confirm or override — do not assume.
Procedure
Step 0 — Confirm account and populate variables
Ask the user to confirm: tenant ID, subscription ID, resource group name, location, SKU choices (including OLLAMA_CPU / OLLAMA_MEMORY — match to model), Ollama model. Then:
cp .claude/skills/deploy-agent-aca-dev/scripts/deploy-vars.sh.template /tmp/deploy-vars.sh
# edit /tmp/deploy-vars.sh with confirmed values
source /tmp/deploy-vars.sh
az login --tenant "$TENANT_ID" && az account set --subscription "$SUBSCRIPTION_ID"
Step 1 — Create Entra objects (Blueprint, Agent, Client SPA)
Delegate to entra-agent-id-setup. Capture BLUEPRINT_APP_ID, AGENT_CLIENT_ID, CLIENT_SPA_APP_ID into /tmp/deploy-vars.sh.
[!WARNING] Run
Connect-MgGraphin an interactive pwsh session, not viapwsh -Command "Connect-MgGraph ..."subshell. The WAM authentication popup hides behind other windows in a subshell and silently times out.
Configure the Blueprint for OBO using the ACA-compatible PowerShell script:
pwsh -NoProfile -File .claude/skills/deploy-agent-aca-dev/scripts/setup-obo-blueprint-for-aca.ps1 \
-BlueprintAppId "$BLUEPRINT_APP_ID" \
-ClientSpaAppId "$CLIENT_SPA_APP_ID" \
-AgentAppId "$AGENT_CLIENT_ID" \
-TenantId "$TENANT_ID"
Step 2 — Azure infrastructure (RG, ACR, env, container app skeleton)
See tutorial §6. Uses SKU variables. Capture MI_OBJECT_ID and APP_FQDN, append to /tmp/deploy-vars.sh. Grant AcrPull to the MI.
[!NOTE] Adding a Dedicated-D4 workload profile can take 20+ minutes to provision. This is normal — do not cancel. If Azure Policy enforces tags on resource groups (e.g.,
Owner,MonthlyCost), add them duringaz group createor use a pre-existing RG.
Step 3 — Federate MI to Blueprint (only federation chain)
Single Graph call — see tutorial §7. Subject = $MI_OBJECT_ID, audience = api://AzureADTokenExchange.
Unlike the AWS skill, there is no Step 4 (AWS federation). The local LLM needs no external cloud.
Step 4 — Build and push images
Tutorial §8. Three images: llm-agent, weather-api, ollama (baked) — or two if using runtime-pull.
Option A — Local Docker (docker buildx):
Requires Docker Desktop running. Works for all images including baked Ollama.
Option B — Remote build (az acr build):
No Docker Desktop needed. Works for llm-agent and weather-api only.
az acr build --registry "$ACR_NAME" --image agent-id-dev/llm-agent:1.0.0 --platform linux/amd64 sidecar/dev/
az acr build --registry "$ACR_NAME" --image agent-id-dev/weather-api:1.0.0 --platform linux/amd64 sidecar/weather-api/
[!NOTE]
UnicodeEncodeError: 'charmap' codec can't encode charactersfromaz acr buildon Windows is cosmetic (colorama/cp1252 encoding). The build succeeds — ignore the error.
[!IMPORTANT] Baked Ollama images cannot be built via
az acr build— theRUN ollama serve & ollama pull ...step requires a running Docker daemon that ACR Build does not provide. The image silently fails to appear in ACR. If Docker Desktop is unavailable, switch toOLLAMA_IMAGE_STRATEGY=runtime-pull.
If OLLAMA_IMAGE_STRATEGY=baked (Option A only):
bash .claude/skills/deploy-agent-aca-dev/scripts/build-ollama-image.sh
Step 5 — Deploy the multi-container app
envsubst < .claude/skills/deploy-agent-aca-dev/scripts/containerapp.yaml.template > /tmp/containerapp.yaml
az containerapp update -g "$RG" -n "$APP_NAME" --yaml /tmp/containerapp.yaml
Step 6 — Post-deploy wiring (REQUIRED — execute immediately after Step 5)
[!IMPORTANT] The AI agent MUST execute both sub-steps below. Do NOT skip or leave for the user. These are automatable —
APP_FQDNis known from Step 2, and all app IDs are known from Step 1.
Two things that cannot be done before deploy:
-
Add deployed SPA redirect URI —
bash .claude/skills/deploy-agent-aca-dev/scripts/add-spa-redirect-uri.sh[!WARNING] On PowerShell,
az ad app update --set spa='{...}'fails withProperty spa in payload has a value that does not match schemadue to JSON escaping. Use this workaround instead:$body = @{ spa = @{ redirectUris = @("http://localhost:3003", "https://$env:APP_FQDN/") } } | ConvertTo-Json -Depth 3 az rest --method PATCH --url "https://graph.microsoft.com/v1.0/applications(appId='$env:CLIENT_SPA_APP_ID')" --body $body --headers "Content-Type=application/json" -
Grant Agent → Graph delegated
User.Read(fixesAADSTS65001):pwsh -NoProfile -File .claude/skills/deploy-agent-aca-dev/scripts/grant-agent-obo-consent.ps1 \ -AgentAppId "$AGENT_CLIENT_ID" -TenantId "$TENANT_ID"
Full rationale: references/post-deploy-manual-steps.md.
Step 7 — Verify
Tutorial §11. ollama_available: true in status; autonomous flow returns Qwen-generated answer; OBO works via MSAL popup.
One-Shot Orchestrator
If all prerequisites are in place and SKU variables are confirmed:
bash .claude/skills/deploy-agent-aca-dev/scripts/deploy-aca-dev.sh
Idempotent. Invokes steps 2–5 in order. Steps 0, 1, 6 require human decisions and remain manual.
Key Artifacts
Persisted in /tmp/deploy-vars.sh:
| Variable | Source |
|---|---|
TENANT_ID, SUBSCRIPTION_ID |
User |
ACR_SKU, ACA_WORKLOAD_PROFILE, LOGS_DESTINATION, MIN_REPLICAS, MAX_REPLICAS |
User (SKU decisions) |
OLLAMA_MODEL, OLLAMA_IMAGE_STRATEGY |
User |
OLLAMA_CPU, OLLAMA_MEMORY |
User (match to model — see sku-sizing.md §7) |
BLUEPRINT_APP_ID, AGENT_CLIENT_ID, CLIENT_SPA_APP_ID |
Step 1 |
MI_OBJECT_ID, APP_FQDN |
Step 2 |
No client secrets, no external-cloud credentials anywhere.
References
04 同仓库更多 Skills
本地 LLM 智能体部署清理
teardown-agent-aca-dev
由 AI 主导拆除由 deploy-agent-aca-dev 在 Azure Container Apps 上创建的本地 LLM(Ollama)示例智能体部署。当用户想要删除开发示例 ACA 部署、清理资源组,或可选删除 Blueprint / Agent Identity / Client SPA 时使用。默认采用 DRY-RUN(试运行)并保留 Entra 对象,除非用户明确选择加入。不适用于本地 docker-compose(使用 `docker compose down -v`),也不适用于 AWS Bedrock 变体(使用 teardown-agent-aca-aws)。
AWS 智能体部署清理
teardown-agent-aca-aws
由 AI 主导拆除由 deploy-agent-aca-aws 在 Azure Container Apps 上创建的 AWS Bedrock 示例智能体部署。当用户想要删除 AWS 示例 ACA 部署、清理资源组、移除 AWS IAM 角色 + OIDC 提供程序、删除中间的 Entra 应用,或可选删除 Blueprint / Agent Identity / Client SPA 时使用。默认采用 DRY-RUN(试运行)并保留 Entra/AWS 对象,除非用户明确选择加入。不适用于本地 docker-compose(无云资源可删除),也不适用于 GCP(待定)。
Entra Agent ID 配置
entra-agent-id-setup
由 AI 引导设置 Microsoft Entra Agent ID。当用户想要在 Entra 租户中预配 Agent Identity Blueprint、Agent Identity 和 OBO 客户端应用时;配置 dev/AWS/GCP sidecar 栈时;调试蓝图创建时的 403 Authorization_RequestDenied 错误时;检查所需的 Entra 角色(Global Admin / Agent ID Administrator / Agent ID Developer)时;运行 Start-EntraAgentIDWorkflow / setup-obo-client-app / setup-obo-blueprint 时使用。
Bedrock 智能体 ACA 部署
deploy-agent-aca-aws
由 AI 主导,将带有 Microsoft Entra Agent ID 边车(sidecar)的 AWS Bedrock 示例智能体部署到 Azure Container Apps。当用户希望将该 AWS 示例部署到 ACA、配置 AWS 联邦中间 Entra 应用、连接令牌刷新器、为 Bedrock 创建 AWS OIDC 提供程序和 IAM 角色、构建并将四个容器镜像推送到 ACR,或调试此特定部署中的 InvalidIdentityToken / AADSTS65001 / Directory.AccessAsUser.All / AcrPull 错误时使用。不适用于本地 docker-compose(使用 sidecar/dev),也不适用于 GCP(deploy-agent-aca-gcp,待定)。可链接到 entra-agent-id-setup 以处理 Blueprint + Agent Identity + Client SPA 对象。