CI CD pipeline for deploying applications into the Azure Container apps using Azure DevOps

 

Steps: 

  • Develop Code at Local
  • Push code into a central git repository
  • Create Docker Image: Our pipeline, whether it be Azure DevOps, GitHub Actions, or another tool, will access the source code from the Git repository and subsequently build the Docker image from that code. Typically, we will have the Dockerfile that is utilized to create a new Docker image.
  • Push in Registry: After obtaining the Docker image, it ought to be pushed to a container registry, such as Azure Container Registry, Docker Hub, or any alternative container registry. We push Docker Hub Registry.
  • Deploy in Container App: The subsequent step involves deploying that application or container image into Azure Container Apps. To achieve this, we will utilize a particular task in Azure DevOps that will establish a connection to the Azure container. 
  • We will first set up the apps using a service principle, and then proceed to deploy that application into container apps.

 

 

LETS DO PRACTICALLY

Create a backed application 'backend_api_csharp_cicd'

Open Github 

  • Create a repository - backend_api_csharp_cicd
  • Clone our Repository at Local Working Directory ‘backend_api_csharp_cicd’
  • Copy our code from 'backend_api_csharp' to Working Directory ‘backend_api_csharp_cicd’
  • Upload our backend api code at Git


Go to DevOps and create pipeline

  • Create A Pipeline to upload our Web App into docker Container
  • PipeLines Tab > Create New Pipeline
  • Select and Approve you Repository at Git hub, where you to use your Pipeline
  • Select Starter PipeLines (Paste code to create a Container Image)
  • Save Directly on the main branch


Explanation of YAML file 

  • A trigger that each time there is a new commit on the main branch excluding some files like the Read-me files and so on.

 

  • Environment Variable Set
    • The image name.
    • Azure container app name
    • Azure container app Environment name 
    • Name of resource group
    • Image tag.  the tag uses the build.build ID, an incremental number for the build defined within Azure DevOps.

 

 

  • Stages
  • First stage, that is for building and pushing the Docker image.
    • Task 1: For Build the task is created for building the image. and name it with the name that I have specified for the repository and the tag.
    • Task 2: push the image to Docker hub to the container registry.

 

 

 

RUN n Test your Pipeline

  • Save your change and click RUN
  • at end you can success

  


  • Check your Container App At Azure
  • click your container app at home
  • Click Containers on Container App Page

 

 

 

in case you face error related to Authentication - add necessary authentication

  • ##[error]Error Code: [1] ##[error]Error: Unable to update Azure Container App via 'az containerapp update' command.
    • make sure you have both reader and writer permission in Application registration under Active Directory
    • Add Reader Permission using CLI
      • az role assignment create --assignee <application-clientid> --role Reader--scope "/subscriptions/<subscription-id>"
    • Add Writer Permission using CLI
      • az role assignment create --assignee <application-clientid> --role Contributor --scope "/subscriptions/<subscription-id>"
    • Check Permission to your application client id
      • az role assignment list --assignee <application-clientid>

 

Documentation at (By Microsoft)

 


Related Question