Reputation: 607
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://learn.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.
Upvotes: 0
Views: 2859
Reputation: 24138
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.
Upvotes: 2