I'm trying to deploy an Azure Container App using an Azure DevOps Pipeline. It's pushing a new image to my ACR but the Container App is not running the new image. My understanding is that it should be creating a new revision with the new image but the only revisions / replicas are a couple of weeks ago, possibly from when I tried to use the publish feature in Visual Studio to do it.
I'm new to container apps so I'm not sure if there's something that needs to be configured in Azure so that it automatically pulls the new image or if the pipeline is meant to do this.
My yaml is:
trigger:
- main
pool:
vmImage: ubuntu-latest
name: '$(Date:yyyyMMdd).$(Rev:rr)' # Set build number
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: 'BackEnd/BackEnd.csproj'
- task: AzureContainerApps@1
inputs:
appSourcePath: '$(Build.SourcesDirectory)'
azureSubscription: 'my-service-connection'
acrName: 'MyAcr'
containerAppName: 'my-backend-app'
resourceGroup: 'myresourcegroup'
imageToBuild: MyAcr.azurecr.io/my-backend-app:$(Build.BuildNumber)
Note: I've tweaked some azure resource names that I'd rather not be public
My container app has a managed identity and has the AcrPull permission for my ACR.
Edit: For clarity, I can see the new image in my ACR each time the pipeline is run, the problem is that the Container App is not using the new image, it's continuing to run the old image.
Can anyone help?
Update: With the suggestions from @Alvin below, I managed to get it deploying successfully but after 3 updates, it broke without any changes to the pipeline and is now stuck again.
I created a new container app as my original one appeared to be stuck and I couldn't create any revisions manually, either with CLI or from the portal UI. I added a dotnet publish step to create an image directly and push to ACR, which is a LOT faster than using AzureContainerApps@1 for building. I then updated the AzureContainerApps@1 to just deploy the image I'd pushed in the previous command. On the 4th run of my pipeline, it took over 11 minutes instead of the previous 1m30 but looked as though it was successful. After this my container app in the portal showed as having 2 "Active Revisions" but with both "Scaled to 0". The app doesn't respond to incoming traffic and every time I've run the pipeline since, no further revisions are created; it only shows 2 active and 1 inactive (the first 3 that I created).
After help from @Alvin Zhao - MSFT here, I discovered that you need to call AzureContainerApps@1
a second time with deploy parameters to actually deploy;
However my original container app seemed to be stuck and was showing a failed revision in addition to the running one and i couldn't create a new revision using the pipeline, CLI or the portal UI, so I needed to create a new container app.
After 3 successful deployments to the new app, it got stuck again showing 2 revisions, both with 0 replicas (meaning it didn't respond to any web requests). This eventually resolved itself after about an hour of downtime.
The same thing happened again after a few more deployments.
I now have the pipeline working reliably but I've abandoned the AzureContainerApps@1
command and instead I'm building and pushing the image with dotnet publish
and then using the Azure CLI command that AzureContainerApps@1
was actually calling internally.
This seems to be both reliable but also takes less than a third of the time to actually run. My new pipeline yaml is
trigger:
branches:
include:
- main
name: '$(Date:yyyyMMdd).$(Rev:rr)' # Set build number
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
inputs:
containerRegistry: 'MyACR-Connection'
command: 'login'
- task: DotNetCoreCLI@2
displayName: 'Build backend project, build image and push to ACR'
inputs:
command: 'publish'
publishWebProjects: false
projects: 'BackEnd/BackEnd.csproj'
arguments: '/t:PublishContainer -p:ContainerImageTag=$(Build.BuildNumber) -p:ContainerRegistry=myacr.azurecr.io'
zipAfterPublish: false
- task: AzureCLI@2
displayName: 'Update Azure Container App with new container'
inputs:
azureSubscription: 'my-azure-service-connection'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az containerapp update -n my-backend -g MyResGroup --image myacr.azurecr.io/my-backend:$(Build.BuildNumber)'
I then added to my csproj
<PropertyGroup>
<IsPublishable>true</IsPublishable>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
<ContainerRepository>my-backend</ContainerRepository>
<ContainerFamily>jammy-chiseled</ContainerFamily>
<ContainerRuntimeIdentifier>linux-x64</ContainerRuntimeIdentifier>
</PropertyGroup>