Azure Developer CLIにおけるリソースデプロイ系コマンド、
azd up
azd provision
azd deploy
これらの違いを整理します。
はじめに
最近、Azure Developer CLIを触っています。
リソースをデプロイするためのコマンドとしてazd up
/ azd provision
/ azd deploy
の3つがありますが、違いがパッと分からなかったので整理してまとめます。
# 作業環境 $ azd version azd version 0.8.0-beta.2 (commit 429b6ccf9a9d1616efa8988f2f8561deeb464c71)
azd up / provision / deploy
違い
azd up
/ azd provision
/ azd deploy
の違いは、
azd provision
: インフラをデプロイするazd deploy
: アプリをデプロイするazd up
: インフラとアプリの両方をデプロイする
です。
ドキュメントにも、下記のように記載されています。
You can run azd up to perform both azd provision and azd deploy in a single step.
「azd upを使えば、azd provisionとazd deployを1ステップで実行できます」
azd
コマンドの--helpマニュアルも見てみます。
$ azd --help The Azure Developer CLI is an open-source tool that helps onboard and manage your application on Azure Usage azd [command] Commands Configure and develop your app auth : Authenticate with Azure. config : Manage azd configurations (ex: default Azure subscription, location). init : Initialize a new application. restore : Restores the application's dependencies. template : Find and view template details. Manage Azure resources and app deployments deploy : Deploy the application's code to Azure. down : Delete Azure resources for an application. env : Manage environments. package : Packages the application's code to be deployed to Azure. (Beta) provision : Provision the Azure resources for an application. up : Provision Azure resources, and deploy your project with a single command. Monitor, test and release your app monitor : Monitor a deployed application. pipeline : Manage and configure your deployment pipelines. About, help and upgrade version : Print the version number of Azure Developer CLI. Flags -C, --cwd string : Sets the current working directory. --debug : Enables debugging and diagnostics logging. -h, --help : Gets help for azd. --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. Use azd [command] --help to view examples and more information about a specific command. Deploying a sample application Initialize from a sample application by running the azd init --template [template name] command in an empty directory. Then, run azd up to get the application up-and-running in Azure. To view available templates run `azd template list` or visit: https://azure.github.io/awesome-azd Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.
該当部分抜粋:
deploy : Deploy the application's code to Azure. provision : Provision the Azure resources for an application. up : Provision Azure resources, and deploy your project with a single command.
訳:
- deploy: アプリケーションコードをAzureにデプロイする
- provision: アプリケーション用のAzureリソースをプロビジョニングする
- up: 単一コマンドでAzureリソースのプロビジョニングおよびプロジェクトのデプロイを行う
言葉選びが少し分かりにくい気もしますが、ここからもdeploy
がアプリコードのデプロイ、provision
がAzureリソースの構築、up
がその両者を一気に実行するコマンドであることが分かります。
動作確認
これら3つのコマンドを実際に実行して、動作を確認してみます。
動作確認には、テンプレートtodo-python-mongoを使います。
# 事前準備 azd auth login # -> ブラウザが開いて認証 # Logged in to Azure. # テンプレートでプロジェクトを初期化 azd init --template todo-python-mongo
構築されるシステムのアーキテクチャはこちらです:
azd provision
まずは、まっさらな状態からazd provision
を実行します。
$ azd provision Provisioning Azure resources (azd provision) Provisioning Azure resources can take some time You can view detailed progress in the Azure Portal: https://portal.azure.com/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/%2Fsubscriptions%xxxxx%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Ftodo-python (✓) Done: Resource group: rg-todo-python (✓) Done: Log Analytics workspace: log-xxx (✓) Done: Key vault: kv-xxx (✓) Done: App Service plan: plan-xxx (✓) Done: Application Insights: appi-xxx (✓) Done: Portal dashboard: dash-xxx (✓) Done: App Service: app-web-xxx (✓) Done: Azure Cosmos DB: cosmos-xxx (✓) Done: App Service: app-api-xxx SUCCESS: Your project has been provisioned! You can view the resources created under the resource group rg-todo-python in Azure Portal: https://portal.azure.com/#@/resource/subscriptions/xxx/resourceGroups/rg-todo-python/overview
このようにazd provision
ではAzureリソース(インフラ)が構築されます。
azd deploy
azd provision
に続けて、azd deploy
を実行してみます。
$ azd deploy Deploying services (azd deploy) (✓) Done: Deploying service api - Endpoint: https://app-api-xxx.azurewebsites.net/ (✓) Done: Deploying service web - Endpoint: https://app-web-xxx.azurewebsites.net/ SUCCESS: Your Azure app has been deployed! You can view the resources created under the resource group rg-todo-python in Azure Portal: https://portal.azure.com/#@/resource/subscriptions/xxx/resourceGroups/rg-todo-python/overview
Service apiとservice webにコードがデプロイされています。
表示されるエンドポイントURLにアクセスすると、実際に無事アプリがデプロイされていました:
ちなみに、azd provision
をまだ実行していない状態(Azureリソース/インフラが構築されていない状態)でazd deploy
を実行しようとすると、下記のエラーが発生します:
$ azd deploy Deploying services (azd deploy) (x) Failed: Deploying service api ERROR: getting target resource: getting default resource groups for environment: todo-python: resource not found: 0 resource groups with prefix or suffix with value: 'todo-python'
インフラが無い状態では当然アプリもデプロイできない、ということですね。
azd up
最後に、リソースが何も無いまっさらな状態からazd up
を実行します。
$ azd up Packaging services (azd package) (✓) Done: Packaging service api - Package Output: /var/folders/qb/xxx0000gn/T/azddeploy2341782931.zip (✓) Done: Packaging service web - Package Output: /var/folders/qb/xxx0000gn/T/azddeploy1615020941.zip Provisioning Azure resources (azd provision) Provisioning Azure resources can take some time You can view detailed progress in the Azure Portal: https://portal.azure.com/#blade/HubsExtension/DeploymentDetailsBlade/overview/id/%2Fsubscriptions%2Fxxx%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Ftodo-python (✓) Done: Resource group: rg-todo-python (✓) Done: Log Analytics workspace: log-xxx (✓) Done: App Service plan: plan-xxx (✓) Done: Key vault: kv-xxx (✓) Done: Application Insights: appi-xxx (✓) Done: Portal dashboard: dash-xxx (✓) Done: App Service: app-web-xxx (✓) Done: Azure Cosmos DB: cosmos-xxx (✓) Done: App Service: app-api-xxx Deploying services (azd deploy) (✓) Done: Deploying service api - Endpoint: https://app-api-xxx.azurewebsites.net/ (✓) Done: Deploying service web - Endpoint: https://app-web-xxx.azurewebsites.net/ SUCCESS: Your Azure app has been deployed! You can view the resources created under the resource group rg-todo-python in Azure Portal: https://portal.azure.com/#@/resource/subscriptions/xxx/resourceGroups/rg-todo-python/overview
このように、azd up
では1ステップでazd provision
とazd deploy
の両方分の処理が実行されました。
おわりに
Azure Developer CLIにおける、azd up / provision / deploy の違いを整理しました。
これまでは主にAWSを使ってきたので、最近Azureを使い始めては何かと新鮮な気持ちです。
以上、どなたかの役に立てば幸いです。
[関連記事]
参考
What is the Azure Developer CLI (preview)? | Microsoft Learn
Make your project compatible with Azure Developer CLI (preview) | Microsoft Learn