部署到Azure Function App插槽导致代码也部署到生产中

时间:2020-06-16 15:22:44

标签: azure-functions

在将功能部署到Function App插槽(称为“暂存”)时,我注意到实际上生产和暂存插槽都开始使用新代码。

我的一个功能/health返回标记在* .dll文件上的程序包版本,并在部署后检查生产和暂存上的运行状况终结点,以表明它们是相同的。

documentation中,我看不到任何有关此行为的提及,也没有提到必须采取行动避免这种行为。

其他人有没有经历过这种行为?有没有办法以这种方式进行插槽交换行为?


通过使用此脚本将zip文件部署到暂存插槽中,可以观察到此行为。您显然需要安装az CLI,并设置相关的上下文。

$resournceGroupName = ""
$functionAppName = ""

### Get the locaion of the zip file containing the code to deploy.
$inFile = "{0}\{1}" -f (Get-Location).Path, "FunctionApp.zip"

### Get the Kudu username and password.
$kuduUser = az webapp deployment list-publishing-profiles --resource-group $resournceGroupName --name $functionAppName --slot Staging --query "[?publishMethod=='MSDeploy'].userName" -o tsv
$kuduPass = az webapp deployment list-publishing-profiles --resource-group $resournceGroupName --name $functionAppName --slot Staging --query "[?publishMethod=='MSDeploy'].userPWD" -o tsv

### Encode the basic authentication credentials.
$creds = "{0}:{1}" -f $kuduUser, $kuduPass
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($creds))

### Generate the URI and headers to use for the request.
$uri = "https://{0}-staging.scm.azurewebsites.net/api/zipdeploy?deployer=VSTS&message=%7B%22type%22%3A%22deployment%22%7D" -f $functionAppName
$headers = @{
    Authorization = "Basic {0}" -f $encodedCreds
    "Content-Disposition" = "attachment; filename=run.cmd"
}

### Deploy the functions.
$response = Invoke-WebRequest -Method Put -Uri $uri -Headers $headers -InFile $inFile -ContentType "application/zip"
$response | ConvertTo-Json -Depth 10

0 个答案:

没有答案