Auto update app in azure container apps on docker image push – Azure

by
Ali Hasan
azure-active-directory azure-container-apps

Quick Fix: To auto-update your app in Azure container apps on a docker image push, follow these steps:

  1. Enable managed identity and assign AcrPull permissions to your Container app.
  2. Create a CI/CD pipeline with tasks for building and pushing the docker image and creating a new revision in Azure container app.
  3. Configure the pipeline with the necessary details (ACR name, image name, container app name, etc.).

By implementing this, your app will automatically get updated whenever a new image is pushed to the registry.

The Solutions:

Solution 1: Automatic Revision Creation with CICD

To automatically create new revisions in Azure Container Apps upon image updates, follow these steps:

1. Enable Managed Identity and Grant Permissions:

  • Enable managed identity for your Container App.
  • Assign the "AcrPull" permission to the identity, granting it access to your Azure Container Registry (ACR).

2. Create a CI/CD Pipeline:

  • Set up a CI/CD pipeline with two tasks:
    • Docker@2 (buildAndPush): Builds and pushes the Docker image to the ACR, using tags like "develop" and $(Build.BuildId).
    • AzureContainerApps@1: Creates a new revision in your Container App using the newly pushed image.

3. Pipeline Code:

trigger: none

pool:
  vmImage: ubuntu-latest

steps:

- task: Docker@2
  displayName: Build & Push docker image to ACR
  inputs:
    containerRegistry: 'svc-acr' #using service connection for authenticating to ACR
    repository: 'testimg'
    command: 'buildAndPush'
    Dockerfile: 'Dockerfile'
    tags: |
      develop
      $(Build.BuildId)

- task: AzureContainerApps@1
  inputs:
    azureSubscription: 'svcv-g'
    acrName: 'containerregistryvjy'
    imageToDeploy: 'containerregistryvjy.azurecr.io/testimg:$(Build.BuildId)'
    containerAppName: 'acavjy01'
    resourceGroup: 'rg-name'
    containerAppEnvironment: 'managedEnvironment-rgname-bfb2'

4. Test and Verify:

  • Run the pipeline and check the output to verify the new revision creation.
  • Make a change in the code and rerun the pipeline to test the continuous deployment functionality.

Q&A

To automatically create new revisions in Azure container apps whenever a new version is available, what approach can be utilized?

To automatically create new revisions, a CICD approach can be utilized.

Can you provide the step-by-step configuration to enable continuous deployment using managed identity and Azure Container Apps?

Enable managed identity in Container app, assign AcrPull permission, create a CI/CD pipeline with Docker and AzureContainerApps tasks.

How can you test the continuous deployment flow?

Save and run the pipeline to review the output, observe the revision created in Azure Container Apps.

Video Explanation:

The following video, titled "Azure Container Apps - CI/CD deployments - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In this demo, we'll build a custom image for our app using Azure Container Registry. Steps will be: 1. Create a resource group 2.