I’ve recently got chance of exploring Azure Web app and was surprised how simple and useful the Web apps and App service plans are. But the only down side being not so great documentation which are mostly interlinked articles.
Azure web apps are Platform As A Service(PAAS), what it means to us is it provides few features(like auto scaling) out of the box. (click here to know more what web apps).Linux Web apps are based on Docker containers making deployments simple.
Here is the quick tutorial for the complete setup in Azure. For this tutorial I’ve used the Azure cli commands, also you can use azure portal to achieve the same.
Step 1: Create a Resource Group
az group create --name MyRG --location "South Central US"
Step 2: First we start with creating the App service plan (ASP) into the resource group.
az appservice plan create -g MyRG -n MyPlan --is-linux -l "South Central US" --sku S1 --number-of-workers 1
Step 3: Create a Linux web app so that we can host our docker containers.
az webapp create -g MyRG -p MyPlan -n MyUniqueAppName --runtime "node|6.2"
Do not worry about run time, it doesn’t matter as we going to use docker image
Step 4:Enable the port in the Web app, this must be the same port number that is exposed in Docker file
az webapp config appsettings set -g MyRG -n MyUniqueAppName --settings PORT=8000
Step 4: Enable container continuous deployment feature in the Web app created
az webapp deployment container config -n MyUniqueAppName -g MyRG -e true
Step 5: Get Webhook URL of the Web app to trigger aoti deployemnt
az webapp deployment container show-cd-url -n MyUniqueAppName -g MyRG
The above command will echo a URL similar to https://<publishingusername>:<publishingpwd>@<sitename>.scm.azurewebsites.net/docker/hook.
Step 6:Create a container registry to host private images, If the images are public and are available on docker hub then you can skip this step.
az acr create -n MyContregistryxyqwe -g MyRG --sku Standard -l "South Central US" --admin-enabled true
Step 8: Get the credentials of the private registry we created
az acr credential show -g MyRG -n MyContregistryxyqwe
Use one of the above credentials to push the docker image to private registry
Step 7: Add Webhook to the container registry to trigger when the image is pushed to the registry.
az acr webhook create -r <my-cr-name> -n <my-wh-name> --actions push --uri <wh-url-from-step-6> --scope <repo-name:latest_tag>