Deploying a web application to an Azure App Service using MSDeploy - azure

I'm having a lot of trouble deploying my web application to an Azure App Service using MSDeploy. What are the command line arguments I need to use?

MSDeploy is a little finicky with the way it accepts parameters. First, the command will need the username and password for your App Service. This can be found by using the Azure CLI in PowerShell like so:
$publishProfile = az webapp deployment list-publishing-profiles --resource-group <ResourceGroupName> --name <WebAppName> --query "[?publishMethod=='MSDeploy']" | ConvertFrom-Json
This will place the username and password into the $publishProfile variable for use with MSDeploy later.
Next, if the path to the source published web site has spaces in it and PowerShell is being used, it will need to be converted to its equivalent short name syntax. If this is not done, MSDeploy will throw meaningless exceptions like the following that are painful to diagnose.
Error Code: ERROR_PROVIDER_NOT_FOUND
More Information: The provider 'dirPath=' could not be found. Learn more at: https://go.microsoft.com/fwlink/?LinkId=221672#ERROR_PROVIDER_NOT_FOUND.
at Microsoft.Web.Deployment.DeploymentProviderSettingCollection..ctor(String factoryName)
at Microsoft.Web.Deployment.DeploymentProviderOptions..ctor(String factoryName)
at MSDeploy.MSDeploy.GetObjectParameters(Dictionary`2 parameters, Boolean isDestination, DeploymentBaseOptions& retbaseOptions, DeploymentProviderOptions& retproviderOptions)
at MSDeploy.MSDeploy.ExecuteWorker()
at MSDeploy.MSDeploy.Execute()
at MSDeploy.MSDeploy.Main(String[] unusedArgs)
Error count: 1.
To convert the path to its short name equivalent, use the following command:
$shortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder(".\Publish").ShortPath
And finally, here's the command to run MSDeploy and deploy the web application to Azure. In order to use the command below, the $webAppName variable will need to be defined.
$webAppName = "MyWebApp"
&"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:dirPath="$shortPath",includeAcls=false -dest:dirpath=D:\home\site\wwwroot,ComputerName="https://$webAppName.scm.azurewebsites.net/msdeploy.axd?site=$($webAppName)",UserName=$($publishProfile.userName),Password=$($publishProfile.userPWD),AuthType='Basic' -verbose -debug
The command should return output similar to the following:
Info: Using ID 'd5e5eb3d-...' for connections to the remote server.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
Verbose: Performing synchronization pass #1.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
Verbose: Received response from agent (HTTP status 'OK').
Info: Adding directory (D:\home\site\wwwroot\cs).
Info: Adding directory (D:\home\site\wwwroot\de).
Info: Adding directory (D:\home\site\wwwroot\es).
Info: Adding directory (D:\home\site\wwwroot\fr).
Info: Deleting file (D:\home\site\wwwroot\hostingstart.html).
Info: Adding directory (D:\home\site\wwwroot\it).
Info: Adding directory (D:\home\site\wwwroot\ja).
Info: Adding directory (D:\home\site\wwwroot\ko).
Info: Adding directory (D:\home\site\wwwroot\pl).
Info: Adding directory (D:\home\site\wwwroot\pt-BR).
Info: Adding directory (D:\home\site\wwwroot\ru).
Info: Adding directory (D:\home\site\wwwroot\runtimes).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\unix\lib\netcoreapp2.1).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netcoreapp2.1).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win\lib\netstandard2.0).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-arm64\native).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x64\native).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86).
Info: Adding directory (D:\home\site\wwwroot\runtimes\win-x86\native).
Info: Adding directory (D:\home\site\wwwroot\tr).
Info: Adding directory (D:\home\site\wwwroot\zh-Hans).
Info: Adding directory (D:\home\site\wwwroot\zh-Hant).
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The current synchronization pass is missing stream content for 201 objects.
Info: Using ID '1f1ab053-88c6-40a2-90e4-5347157542e6' for connections to the remote server.
Verbose: Performing synchronization pass #2.
Verbose: Pre-authenticating to remote agent URL 'https://webappname.scm.azurewebsites.net/msdeploy.axd?site=webappname' as '$webappname'.
...
Verbose: The HTTP connection (ID='1f1ab053-88c6-40a2-90e4-5347157542e6', type ='GetTraceStatus') is being kept alive while the request is processed.
Verbose: Received response from agent (HTTP status 'OK').
...
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The synchronization completed in 2 pass(es).
Total changes: 231 (230 added, 1 deleted, 0 updated, 0 parameters changed, 44498979 bytes copied)

Related

Publishing Azure Function Using CloudShell

I am using CloudShell to publish AzureFunction. I was able to publish the AzureFunction previously but today I am getting this Error while executing the publish command func azure functionapp publish <APP_NAME>
Getting site publishing info...
Creating archive for current directory...
Performing remote build for functions project. Deleting the old .python_packages directory Uploading 15.91 KB [##############################################################################]
Remote build in progress, please wait...
Unexpected character encountered while parsing value: {. Path '[0].build_summary', line 1, position 630.

arm template, customscriptextension is failing with returned a non-zero exit code of: '1'. Command execution may have been interrupted by a VM restart

i have a arm template that contains a customscriptextension that is meant to install an app (Sophos AV and Notepad++) from a storage account.
the deployment is picking up the storageaccount correctly and copying the sophos.ps1 file from the blob storage account and adding it to the VM.
i can find the file in this location
C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.10.12\Downloads\0
the log file for the customscriptextension shows that sophos file is downloaded.
[INFO] DownloadFiles: fileUri = https://stgacctname.blob.core.windows.net/scripts/sophos.ps1
[INFO] DownloadFiles: fileDownloadPath = C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.10.12\Downloads\0
[INFO] Waiting for all async file download tasks to complete...
[INFO] DownloadFiles: asynchronously downloaded file to fileDownloadLocation = Downloads\0\sophos.ps1
[INFO] Files downloaded. Asynchronously executing command: 'SecureCommand_0'
[INFO] Command execution task started. Awaiting completion...
but the install of this file is failing and spitting out this error
**[ERROR] Command execution finished, but failed because it returned a non-zero exit code of: '1'. Command execution may have been interrupted by a VM restart**
[INFO] {"sequenceNumber":0,"totalDuration":21317,"status":"error","code":1,"filesDownloaded":1,"durationOfFileDownload":336,"durationOfDownloadHashing":0,"statusFileAccessed":5,"operation":"enable","operationDuration":123,"operationResult":"success","operationSizeOfOutput":42,"operationSizeOfError":0,"sha256HashOfCommandToExecute":"HASHNUMBER","downloadSummary":{"downloadUris":["https://stgacctname.blob.core.windows.net/scripts/sophos.ps1"],"fileHashes":[{"fileName":"sophos.ps1","sha256Hash":"HASHNUMBER"}]}}
the sophos.ps1 file contains the following
Set-ExecutionPolicy Bypass
cmdkey /add:stgacctname.file.core.windows.net /user:AZURE\stgacctname /pass:sttgacctkey
\\stgacctname.file.core.windows.net\fileshare\SophosSetup.exe --quiet --devicegroup="Test servers"
\\stgacctname.file.core.windows.net\fileshare\npp.8.1.4.Installer.x64.exe /S
when i open the PS1 file and run it as admin it runs and installs sophos without any issues.
so question is...why is it failing here?
my thoughts are that the PS1 file is not being run as admin... its running as a standard user so its failing.. but thats just pure speculation.
can anybody shed some light on what could be happening?
let me know if you need any more info...
in the mean time i will keep digging around....
cheers!

Azure Function deployed using FTP, how to fix non-existence docker container issue

I am in development phrase, and I am trying out Azure Function, with the following settings:
Linux
Premium Plan,
NodeJS 12
Deploy using FTP
What I have done:
I have deployed a sample Durable Functions HTTP Starter as specified here: https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-js-vscode#client-function-http-starter
And deployed my code to the xxxxxxxxxxx.ftp.azurewebsites.windows.net under /site/wwwroot
And I received the following Error in LogFiles/2020_06_10_xxxx_docker.log:
2020-06-10T01:05:51.825Z ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository)
2020-06-10T01:05:51.845Z INFO - Stopping site XXXXXXXXXX because it failed during startup.
2020-06-10T01:09:59.152Z INFO - Pulling image from Docker hub: mcr.microsoft.com/azure-functions/node:3.0-node8-appservice-stage6
2020-06-10T01:10:00.049Z ERROR - DockerApiException: Docker API responded with status code=NotFound, response={"message":"manifest for mcr.microsoft.com/azure-functions/node:3.0-node8-appservice-stage6 not found: manifest unknown: manifest tagged by \"3.0-node8-appservice-stage6\" is not found"}
Upon inspection, this mcr.microsoft.com/azure-functions/node:3.0-node8-appservice-stage6 docker image didn't exists, so it failed.
My question is, how to instruct Azure Function to use a valid docker image instead of a non-existing one? Or if any step above I done wrong so result in this issue? Thanks
Completely removing the Azure Function and creating a new one fix this issue.

MSDeploy fails with authorization error when using filePath provider

I am trying to deploy a web application using MSDeploy. In the first step the app is deployed to test server (using the package created during the build), then to production server (source and destination are iisApp) and the next step is production web.config file deployment to the production server.
Everything works fine but the web.config file deployment reports an error
Error Code: ERROR_USER_NOT_AUTHORIZED_FOR_DEPLOYMENTPROVIDER
More Information: Could not complete an operation with the specified
provider ("filePath") when connecting using the Web Management Service.
This can occur if the server administrator has not authorized the user for
this operation. filePath http://go.microsoft.com/fwlink/?LinkId=178034
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_NOT_AUTHORIZED_FOR_DEPLOYMENTPROVIDER.
I am using the same machine for deployment, the same username and the same password. I can see the user has filePath deployment enabled (as well dirPath, contentPath, iisApp and setAcl) in the Management Service Delegation screen in IIS Manager on the machine used for deployment:
It also fails for dirPath and contentPath.
Can anybody help? Thanks
Update - log when MSDeploy executed with -verbose flag
"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy"
-verb:sync -source:filePath="C:\MyProject\DeployConfig\web\web.config"
-dest:filePath="web/web.config",computerName="https://deployement:8172/MSDeploy.axd?site=my-site",userName="publish",password="password",authtype="Basic",includeAcls="False"
-allowUntrusted -verbose
Info: Using ID '7fcedfe4-c103-48f4-ab98-4fae743d5eb7' for connections to the remote server.
Verbose: Pre-authenticating to remote agent URL 'https://deployment:8172/MSDeploy.axd?site=my-site' as 'publish'.
Verbose: Performing synchronization pass #1.
Verbose: Pre-authenticating to remote agent URL 'https://deployment:8172/MSDeploy.axd?site=my-site' as 'publish'.
Verbose: No backup was executed.
Verbose: Received response from agent (HTTP status 'OK').
Info: Adding MSDeploy.filePath (MSDeploy.filePath).
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The current synchronization pass is missing stream content for 1 objects.
Info: Using ID '8f582c09-614e-4344-87c9-64867e44fc4e' for connections to the remote server.
Verbose: Performing synchronization pass #2.
Verbose: Pre-authenticating to remote agent URL 'https://deployment:8172/MSDeploy.axd?site=my-site' as 'publish'.
Info: Adding MSDeploy.filePath (MSDeploy.filePath).
Verbose: Received response from agent (HTTP status 'OK').
Info: Adding child MSDeploy.filePath (C:\MyProject\DeployConfig\web\web.config).

Why is Web Deployment Agent Service (MsDepSvc) crashing with a FileNotFoundException?

I'm attempting to deploy a .NET 4 web application to a Windows 2008R2 server using Web Deploy V2. As part of this deployment we copy some batch files to the target machine. When I execute the command below, Web Deployment Agent Service (MsDepSvc) stops and a FileNotFoundException is logged to the system Application event log.
The web deploy command:
"C:\Program Files (x86)\IIS\Microsoft Web Deploy V2\msdeploy.exe" -verb:sync -source:contentPath="C:\work\27f84e3eca3a33d5\Output\BatchFiles" -dest:contentPath="c:_DeployCommands",computerName="192.168.1.14"
Full console output:
C:\Windows\system32>"C:\Program Files (x86)\IIS\Microsoft Web Deploy
V2\msdepl y.exe" -verb:sync
-source:contentPath="C:\work\27f84e3eca3a 3d5\Output\BatchFiles"
-dest:contentPath="c:_DeployCommands",computer ame="192.168.1.14" Info: Using ID '326b55b4-602c-4cdf-ae5c-052e9d44b377' for connections
to the remote server. Warning: Retrying the sync because a socket
error (10054) occurred. Retrying operation 'Serialization' on object
MSDeploy.contentPath (sourcePath). Attempt 1 of 25. Info: Using ID
'a6e468ca-53b9-474b-8568-42dba196bd72' for connections to the remote
server. Error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC More
Information: Could not connect to the destination computer
("192.168.1.14" using the specified process ("Web Deployment Agent
Service") because the serve did not respond. Make sure that the
process ("Web Deployment Agent Service") i started on the destination
computer. Error: The remote server returned an error: (503) Server
Unavailable. Error count: 1.
Event Log Entry:
Application: MsDepSvc.exe Framework Version: v4.0.30319 Description:
The process was terminated due to an unhandled exception. Exception
Info: System.IO.FileNotFoundException Stack: at
Microsoft.Web.Deployment.Tracer.TraceError(Microsoft.Web.Deployment.DeploymentTraceSource,
System.String, System.Object[]) at
MSDepSvc.WDAgent.BeginProcessRequest(System.Net.HttpListenerContext)
at System.Net.LazyAsyncResult.Complete(IntPtr) at
System.Net.ListenerAsyncResult.IOCompleted(System.Net.ListenerAsyncResult,
UInt32, UInt32) at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32,
UInt32, System.Threading.NativeOverlapped*)
How can I diagnose this?
We ran into a similar issue. You're best bet is to decompile using ILSpy and add extra logging in every catch block and replace the exe on the client to see the exact error. In our scenario, we used on older version 7.1.1631.0 that works. There's a newer version 7.1.1762.0 that's caused the problem. The exe is copied from the client and not the server.
I had the exact same issue. It turned out to be a bug in Web Deploy 3.5 as described here: Could not find file or assembly Microsoft.Web.Deployment.Tracing with Web Deploy V3 using tempagent

Resources