问题描述
我有一个很奇怪的问题(并且我想很容易解决):)我试图在Azure中使用有效的CI/CD管道.为此,我在Azure devops中有一个存储库,并创建了构建和发布管道.我正在将Docker映像发布到Azure容器注册表,并且在发布期间,我拉出了该映像(或者至少-我正在尝试,因为它不起作用),并且试图将其发布在Webapp上用于容器.在我的情况下,应用程序"是.NET Core 3.1上的SingalR集线器(但我不认为它对我遇到的问题有所帮助)
如果有人想详细了解我如何配置它-这是我确实使用过的教程:
让我惊讶的是,它表明一切都还不错-距离"ok"还很远的时候:)
之后,当我进入容器设置时:a)新代码已发布b)造成管道大火c)释放管道火灾
我这样看:
标签为空.如果我会手动选择一些标签:
并选择:保存",一切正常(SingalR已启动并正常运行)
很明显,我缺少了一些东西://帮我看看有什么;)
对我来说,根本原因是该片段: DockerImageTag:'$(Build.BuildNumber)'
应该插入内部版本号(如前所述),并且容器设置中的信息应为:拖动图像:myAcrName.azurecr.io/mobile/signalr:20200421.09
(对于BuildNumber 20200421.09),并在其中插入GIT COMMIT作为标签,最终显示为:拖动图像:myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
为什么还是为什么?:)
[UPDATE 22.04 10:56]
我正在发布我当前正在使用的构建管道.我不认为这很重要,因为它可以正常工作,而且问题更多是在部署正确创建的Docker映像(在ACR上)而不是在构建管道上创建此映像.不过,这是管道:
#Docker#构建Docker映像#https://docs.microsoft.com/azure/devops/pipelines/languages/docker扳机:- 掌握资源:-回购:自我变量:dockerRegistryServiceConnection:'MyProductDockerACR'imageRepository:移动/信号"containerRegistry:'myAcrName.azurecr.io'dockerfilePath:"**/Dockerfile"标签:"$(Build.BuildNumber)"vmImageName:'ubuntu-latest'阶段:-阶段:制作displayName:构建和推送阶段职位:-工作:制作displayName:构建水池:vmImage:$(vmImageName)脚步:-任务:Docker @ 2displayName:构建并将图像推送到容器注册表输入:containerRegistry:$(dockerRegistryServiceConnection)仓库:$ {imageRepository)命令:"buildAndPush"Dockerfile:$(dockerfilePath)标签:$(标签)
我看到您正在使用的发行版是由 UI
配置的.它的工作逻辑与 YAML
配置的逻辑大不相同.
实际上,您在这里所收到的是由于该版本的运行原因不同而产生的不同性能.
我猜这个发行版的工件来源是 Repos ,对吗?您可以通过检查其图标来确认.
虽然发布源来自Repos,但 Build.BuildNumber
将是 commit id
(8个字符)的一小部分.Build.BuildId是完整的提交ID.
如果您希望发行版继续使用相应的build( created/pushed image )使用的 Build.Buildnumber
值,则必须确保发行版源为定位到此版本.同样,此构建需求还会生成工件.根据您分享的YAML,很明显,您还没有这样做.
仅由构建以及工件触发的版本,然后 Build.BuildNumber
可能类似于构建所使用的 20200422.1
.
因此,请确定您的发布定义,然后重新配置其源代码,以确保它来自构建工件,而不是存储库.
I have a very weird (and I suppose easy to fix) problem :) I am trying to have a working CI/CD pipeline in Azure. For this purpose, I have a repository in Azure devops and build and release pipeline created. I am publishing docker images to Azure Container Registry and during release, I am pulling this image (or at least - I am trying because it doesn't work) and I am trying to publish it on Webapp for containers. The "app" in my case it is SingalR hub on .NET Core 3.1 (but I don't suppose it makes a difference in the problem I am having)
If somebody wants to know in details how did i configure it - here is the tutorial i did use:
There were some doubts/differences in the tutorial (for example - why initially in the tutorial web app is being configured on Docker hub, when in fact it is using ACR. And why to connect to ACR the tutorial uses Azure Resource Manager connection (And not dedicated Docker container --> ACR connetion) And why later on in build pipeline there is some weird id set for dockerRegistryServiceConnection (i am giving in this place name of my ACR docker service connection)
But the whole build pipeline is working. It is publishing image to ACR. Everything is fine till this step.
The problem starts when I want to publish Azure WebApp with this image. The problem is with ... TAGS :) They are mismatching. I have automatic CI/CD - so when i push some change to the repo i see that release pipeline is working. It is creating the image in the ACR. Then i see, that release pipeline is running. Everything is "correct" - meaning no error are seen and the release is green.
But when i go to App service and Container settings i see from logs:
2020-04-21 18:02:28.321 INFO - Pulling image: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
2020-04-21 18:02:28.761 ERROR - DockerApiException: Docker API responded with status code=NotFound, response={"message":"manifest for myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a not found: manifest unknown: manifest unknown"}
2020-04-21 18:02:28.761 ERROR - Pulling docker image myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a failed:
2020-04-21 18:02:28.762 INFO - Pulling image from Docker hub: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
2020-04-21 18:02:28.867 ERROR - DockerApiException: Docker API responded with status code=InternalServerError, response={"message":"Get https://myAcrName.azurecr.io/v2/mobile/signalr/manifests/c7aead0c46b66afc4131935efc7e6a51280dfb1a: unauthorized: authentication required"}
2020-04-21 18:02:28.870 ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository)
Very sophisticated error but the root cause is, that he is trying to get the image with non-existing tag, which is GIT COMMIT tag. And it suppose to get image by $(Build.BuildId) (this was my first attempt) or by $(Build.BuilNumber) (this was my second attempt)
Here is how this pipeline step (Deploy Azure App Service) looks like:
- task: AzureRmWebAppDeployment@4
displayName: 'Deploy Azure App Service'
inputs:
azureSubscription: mySubcsriptionARM
appType: webAppContainer
WebAppName: myProductsignalr
DockerNamespace: myAcrName.azurecr.io
DockerRepository: mobile/signalr
DockerImageTag: '$(Build.BuildNumber)'
When i go to Release pipeline logs as a "Deploy Azure App Service" log i see that
2020-04-21T18:41:01.6012767Z ##[section]Starting: Deploy Azure App Service
2020-04-21T18:41:01.6367124Z ==============================================================================
2020-04-21T18:41:01.6367787Z Task : Azure App Service deploy
2020-04-21T18:41:01.6368381Z Description : Deploy to Azure App Service a web, mobile, or API app using Docker, Java, .NET, .NET Core, Node.js, PHP, Python, or Ruby
2020-04-21T18:41:01.6368765Z Version : 4.163.5
2020-04-21T18:41:01.6369158Z Author : Microsoft Corporation
2020-04-21T18:41:01.6369603Z Help : https://aka.ms/azureappservicetroubleshooting
2020-04-21T18:41:01.6369976Z ==============================================================================
2020-04-21T18:41:03.8970184Z Got service connection details for Azure App Service:'myProductsignalr'
2020-04-21T18:41:04.5534864Z Trying to update App Service Configuration settings. Data: {"appCommandLine":null,"linuxFxVersion":"DOCKER|myAcrName.azurecr.io/mobile/signalr:1f283100"}
2020-04-21T18:41:05.5465725Z Updated App Service Configuration settings.
2020-04-21T18:41:05.5495890Z Trying to update App Service Application settings. Data: {"DOCKER_CUSTOM_IMAGE_NAME":"myAcrName.azurecr.io/mobile/signalr:1f283100"}
2020-04-21T18:41:06.2703349Z Updated App Service Application settings and Kudu Application settings.
2020-04-21T18:41:32.4715682Z Updated App Service Application settings and Kudu Application settings.
2020-04-21T18:41:33.4179962Z Successfully updated deployment History at https://myProductsignalr.scm.azurewebsites.net/api/deployments/111587494492765
2020-04-21T18:41:33.5945654Z App Service Application URL: http://myProductsignalr.azurewebsites.net
2020-04-21T18:41:33.6180118Z ##[section]Finishing: Deploy Azure App Service
What amazes me, that it is showing, that everything was ok - when it was far from "ok" :)
When i go to container settings after:a) new code is publishedb) build pipeline firesc) release pipeline fires
i see it like this:
The tag is empty. If i would pick some tag manually:
And would choose: "SAVE" everything works correctly (SingalR is up and running correctly)
Clearly, I am missing something :/ Help me to see what;)
The root cause for me is that this fragment:DockerImageTag: '$(Build.BuildNumber)'
should insert build number (as stated) and the info from container settings should be:Pulling image: myAcrName.azurecr.io/mobile/signalr:20200421.09
(for BuildNumber 20200421.09) and it is inserting GIT COMMIT there as a tag and ends up with: Pulling image: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
Why o why?:)
[UPDATE 22.04 10:56]
I am posting build pipeline that i am using currently. I don't suppose it is important as it is working correctly, and the problem is more with deployment of correctly created docker image (on ACR), than with creating this image by the build pipeline. Nevertheless, here is the pipeline:
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
dockerRegistryServiceConnection: 'MyProductDockerACR'
imageRepository: 'mobile/signalr'
containerRegistry: 'myAcrName.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildNumber)'
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push image to container registry
inputs:
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepository)
command: 'buildAndPush'
Dockerfile: $(dockerfilePath)
tags: |
$(tag)
I saw the release you are using is configured by UI
. It's work logic much different with the one which configured by YAML
.
In fact, here what you received just be the different performance produced while the running reason of the release are different.
I guess this release has the artifact source which targeting to Repos, right? You can confirm by checking its icon.
While the release source is coming from Repos, then the Build.BuildNumber
would be the short part of the commit id
(8 characters). And the Build.BuildId is the complete commit id.
If you want the release keep using the Build.Buildnumber
value which the corresponding build(created/pushed image) was using, you must make sure the release source is targeting to this build. Also, this build need has artifacts generated. According to the YAML you shared, obviously, you haven't done that.
Only the release triggered by build along with artifact, then the Build.BuildNumber
can be like 20200422.1
which the build was using.
So, please go your release definition, and re-configure its source to make sure it is coming from build artifact instead of repository.
这篇关于Azure Devops-具有docker和Azure Container Registry(ACR)的发布管道-标记问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!