0
votes

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
why would the script unzip it for you? is that specified in the documentation?lloyd
@lloyd, the documentation says the default path is wwwroot but is unclear about there being a folder. Using the ZipDeployUI puts the zip folder directly into wwwroot without the nested directory, whereas powershell adds the nested directory, so curious why the difference? Is there a good way to copy over the files ie a post deploy trigger?apleroy

1 Answers

1
votes

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

enter image description here

Fig 1.1. the container xml contains two xml files

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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.