Setting the Context
In the first article of this series, we developed an ASP.NET Core application and created a "Docker Compose" file to package the application in a Linux container. Then, we configured an Azure DevOps pipeline Continuous Integration build to push this image to Azure Container Registry. In this article, we will pull the image from the Azure Container Registry and deploy it to Azure Web App for Linux Containers using Azure Pipeline deployment build. Below is the link to the first article.
Follow these steps that will help deploy the container to Azure Web App for Linux Container.
Step 1
Create a Service Principal in Azure AD and configure necessary privileges. By default, the Azure Pipeline should be able to pull the images from Azure Container Registry and deploy it Web App. To make this work the right permissions should be configured. Service Principal will do the trick here.
Step 2
Add the Service Principal to the Web App and Azure Container Registry. The Service Principal should be added to the Web App and Azure Container Registry so that the pipeline can seamlessly connect and work.
Step 3
Create Azure Pipeline Deployment build. Azure Pipeline Continuous Deployment build will pull the image from Azure Container Registry and deploy it to Web App.
Step 4
Run the Azure pipeline Deployment build. This will deploy the .NET Core application packaged in Linux container to the Web App.
Create a Service Principal in Azure AD and configure necessary privileges
Go to Azure portal and click on Azure Active Directory.
Click on App registrations.
Click on New registration.
Provide a suitable Name and click on Register.
Click on API permissions.
Click on Add a permission.
Select Visual Studio Team Services.
Check user_impersonation. Click Add permissions.
Click on Add a permission and select Azure Service Management and check user_impersonation as we did for Visual Studio Team Services. Click on Grant admin consent for Default Directory.
Now, the Service Principal is configured and can be used.
Add the Service Principal to Web App and Azure Container Registry
Go to the Azure Container Registry we created in the last article. Click on Access control (IAM).
Click on Add.
Click on Add role assignment.
Provide the right role and select the Service Principal we created earlier. Click on Save.
Go to the Web App we created in the last article. Follow exactly the same steps we did for Azure Container Registry to add the Service Principal.
Create Deployment Pipeline in Azure DevOps
Go to the project inside Azure DevOps. Click on Releases.
Click on New pipeline.
Select Azure App Service Deployment template and click Apply.
Select Azure Subscription and provide App type. Select App Service name where the container will be deployed. Provide Registry or Namespace for Azure Container Registry. Provide Repository Name and click on Save.
Click on Pipeline.
Click on Add an artifact.
Provide the source type as Azure Container Registry. Provide Service Connection, Resource Group, Azure Container Registry, and Repository.
Provide the default version as Specify at time of release creation. Click on Add.
Click on Save.
Now, the Deployment Build is released.
Run the Deployment build
Now, go to the Azure Repo and make some changes in the source code. Continuous Integration build that we created in the first part of the series will get triggered and a new image will be pushed to the Azure Container Registry as soon as we commit the changes. We can see below that a new image with tag 33 is pushed now in the registry.
Now, go to the Deployment Pipeline we have created. Click on Release.
Provide the version as the tag of the new image that got pushed to Azure Container Registry. Click on Create. The build will get triggered.
Once the build completes successfully, browse the Web App. The new changes can be seen.
Winding up
In this article, we deployed the .NET Core application packaged as a Docker container to Azure Web App for Linux. In the next article, we will see other easier options available by default in a Web App to support Continuous Deployment scenarios.