I am trying to create an ARM template to deploy resources for VM plus auto-deploy ASP.Net web app to VM using CustomScriptExtension. I have created a CustomScriptExtension child resource under VM with code snippet as follow:
"resources": [{
"type": "extensions",
"name": "CustomScriptExtension",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"<my_storage_file_path>/webdeploy.ps1"
],
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File webdeploy.ps1"
}
}
}
]
Here's the powershell script for webdeploy.ps1:
# Install IIS (with Management Console) Install-WindowsFeature -name Web-Server -IncludeManagementTools # Install ASP.NET 4.6 Install-WindowsFeature Web-Asp-Net45 # Delete contents of wwwroot Remove-Item -Recurse C:\inetpub\wwwroot\* # Install Web Management Service (enable and start service) Install-WindowsFeature -Name Web-Mgmt-Service Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 Set-Service -name WMSVC -StartupType Automatic if ((Get-Service WMSVC).Status -ne "Running") { net start wmsvc } # Install Web Deploy 3.6 # Download file from Microsoft Downloads and save to local temp file (%LocalAppData%/Temp/2) $msiFile = [System.IO.Path]::GetTempFileName() | Rename-Item -NewName { $_ -replace 'tmp$', 'msi' } -PassThru Invoke-WebRequest -Uri http://download.microsoft.com/download/0/1/D/01DC28EA-638C-4A22-A57B-4CEF97755C6C/WebDeploy_amd64_en-US.msi -OutFile $msiFile # Prepare a log file name $logFile = [System.IO.Path]::GetTempFileName() # Prepare the arguments to execute the MSI $arguments= '/i ' + $msiFile + ' ADDLOCAL=ALL /qn /norestart LicenseAccepted="0" /lv ' + $logFile # Sample = msiexec /i C:\Users\{user}\AppData\Local\Temp\2\tmp9267.msi ADDLOCAL=ALL /qn/norestart LicenseAccepted="0" /lv $logFile # Execute the MSI and wait for it to complete $proc = (Start-Process -file msiexec -arg $arguments -Passthru) $proc | Wait-Process Get-Content $logFile #Deploy Web App package $WebClient = New-Object -TypeName System.Net.WebClient $Destination= "C:\WindowsAzure\WebApplication.zip" #$WebClient.DownloadFile($using:WebDeployPackagePath,$destination) $WebClient.DownloadFile("<my_personal_storage_account_web_application_path>.zip",$destination) $Argument = '-source:package="C:\WindowsAzure\WebApplication.zip" -dest:auto,ComputerName="localhost", -verb:sync -allowUntrusted' $MSDeployPath = (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" | Select -Last 1).GetValue("InstallPath") Start-Process "$MSDeployPath\msdeploy.exe" $Argument -Verb runas
After running the ARM template, all the resources are deployed correctly, but the web app is not deployed to IIS. I checked that the IIS and Web deploy are installed as according to the script. I also see that my web application zip file is downloaded from my storage account to C:\WindowsAzure\WebApplication.zip. Appreciate if anyone can advise me on the correct coding for the #Deploy Web App package part.
I can manually publish my app to the VM from Visual Studio after running the ARM template. But still I want to know how do that in automated way via CustomScriptExtension/powershell
Many thanks in advance.