Azure 開發人員 CLI () 可組合性 (azdcompose) 功能可讓您逐步撰寫應用程式所需的 Azure 資源,而不需要手動撰寫 Bicep 程式代碼。 在本文中,您將瞭解如何使用撰寫功能來建置最少的範本。
azd
如需此功能的詳細資訊,請流覽撰寫概觀文章。
備註
azd撰寫功能目前處於 Alpha 階段,尚未穩定,不應用於生產應用程式。 後續版本中 Alpha 功能的變更可能會導致重大變更。 如需詳細資訊,請流覽 azd 功能版本設定和發行策略 和 功能階段 頁面。 使用右上方的 [ 意見反應 ] 按鈕,提供有關 compose 功能及本文的意見回饋。
使用撰寫功能
透過 azd 命令存取 azd add 撰寫功能。 此命令 azd add 適用於使用下列 azd init 工作流程所建立的範本:
- 在目前目錄中使用程式碼 (用於裝載以 Azure Container Apps 為目標的應用程式)
- 建立最小專案
目前不支援透過 選取範本 流程初始化的範本。
azd撰寫功能會為您管理基礎結構,且與具有現有infra資料夾資產的範本不相容。 如需詳細資訊,請瀏覽 產生 Bicep 程式代碼 文章和 範本建立工作流程 頁面。
完成下列步驟,將新的資源新增至範本,而不需撰寫任何程序代碼:
在終端機視窗中,流覽至範本的
azd根目錄。azd add執行 命令以新增資源並啟動撰寫工作流程:azd add選取其中一個支援的資源,以新增至您的應用程式。 在這裡範例中,選取
Database。? What would you like to add? [Use arrows to move, type to filter] > AI Database Host service Key Vault Messaging Storage account ~Existing resource針對資料庫類型,選取
PostgreSQL。? Which type of database? [Use arrows to move, type to filter] MongoDB > PostgreSQL Redis輸入新資源的名稱,例如
azddb。? Input the name of the app database (PostgreSQL)如果您的應用程式包含服務,
azd會提示您選取使用此資源的服務。? Select the service(s) that uses this resource > [✓] webfrontendazd會產生對azure.yaml檔案所需變更的預覽。 按 Enter 以接受並套用變更。Previewing changes to azure.yaml: + azddata: + type: db.postgres webfrontend: type: host.containerapp uses: - azddb + - azddata port: 80執行
azd up命令以配置透過azd add命令所做的任何變更。 在此範例中,會在azdAzure 中布建 PostgreSQL 資料庫。再次執行
azd add命令以新增其他資源,例如 OpenAI 服務。
探索 azure.yaml 檔案
azure.yaml 是用來管理應用程式的組態檔 azd 。
azd 使用對應的 azd add 和 services 節點來管理透過 resources 命令所組成的服務和資源。 請考慮下列完整透過 azure.yaml更新的azd add檔案範例:
name: azdcomposesample
metadata:
template: azd-init@1.11.0
services:
webfrontend:
project: src
host: containerapp
language: dotnet
resources:
webfrontend:
type: host.containerapp
port: 80
uses:
- azdsql
- azdchat
azdsql:
type: db.postgres
azdchat:
type: ai.openai.model
model:
name: gpt-4o
version: "2024-08-06"
- 節點
services宣告:- 名為
webfrontend的部署對應,位於src目錄中的 .NET Web 應用程式與 Azure Container Apps 之間。
- 名為
- 節點
resources宣告:- Azure 容器應用程式,以及名為
webfrontend的對應相依性對應,此對應存在於裝載的 .NET 容器應用程式及其所依賴的資料庫和 AI 服務之間。 節點會將uses應用程式對應至它相依的其他資源。 - 名稱為
azdsql的 Azure Database for PostgreSQL 資源。 - 名為
azdchat的 Azure OpenAI 資源。
- Azure 容器應用程式,以及名為