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.
- for this we need a connection with docker. Create connection with Docker Hub in DevOps first.
- docker name itself
- Second stage - Deployment
So for that we need to use this task, Azure Container apps, which is available actually on the list of tasks here if we search by container apps. - Search Task Template inside your pipeline
- Make connect with your Azure Account
- Define a container task to create a docker image at Azure
- Make sure following already created at Azure:
- Azure Container Apps Environment
- Azure Resources:Azure Container Registry (ACR)
- Azure Container App
RUN n Test your Pipeline
- Save your change and click RUN
- at end you can success