概要
前回はローカルからのデプロイをした。
今回はパイプラインを通したデプロイを行う。
Azure Pipelines から Azure Container Apps にデプロイするに従う。
マネージドIDの作成
#!/bin/bash
az containerapp identity assign \
--name test-container-1 \
--resource-group bicep-test-rg \
--system-assigned \
--output tsv
piyopiyo-0000-0000-0000-bd62ce015a3f b990eb0b-ab75-4423-8ae2-4837dd052dd2 SystemAssigned
assignment.sh
#!/bin/bash
ACR_NAME="acrhogehoge"
ACR_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
az role assignment create \
--assignee piyopiyo-0000-0000-0000-bd62ce015a3f \
--role AcrPull \
--scope $ACR_ID
az containerapp registry set \
--name test-container-1 \
--resource-group bicep-test-rg \
--server acrhogehoge.azurecr.io \
--identity system
Azure DevOpsサービス接続を作成
パイプラインからデプロイする
手順の通りに進めたら、下記エラーとなった。
##[error]Error Code: [1]
##[error]Error: Unable to create runnable application image using Oryx++ Builder.
原因は、手順のソースと別のソースを使っていたため、appSourcePath
にDockerfileのないsrcフォルダを指定していた('$(Build.SourcesDirectory)/src`)こと。
タスクでは、appSourcePath 内の Dockerfile を使用してコンテナー イメージがビルドされます。 Dockerfile が見つからない場合、タスクは、appSourcePath 内のソース コードからコンテナー イメージをビルドすることを試みます。
下記に修正したら動いた。
trigger:
branches:
include:
- main
pool:
vmImage: ubuntu-latest
steps:
- task: AzureContainerApps@1
inputs:
appSourcePath: '$(Build.SourcesDirectory)'
azureSubscription: 'my-subscription-service-connection'
acrName: 'acrhogehoge'
containerAppName: 'test-container-1'
resourceGroup: 'bicep-test-rg'
デプロイし、Functionsが更新されたことを確認できた。
なお、このときにACRにPUSHされ、コンテナアプリで指定されるイメージの名前は下記のようなものになる。
最後の185.20240613.4
はAzure DevOpsのパイプラインが提供するビルド番号
acrhogehoge.azurecr.io/ado-task/container-app:185.20240613.4