Azure Devops Pipeline ACR 部署到 Web App Container

Azure Devops Pipeline ACR deployment to Web App Container

我有一个奇怪的问题,可能是我遗漏了什么。 Web 应用程序创建为具有默认设置(快速入门)的容器,我正在使用 Azure 容器注册表来推送我的 docker 图像。我有管道登录到 ACR,构建和推送图像,然后将图像部署到 Web 应用程序。所有这些任务都是成功的。但是当我进入 Azure 门户中的 Web 应用程序时,图像源设置为 docker 集线器而不是 Azure 容器 registry.The 完整的名称和标签属于 ACR。有什么我遗漏的建议吗?

更新:我添加了 pipeline.yml 文件以供参考,如果有帮助的话。我在推送 docker 图像时登录注册表,我确认图像已推送到 ACR 中。

          - task: Docker@2
            displayName: Login to QA Azure Container Registry
            inputs:
              command: login
              containerRegistry: $(azureSubscriptionContainer) #Docker Registry type Service connection
          - task: Docker@2
            displayName: Build and Push
            inputs:
              command: buildAndPush
              repository: $(repository) #custom name of repository in ACR
              tags: $(Build.BuildId)
          - task: AzureRMWebAppDeployment@4
            displayName: Azure App Service Deploy
            inputs:
              appType: webAppContainer
              ConnectedServiceName: $(azureSubscription)    #ARM service connection
              WebAppName: $(webApp)
              DockerNamespace: $(dockerNameSpace) #ACR namespace myacr.azurecr.io
              DockerRepository: $(repository) #custom name of repository in ACR
              DockerImageTag: $(Build.BuildId)

使用 CLI 创建应用服务:

az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name <app-name> --deployment-container-image-name <azure-container-registry-name>.azurecr.io/mydockerimage:v1.0.0

这适用于 public 图像,但根据 documentation 如果您想使用私人图像,您还必须为您的 Web 应用程序配置注册表凭据,如果这不是 Docker您必须提供注册表 -docker-registry-server-url:

az webapp config container set --name <app-name> --resource-group myResourceGroup --docker-custom-image-name <azure-container-registry-name>.azurecr.io/mydockerimage:v1.0.0 --docker-registry-server-url https://<azure-container-registry-name>.azurecr.io --docker-registry-server-user <registry-username> --docker-registry-server-password <password>

TLDR:您需要 select UI 中的存储库;或通过 ARM 或 AzureCLI 添加凭据。

https://docs.microsoft.com/en-us/azure/devops/pipelines/targets/webapp-on-container-linux?view=azure-devops&tabs=dotnet-core%2Cyaml#configure-registry-credentials-in-web-app

您可以像现在一样使用部署任务,并非所有开发人员都需要访问 WebApp。但是,您需要至少为注册表设置一次凭据。 UI 将基本上显示其对如何解释底层配置的“最佳猜测”。

https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image#configure-registry-credentials-in-web-app

您也可以对每个管道执行此操作 运行,但我不建议这样做。

旁注:如果您select“持续部署”,您也可以让您的 webapp 在容器注册表中更新时自动提取某个标签。