Deploying a Web Application from Source Control Alongside Azure Resources using ARM Templates
In this short article I describe a way of deploying a web application in to an Azure App Service Web App alongside the Web App resource itself using Azure Resource Manager templates.
First create a new Azure Resource Group project using Visual Studio. Give the project a name and select a location for the project.
Then from the Select Azure Template dialog select Web App template to keep things simple. This will give us a template with an Azure App Service web application, an App Service Plan and some alerts and Application Insights component.
For this demo we don’t need the Application Insights component and the server alerts and auto scale rules. So, I will clean up the template by deleting the unnecessary resources. So now we only have a App Service Plan and a Web Site in the template.
Now to deploy the application using the ARM template, we need to do some changes to the Web Site definition in the ARM Template. Add the following code segment in to the Web Site resource.
"resources": [
{
"name": "web",
"type": "sourcecontrols",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('webSiteName'))]"
],
"properties": {
"RepoUrl": "[parameters('repositoryUrl')]",
"branch": "[parameters('branch')]",
"IsManualIntegration": true
}
}
]
So, we have added a resource section in to an existing website resource. So, what we have done is adding a sub resource to an existing resource. There are some resources that can have sub resources and Azure Resource Manager documentation has more information.
In the code segment, we have used web as the name, which is a pre-configured name meaning the name has to be web. Then we have the resource type as sourcecontrols and the API version. Then we have declared a dependency on the Web Site resource by using dependsOn. So, the Web Site resource must exist in order for the deployment to happen. Next, we have the properties related to the deployment.
As properties we have the RepoUrl which is the URL of the source control repository where our web application code resides. We will be using a GitHub repo that contains an ASP.Net MVC application. Then we define the branch we need to deploy. Both these values are taken from a parameter we have defined. And finally, we have set IsManualIntegration to true.
Now we are ready to deploy the ARM template. We can use PowerShell to deploy this template from the local machine. But we will use Visual Studio Team Services for this example.
Create a Build Definition on Visual Studio Team Services and add Azure Resource Group Deployment task from the Deploy section of the available tasks.
As seen in the screen shot, configure the task to use an Azure Subscription, and set the Resource Group, Location and Select the Template and Template Parameter file for the deployment. Finally, save and queue a new build.
After the deployment completes, navigate to the Azure Portal and go in to the Resource Group you selected, you can see an App Service Plan and a Web App is created. Click on the Web App and go to Deployment Options section.
You can see there is a deployment configured there and a new deployment has already happened. Then use the web browser to navigate to the site that you just created. There you can see the ASP.Net MVC Web Application we provided is now deployed in to the Azure App Service Web App.
Summary
In this article we discussed how we can include a sub resource in to an Azure App Service web app resource to deploy a web application from source control when deploying web app resource using ARM Templates. Hope you enjoyed this article, I’ll see you on the next one.
You Might Also Like
← Previous Post
Introducing OWASP Zed Attack Proxy Task for Azure Pipelines
September 03, 2017
Next Post →