Skip to content

Deploy Azure Container App from Azure DevOps

Hello World image of the Container Apps

November 02, 2021 Microsoft published new way to run Docker applications in the Azure. The Azure Container Apps is more of a SAAS version of the good old Azure Container Instances (ACI). There are some differences between these services like in the accessibility of the Kubernetes API, but I’m not now going to dive any deeper into that. However in this blog post I’m going to tell you how to deploy (update) Azure Container Apps applications from Azure DevOps.

The backbone of the deployment is again the container registry and for Azure services that means the Azure Container Registry. Our DevOps project will push new Docker image into container registry and then tell the Container Apps to update the app from there with latest tag. Azure DevOps does not yet have Container Apps task, so we have to do some AZ CLI magic for that.

1. build and publish application in devops into container registry. 2.tell container apps to update itself. 3. container apps reads image from azure container registry.
Architecture is based on container registry

First we need to setup build pipeline that builds our application, wraps it into Docker image and pushes that new Docker image into Azure Container Registry. Azure DevOps has a task called Docker build and push that can be used to push images into container registry. To access the container registry we need to add new service connection that can be created directly from task page by clicking the + New button next to container registry dropdown. Command we want to use is buildAndPush, so that this pipeline will build image by our Dockerfile definition and then push it into container registry. For tags I suggest replacing the BuildId with latest. This way our release pipeline can be set to always update the image from tag latest and we don’t have to worry about knowing the actual build id. You can also define multiple tags, so adding both is fine.

Set build pipeline to build and push Docker image into container registry
Build pipeline to build and push images into container registry.

After creating the build pipeline we can run it and check from Azure Portal that our container registry has newly build image in the repository. The tags section contains the build id and/or latest depending what was set into pipeline.

Newly build image should be now available in the container registry
helloworldcontainerapp repository contains one image with tag 12983 (build id)

Now that we have our image ready to be deployed, we need to create new release pipeline that will tell the Container Apps to get the image from container registry and update itself with it. So lets create a new release pipeline and add Azure CLI task into it.

Azure CLI tool does not yet have a full support for Container Apps, so we need to install the az extension into our build agent. The simplest way to achieve this is to run az extension add command. Note that there is -y in the ending for accepting the installation without user interaction. The full command is:

az extension add --source https://workerappscliextension.blob.core.windows.net/azure-cli-extension/containerapp-0.2.0-py2.py3-none-any.whl -y
Install Container Apps extension
Install the Container Apps extension

After installing the Container Apps extension we can command Container Apps to fetch the new image with az containerapps update command. We need to add second Azure CLI task into our pipeline and call the method in the inline script section.

Call az containerapp update to update the Container Apps
Call az containerapp update
az containerapp update `
   --name helloworld `
   --resource-group (reseource group name)`
   --image (imagename).azurecr.io/helloworldcontainerapp:12984 `
   --registry-login-server (continer registry name).azurecr.io `
   --registry-username (container registry username) `
   --registry-password (container registry password) `
   --target-port 80 `
   --ingress 'external' `
   --query configuration.ingress.fqdn

The az containerapp update requires multiple parameters, so we should go through all of them.

–name points into container app name that I have previously created. You can create container apps from Azure Portal or create one with az containerapp create command.
— resource-group needs resource group name that contains the Container App
— image is url into our container registry. You can fetch this url from container registry repository settings.
— restiry-login-server the name of the registry. Usually it is something.azurecr.io
— registry-username See this from container registry Access keys page
— registry-password See this from container registry Access keys page
— target-port The part that should be exposed
— ingress Is our app open to the world or only for integrated VNET
— query set the ingress setting.

The update is relatively slow and can take up to 10 minutes. After the deployment the Container Apps “Revision management” page should show the new instance

Summary

The Azure Container Apps has ready build support for GitHub actions in the deployment page, but luckily setting the pipeline for Azure DevOps is not that hard task to do. The pipeline relies on in-preview az extension, and in the future we should receive out-of-the-box support into Azure CLI tool. That’s why I separated the extension install step into own task in the pipeline, so that it can be removed easily when support is ready.

One last thing to note is that if you update the Container Apps application with new tag (for example build number), the app is deployed and provisioned into Container Apps as new revision, but the traffic manager is set to route traffic into old revision. Use az containerapp commands to route traffic into new revision when you have verified that the new app is working without issues.

Microsoft Container Apps deployment documentation is available at https://docs.microsoft.com/fi-fi/azure/container-apps/get-started?tabs=powershell

3 thoughts on “Deploy Azure Container App from Azure DevOps”

  1. I know the preview only supports Linux containers. Do you know if there are future plans to support windows containers?

  2. Pingback: Top Stories from the Microsoft DevOps Community – 2021.11.12 - Power Community

Comments are closed.