azure - 使用 Powershell 发布到 WebApp 虚拟目录
问题描述
我有一个 Azure WebApp,它分为两个虚拟目录 - UI 和 API。
我设法在代码中创建了虚拟目录,但找不到向它们发布的方法。
到目前为止,这是我的代码:
# Set UI Virtaul Directory (call /ui )
$website = Get-AzWebApp -Name $appsvWebAppName -ResourceGroupName $resourceGroupName
$VDApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication
$VDApp.VirtualPath = "/ui"
$VDApp.PhysicalPath = "site\wwwroot\ui"
$VDApp.PreloadEnabled ="YES"
$website.siteconfig.VirtualApplications.Add($VDApp)
$website | Set-AzWebApp -Verbose
# Set API Virtual Directory (call /api )
$website = Get-AzWebApp -Name $appsvWebAppName -ResourceGroupName $resourceGroupName
$VDApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication
$VDApp.VirtualPath = "/api"
$VDApp.PhysicalPath = "site\wwwroot\api"
$VDApp.PreloadEnabled ="YES"
$website.siteconfig.VirtualApplications.Add($VDApp)
$website | Set-AzWebApp -Verbose
$website.SiteConfig.VirtualApplications
# Dotnet publish & convert to zip here, removed for brevity ...
$uiZipPath = $zipFilesFolder + "\ui.zip"
$publishprofile = Get-AzWebAppPublishingProfile -ResourceGroupName $resourceGroupName `
-Name $appsvWebAppName `
-OutputFile $publishProfileFileName
Publish-AzWebApp -ArchivePath $uiZipPath `
-ResourceGroupName $resourceGroupName `
-Name $appsvWebAppName
我看不到如何将Publish-AzWebApp指向虚拟目录。
发布可以手动完成,但我真的想自动化它(使用 Publish-AzWebApp 或其他方式)。
请问我该怎么做?
解决方案
Publish-AzWebApp
不支持,您可以在 powershell 中使用它Kudu API
来自动化它。
$appsvWebAppName = "xxxxxxx"
$resourceGroupName = "xxxxxxx"
$resource = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName "$appsvWebAppName/publishingcredentials" -Action list -ApiVersion 2018-02-01 -Force
$username = $resource.Properties.publishingUserName
$password = $resource.Properties.publishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"
# Create the folder, not lose `/` after `ui`
$apiUrl = "https://$appsvWebAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/ui/"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT
#Upload the zip file
$apiUrl = "https://$appsvWebAppName.scm.azurewebsites.net/api/zip/site/wwwroot/ui"
$filePath = "C:\Users\joyw\Desktop\testdep.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"
对于site\wwwroot\api
, 也是一样的逻辑,只是在脚本里ui
改成。api
推荐阅读
- asp.net - 限制 ASP.NET Core 控制器操作中接受的媒体类型
- ios - 如何在 didFinishLaunchingWithOptions AppDelegate 中使用框架函数?
- php - 实现 AJAX 搜索表后,重写 jQuery 脚本以使用动态链接链接表行
- python - 如何使用 Putty 在 Python 中设置 Cron 作业(操作系统为 Linaro)
- typescript - 设置 TypeScript 编译器的基本/工作目录
- java - 在 HQL 中查找日期之间的实体
- angular - 在 AngularFirestoreCollection 中转换 CollectionReference
还是可观察的? - python - Python - 将 For Loop 编写为文件作为生成器而不是 str/dict
- vba - 将全名从批处理文件传递到 vbs 文件,然后用它运行一个 word 宏
- python-3.x - QtDesigner5.11.0、python3.5和pyside2之间的兼容性问题?