Azure App Service 部署任务选项,用于在部署时删除容器中的文件 [英] Azure App Service deploy task option to remove files in container upon deployment

查看:18
本文介绍了Azure App Service 部署任务选项,用于在部署时删除容器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Linux 服务上的 Web 应用程序并使用 DevOps 发布管道部署一个 Python Web 应用程序.我正在使用的管道任务称为 AzureRmWebAppDeployment@4.

I am deploying a python web app using Web App on Linux service and using a DevOps release pipeline. The pipeline task that I am using is called AzureRmWebAppDeployment@4.

在部署之间,容器中的文件没有被删除,这会导致问题.

Between deployments, the files in the container are not being removed and this is causing issues.

我注意到如果我使用的是不同类型的应用程序服务(即 Windows 上的 Web 应用程序),并且如果部署方法设置为 Web 部署Remove additional files at destination 的选项 存在(见截图).但是,我们使用的是 Zip Deploy 方法,并且更喜欢使用 linux 服务.如果没有应用服务和部署方法的组合,我无法使用此选项.

I noticed if I am using a different type of app service (i.e. Web App on Windows) and if the deployment method is set to Web Deploy the option for Remove additional files at destination exists (see screenshot). However we are using a Zip Deploy method and prefer to be using a linux service. without that combination of app service and deployment method, this option is not available to me.

有人可以建议在部署时删除容器内容的替代方法吗?此外,关于为什么在使用 Zip Deploy 和 Linux 时无法通过管道任务使用此选项的任何见解?

Can anybody suggest an alternate method for deleting the container contents upon deployment? Also, any insight as to why this option is not available through the pipeline task when using Zip Deploy and Linux?

提前感谢您提供的任何帮助.

Thanks in advance for any help provided.

推荐答案

你可以使用 kudu command api 清理 webapp 服务器上的 wwwroot 文件夹.kudu命令rest api会执行服务器上指定目录下的command.

You can use kudu command api to clean the wwwroot folder on your webapp server. The kudu command rest api will execute the command in the specified directory on the server.

{
    command = "find . -mindepth 1 -delete"  
    dir = "/home/site/wwwroot
} 

<小时>

在 Azure 应用服务部署任务之前添加一个 Azure powershell 任务,并在下面运行内联脚本.


Add an Azure powershell task before Azure app service deploy task, and run below inline scripts.

$ResGroupName = ""
$WebAppName = ""

# Get publishing profile for web application
$WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp

# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$bodyToPOST = @{  
                  command = "find . -mindepth 1 -delete"  
                  dir = "/home/site/wwwroot"  
}  
# Splat all parameters together in $param  
$param = @{  
            # command REST API url  
            Uri = "https://$WebAppName.scm.azurewebsites.net/api/command"  
            Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}  
            Method = "POST"  
            Body = (ConvertTo-Json $bodyToPOST)  
            ContentType = "application/json"  
}  
# Invoke REST call  
Invoke-RestMethod @param  

上述脚本将在每次部署之前清空文件夹/home/site/wwwroot.

Above scripts will empty the folder /home/site/wwwroot before each deployment.

如果需要删除应用服务器上的特定文件,可以使用kudu delete rest api:

If you need to delete specific files on the app server, you can use kudu delete rest api:

DELETE /api/vfs/{path}
Delete the file at path.

有关更多示例,您可以查看 这里.

For more examples you can check here.

这篇关于Azure App Service 部署任务选项,用于在部署时删除容器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆