Kudu Azure App Zip Deploy via Powershell - Transfer files to wwwroot

守給你的承諾、 提交于 2019-12-08 09:23:42

问题


I am using the Kudu Azure Zip Deploy API from powershell.

How can I ensure that the contents of the deployed zip folder are extracted within wwwroot with wwwroot being the containing folder?

Current:

(here my zip folder is the container within wwwroot)

/site/wwwroot/MYZIPFOLDERNAME/CONTENTS

Expected:

(I want the contents of the zip folder to be added directly to wwwroot and outside of the zip folder name)

/site/wwwroot/CONTENTS

I have followed the documentation like below and have a powershell script like below:

https://docs.microsoft.com/en-us/azure/app-service/deploy-zip

#PowerShell
$username = "<deployment_user>"
$password = "<deployment_password>"
$filePath = "<zip_file_path>"
$apiUrl = "https://<app_name>.scm.azurewebsites.net/api/zipdeploy"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"

Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath -ContentType "multipart/form-data"

When the script is finished, the zipped file is uploaded to my site, however the content is packaged within the folder and nested under the wwwroot directory.

If I use the ZipDeployUI and drag the folder, it unzips into the wwwroot/ directory without the folder name as expected.


回答1:


I followed the offical document Deploy your app to Azure App Service with a ZIP or WAR file to run the PowerShell script in the subsection With PowerShell, it's OK and works fine.

Your issue was caused by the file structure of your zip file. I will show you the difference.

There are two xml files in my directory D:\projects\xml on local. I packaged them into a zip file xml.zip using two different way: with a container xml, without any container, as the figures below via 7-zip.

Fig 1. a container xml in the zip file xml.zip

Fig 1.1. the container xml contains two xml files

Fig 2. no container in the zip file xml.zip

Then I run the same PowerShell script with different zip file which has different file structure, I got the different result in the ZipDeployUI of my WebApp, as the figures below.

Fig 3. Run the PowerShell script with the zip file which has a container xml, the xml container be decompressed under wwwroot

Fig 3.1. the two xml files within the container xml under the path wwwroot/xml

Fig 4. Run the PowerShell script with the zip file which has no container, the two xml files be decompressed directly under wwwroot

So please package these files directly to a zip file, not package their parent directory, if you were using some tools like 7-zip. Or in the PowerShell command line, please first cd move to the directory which contains these files you want to package, then to run Compress-Archive -Path * -DestinationPath <file-name>.zip to get a zip file, as Create a project Zip file said.

Hope it helps.



来源:https://stackoverflow.com/questions/57100250/kudu-azure-app-zip-deploy-via-powershell-transfer-files-to-wwwroot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!