Deno on Azure - Azure Pipelines, Azure Container Registry and Azure Web App for Containers
Tags: deno, azure, azurepipelines, azurewebapp
Published: 2020-06-14 15:08:52

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.


### Prerequisites
- Docker
- Azure Account
- Azure DevOps Account

### Download the repository
- You can clone the repo from [here](https://github.com/jishnukoottala/deno-task-management-api)
- Create a new repository in either Azure Devops or Github

### Create resources
- Go to Azure Portal
- Create a Web App for Container 

![Create a web app](https://dev-to-uploads.s3.amazonaws.com/i/tx88sc06zbab6oanai6v.png)

- Create an Azure Container Registry (ACR)

![Azure Container registry](https://dev-to-uploads.s3.amazonaws.com/i/76jhmd0wbk8pf5q0w0ef.png)




### Create Build Pipeline
- Go to your Azure DevOps Account, go to Releases section, click on new pipeline

![Image of Release Pipeline]
(https://dev-to-uploads.s3.amazonaws.com/i/qtkveezht2j792up4kyq.png)

- In the connect section, click on classic editor 

![Select Classic Editor](https://dev-to-uploads.s3.amazonaws.com/i/ihjqk70pj03m5m14r006.png)

- 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 Source](https://dev-to-uploads.s3.amazonaws.com/i/jg4f4ulc4u5i2b90pyf1.png)

- Select Template, click on empty Job

![select template](https://dev-to-uploads.s3.amazonaws.com/i/vc7b8nh4i9ep6tx0f69z.png)

- In next, step click on add Task (+) icon

![click add task](https://dev-to-uploads.s3.amazonaws.com/i/lx1w2lbuwqog3phfhecu.png)

- Search for docker build, and click on Docker 

![Select Docker](https://dev-to-uploads.s3.amazonaws.com/i/uzqreofgllbspk0uksbv.png)

- Now give it a name Build an image, and click on + New Button

![build image](https://dev-to-uploads.s3.amazonaws.com/i/7taofwrqqhzf7d2a4hyl.png)

- 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.

![Service Connection](https://dev-to-uploads.s3.amazonaws.com/i/c683yqm1x5e8mydu85ua.png)

![Build id](https://dev-to-uploads.s3.amazonaws.com/i/cp0h7nvyokc04knuqq9i.png)

- 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 <br>

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4s2ncb003bfnfobattyp.png)


![Pipeline Running](https://dev-to-uploads.s3.amazonaws.com/i/2xm3mzazppnpfnxyflzl.png)

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

![New Release](https://dev-to-uploads.s3.amazonaws.com/i/r8hgkop2gp1u66jp0wiy.png)

- Upon click, a modal asks to select a template, from a list, you need to select Azure App Service deployment.


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v4cfqrwzsoyubv6rxege.png)


- 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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/maryx6q45e9kh61a0igq.png)

Inorder to enable continous deployment, add an artifact as well
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x0dgbnbibaalovhbm1es.png)


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


### Accessing API through Public URL
- go to your app service in Azur eportal - go to overview section, click on the URL, which will open in a new tab

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/aafwdpi3slhavczao14t.png)

### Testing your API in postman
Open postman, click on create a new request, 
enter your URL and corresponding api route and click on Send

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/frcq74lnii1b3q9wobe1.png)




### Troubleshooting
In case you have any DockerAPIException like follows 

![error message](https://dev-to-uploads.s3.amazonaws.com/i/y59lsyl18pui9z6ua2xd.png)

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.