PostgreSQL และเซิร์ฟเวอร์ Container Apps บน Azure Resource Manager
ฐาน
เจตนา
บล็อก
ไฟล์
aggregate.yaml— เจตนาของ นัก พัฒนา: ส่วน ประกอบ ฐาน ข้อมูล payments-dbชนิดcore/datastore/postgresและเซิร์ฟเวอร์ orders-apiชนิดcore/compute/serverที่ประกาศ ว่า ใช้ ฐาน ข้อมูล ไม่มี สิ่ง ใด เกี่ยว กับ Azure อยู่ ที่ นี่ release-one-deployment.yaml— ทั้งสอง ส่วน ประกอบ อยู่ ใน แนว เขต เดียว จึง ประกอบ เป็น เทมเพลต เดียว ระบุ ชื่อ ข้อมูล ลับ ของ Key Vault ที่ เก็บ รหัส ผ่าน เครือข่าย ที่ ฐาน ข้อมูล วาง อยู่ สภาพ แวดล้อม Container Apps ที่ เซิร์ฟเวอร์ รัน และ อิมเมจ ของ เซิร์ฟเวอร์ release-two-deployments.yaml— สองส่วน ประกอบ เดิม ใน สอง แนว เขต จึง ประกอบ เป็น เทมเพลต สอง รายการ รายการ ละ หนึ่ง ไดเรกทอรี เอาต์พุต เทมเพลต ของ เซิร์ฟเวอร์ อ่าน ชื่อ โฮสต์ ของ ฐาน ข้อมูล จาก การ ปรับ ใช้ ของ ฐาน ข้อมูล release-negative-name-collision.yamlกับaggregate-name-collision.yaml— คาดว่า ส่วนจะ ล้ม เหลว ประกอบ สอง รายการ ที่ id ของ อินสแตนซ์ กลาย เป็น ชื่อ สัญลักษณ์ เดียวกัน manifest.yaml— ผูกแต่ละ ชนิด ของ ส่วน ประกอบ และ Feature ข้อมูล รับรอง เข้า กับ Recipe ที่ อิมพลีเมนต์ บน เป้า หมาย นี้ .aggrega-config.yaml— ระบุชื่อ รีจิสทรี hub ที่ เอนทิตี ของ แค็ตตาล็อก หา ค่า มา
ทุก
ร่างตัวอย่าง
คุณ
เขียน
aggrega draft --example arm-postgres-container-appsจาก
cd arm-postgres-container-appsบิลด์
ตัวอย่าง
aggrega pull --release release-one-deployment.yamlaggrega build --release release-one-deployment.yamlบิลด์<workspace> แทน
[… omitted: the pull's line, which reports the lockfile it wrote, and a lint notice about the credential Feature's origin]Total build time: 4.9sBuild completed: 1 file written to <workspace>/distเทมเพลตdist/one-deployment/arm/arm-template.json ทุก
กับผู้ช่วย AI
ผู้
ใช้เครื่องมือของ Aggrega เท่านั้น และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์ของพื้นที่ทำงานยังไม่มีโฟลเดอร์ `arm-postgres-container-apps` เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `arm-postgres-container-apps` และไม่ระบุ `dir`: เครื่องมือจะเขียนตัวอย่างลงในโฟลเดอร์ `arm-postgres-container-apps` ใหม่ จากนั้นเรียกเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `arm-postgres-container-apps` ตั้ง `release` เป็น `release-one-deployment.yaml` ตั้ง `auto_pull` เป็น true และตั้ง `write` เป็น true แล้วบอกฉันว่าบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใต้ `arm-postgres-container-apps/dist/`เทมเพลตเดียว การปรับใช้แบบซ้อนสองรายการ
ทั้งMicrosoft.Resources/deployments ที่resources ของ
| ชื่อ | มี |
|---|---|
PaymentsDb | Recipe ของarm/postgres-flexible-server |
OrdersApi | Recipe ของarm/server-container-apps |
แต่ละ Recipe ห่อentity.lock ของ Recipe ดัง
"OrdersApi": { "apiVersion": "2025-04-01", "metadata": { "aggrega.ai/provenance": { "aggrega.ai/aggregate-name": "aggregate", "aggrega.ai/boundary-path": "azure", [… omitted: a compiler-version entry, which moves with the build] "aggrega.ai/component-id": "orders-api", "aggrega.ai/environment": "production", "aggrega.ai/provider": "arm", [… omitted: a provider-version entry, which moves with the build] "aggrega.ai/recipe-uri": "server-container-apps:1.0.0" } }, "name": "[format('OrdersApi-{0}', uniqueString(deployment().name))]", [… omitted: the nested deployment's mode and parameters, and the module's template] },ชื่อorders-api กลายOrdersApi และ payments-db กลายPaymentsDb ชื่อuniqueString(deployment().name) ดัง
แต่ละ Recipe ปิดenableTelemetry เป็น false บน
"enableTelemetry": { "value": false },เซิร์ฟเวอร์อ่านฐานข้อมูลด้วยนิพจน์
Aggregate ระบุhost ของDB_HOST ที่
"env": [ { "name": "DB_HOST", "value": "[reference('PaymentsDb').outputs.fqdn.value]" }, { "name": "DB_NAME", "value": "orders" }, { "name": "DB_PORT", "value": "5432" }, { "name": "DB_USER", "value": "orders_admin" } ],host เป็นfqdn ของPaymentsDb ส่วน database, port และ user เป็นaggregate.yaml จึงPaymentsDb ก็
รหัสผ่านคือการอ้างอิง Key Vault
flexible server ต้องcore/referenced-secret เข้าpassword ของ
features: password: type: core/referenced-secret infra: origin: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/orders-security/providers/Microsoft.KeyVault/vaults/orders-vault/secrets/orders-db-passwordManifest ผูก Feature นั้นarm/key-vault-secret ซึ่ง
"administratorLoginPassword": { "reference": { "keyVault": { "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/orders-security/providers/Microsoft.KeyVault/vaults/orders-vault" }, "secretName": "orders-db-password" } },ไม่มี
การvalues: เลย
การปรับใช้เทมเพลต
เทมเพลต
az deployment group what-if --resource-group <group> --template-file dist/one-deployment/arm/arm-template.jsonaz deployment group create --resource-group <group> --name <name> --template-file dist/one-deployment/arm/arm-template.jsonหรือ
az stack group create --name <stack> --resource-group <group> \ --template-file dist/one-deployment/arm/arm-template.json \ --action-on-unmanage detachAll --deny-settings-mode none--action-on-unmanage detachAll ปล่อย--deny-settings-mode none ไม่
สองเทมเพลต ปรับใช้ทีละรายการต่อเนื่องกัน
release-two-deployments.yaml บิลด์ Aggregate เดียวกัน
aggrega pull --release release-two-deployments.yamlaggrega build --release release-two-deployments.yamlบิลด์
[… omitted: the pull's line, which reports the lockfile it wrote, and a lint notice about the credential Feature's origin]Total build time: 3.0sBuild completed: 2 files written to <workspace>/distdist/two-deployments-database/arm/arm-template.json เป็นdist/two-deployments-server/arm/arm-template.json เป็น
เทมเพลตของฐานข้อมูลเผยแพร่สิ่งที่เซิร์ฟเวอร์อ่าน
เซิร์ฟเวอร์string() เพื่อ
"payments_zhdb__host": { "type": "string", "value": "[string(reference('PaymentsDb').outputs.fqdn.value)]" },เทมเพลตmetadata ของ
"metadata": { "aggrega.ai/deployment-name": "aggrega--orders--two-deployments-database-zsarm" }เทมเพลตของเซิร์ฟเวอร์อ่านการปรับใช้นั้น
เซิร์ฟเวอร์
"value": "[reference(format('/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Resources/deployments/{2}', subscription().subscriptionId, resourceGroup().name, 'aggrega--orders--two-deployments-database-zsarm'), '2025-04-01').outputs.payments_zhdb__host.value]"ID สร้างaggrega.ai/azure-subscription หรือ aggrega.ai/azure-resource-group ใน annotations ของ
ปรับใช้ฐานข้อมูลก่อน ภายใต้ชื่อที่บันทึกไว้
ชื่อ
az deployment group create --resource-group <group> -n aggrega--orders--two-deployments-database-zsarm --template-file dist/two-deployments-database/arm/arm-template.jsonaz deployment group create --resource-group <group> -n <name> --template-file dist/two-deployments-server/arm/arm-template.jsonชื่อmetadata["aggrega.ai/deployment-name"] ของdirectory: ของ
บิลด์ที่หยุด
aggrega pull --release release-negative-name-collision.yamlaggrega build --release release-negative-name-collision.yamlaggregate-name-collision.yaml ประกาศpayments-db และ payments--db ทั้งPaymentsDb ชื่อ
[… omitted: the pull's lines, which report the same collision while writing the lockfile][TRANSLATION_ERROR E0038] dispatch groups whose contributors derive one name more than once in one key space caused by (2): [TRANSLATION_ERROR] release-negative-name-collision.yaml derived name collision: one name is derived more than once in one key space ("PaymentsDb", key space "symbolic-names", derived by component "payments--db", provider "arm", dispatch path "name-collision/arm") --- [TRANSLATION_ERROR] release-negative-name-collision.yaml derived name collision: one name is derived more than once in one key space ("PaymentsDb", key space "symbolic-names", derived by component "payments-db", provider "arm", dispatch path "name-collision/arm")สิ่ง
- ระบุ
ชื่อ แต่ละทั้ง สอง ฝั่ง รายการ ระบุ ส่วน ประกอบ จึง ค้นหา ทั้ง สอง ได้ ใน ไฟล์ ที่ คุณ เขียน ทั้ง สอง ถูก รายงาน เพราะ ทั้ง สอง ได้ สัญลักษณ์ เดียวกัน - ระบุ
สัญลักษณ์ ที่ ใช้ ร่วม กัน และ พื้นที่ คีย์ ของ สัญลักษณ์ นั้น PaymentsDbคือสัญลักษณ์ ที่ ทั้ง สอง ไป ถึง และ symbolic-namesคือเนมสเปซ ของ ทรัพยากร ใน เทมเพลต - ไม่
ส่ง บิลด์ออก สิ่ง ใด เลย หยุด แทนที่ จะ เขียน เทมเพลต ที่ การ ปรับ ใช้ แบบ ซ้อน หนึ่ง รายการ แทนที่ อีก รายการ โดย ไม่ แจ้ง การ เปลี่ยน ชื่อ ส่วน ประกอบ ใด ส่วน ประกอบ หนึ่ง ใน Aggregate แก้ไข ได้
อินพุตเดียวกัน เอาต์พุตเดียวกัน
การ
dist/ ถูก commit ไว้dist/one-deployment/, dist/two-deployments-database/ และ dist/two-deployments-server/ — ดัง*.lock ถูก