In this post I am going to deploy a simple REST API written on Deno to Azure Web app for Containers and use Azure container registry to hold the container, and use Azure Pipelines to enable CI/CD.
- Azure Account
- Azure DevOps Account
- You can clone the repo from here
- Create a new repository in either Azure Devops or Github
- Go to Azure Portal
- Create a Web App for Container
- Create an Azure Container Registry (ACR)
- Go to your Azure DevOps Account, go to Releases section, click on new pipeline
- In the connect section, click on classic editor
- Select a source and Project, Repository and Branch, in my case I have the code uploaded in a new repository in Azure Devops, you can choose anyone of your choice.
- Select Template, click on empty Job
- In next, step click on add Task (+) icon
- Search for docker build, and click on Docker
- Now give it a name Build an image, and click on + New Button
- upon, new service connection, select Azure Container Registry, and fill in your subscription and other details, it will automatically populate your ACR created in portal.
- Now, create a Task again to push the image, select Docker give the name Push an Image,
Container Registry Type = Azure Container Registry
select subscription, it will populate your ACR,
Action = Push an image
Image name = ur-image-name:tag
Thats, it , the build, pipeline configuration is done, now you can click on Run Pipeline
The next process is to create a release pipeline,
- Go to the release section you will find it in the pipelines menu of Azure Devops on the left side
- Click on Create Pipeline
- Upon click, a modal asks to select a template, from a list, you need to select Azure App Service deployment.
- Give an appropriate stage name, means (production, development, testing, etc..)
- Link your Azure Subscription
- App Type = Web App for Containers (Linux)
- App Service name = select your webapp service appname you have already created in azure portal
- Registry = name of Azure container registry (fully qualified)
- Repository - you can find it from the previous build pipeline step
- startup command = leave blank
Hurrayyyy!! Thats,it now click on Create a Release, now the pipeline will run, get your image from your ACR and Deploy it in Azure Web App for Container
- go to your app service in Azur eportal - go to overview section, click on the URL, which will open in a new tab
Open postman, click on create a new request,
enter your URL and corresponding api route and click on Send
In case you have any DockerAPIException like follows
You need to give access to your Azure App Service for Container,
just go to the Azure Container Registry, go to IAM (left side),
Click on add a role assignment, select contributor role and select your App Service.
Go to Azure Container Registry, enable Admin Access
Goto IAM Control, add a contributor role to App Service( if app service is not reflecting, go to your app service and go to identity section on the left, and click on system assigned - change status to On)
Restart your App Service, changes will take few minutes to propogate.