当有多个函数时,是否可以在 Azure 函数应用程序中只部署一个函数?
Is it possible to deploy just one function in an Azure function app when there are multiple functions?
我正在为正在创建的新 Azure 函数设置部署管道。由于我们已经在工作中使用 TeamCity 和 Octopus deploy 进行部署,我正在考虑使用 KUDU REST API 详细部署 Azure 功能 here 其中 Powershell 命令来自 运行章鱼部署。
由于 Azure 函数驻留在 Azure 函数应用程序中,并且一个应用程序可以有多个函数,是否可以一次只在应用程序中部署一个函数?
是的,当然可以。几乎每个功能应用程序都以 1 个功能开始...
我认为@Mikhail 的回答更多是关于 "is it possible to have a function app with only one function?",而问题可能更多是 "is it possible to individually deploy a function even if there are already others?"。
答案是,如果您使用 Kudu zip 控制器,这是可能的,因为您可以将它瞄准任何您想要的文件夹。因此,如果您部署到 /api/zip/site/wwwroot/MyFunc1/
,您只会影响那个功能。
需要注意的一件事:zip 控制器不会传播删除内容。因此,如果您发布一个带有功能的文件,然后发布一个没有它的新 zip 以实现相同的功能,该文件将保留。可以使用 msdeploy,因为它支持此功能。
既然您说您使用的是Octopus Deploy,那么您可以使用Deploy web 模板步骤来部署单个函数。
只需在要求自定义文件夹路径的字段中提供函数名称。
对于任何想要使用调用 KUDU
API 并由 Octopus deploy
执行的 powershell
脚本执行此操作的人,您可以按照我的回答中的步骤操作 (你也可以参考其他关于这个问题的答案以获得一些有趣的方法)
这是仅将一个函数部署到函数应用程序的相关部分。
按照说明获取您的发布配置文件用户名和密码here
$creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
调用 Kudu REST API 将您的函数推送到函数 app
$username = '<publish username>' #IMPORTANT: use single quotes as username may contain $
$password = "<publish password>"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiUrl = "https://<yourFunctionApp>.scm.azurewebsites.net/api/zip/site/wwwroot"
$filePath = "<yourFunctionName>.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method PUT -InFile $filePath -ContentType "multipart/form-data"
我正在为正在创建的新 Azure 函数设置部署管道。由于我们已经在工作中使用 TeamCity 和 Octopus deploy 进行部署,我正在考虑使用 KUDU REST API 详细部署 Azure 功能 here 其中 Powershell 命令来自 运行章鱼部署。
由于 Azure 函数驻留在 Azure 函数应用程序中,并且一个应用程序可以有多个函数,是否可以一次只在应用程序中部署一个函数?
是的,当然可以。几乎每个功能应用程序都以 1 个功能开始...
我认为@Mikhail 的回答更多是关于 "is it possible to have a function app with only one function?",而问题可能更多是 "is it possible to individually deploy a function even if there are already others?"。
答案是,如果您使用 Kudu zip 控制器,这是可能的,因为您可以将它瞄准任何您想要的文件夹。因此,如果您部署到 /api/zip/site/wwwroot/MyFunc1/
,您只会影响那个功能。
需要注意的一件事:zip 控制器不会传播删除内容。因此,如果您发布一个带有功能的文件,然后发布一个没有它的新 zip 以实现相同的功能,该文件将保留。可以使用 msdeploy,因为它支持此功能。
既然您说您使用的是Octopus Deploy,那么您可以使用Deploy web 模板步骤来部署单个函数。 只需在要求自定义文件夹路径的字段中提供函数名称。
对于任何想要使用调用 KUDU
API 并由 Octopus deploy
执行的 powershell
脚本执行此操作的人,您可以按照我的回答中的步骤操作
这是仅将一个函数部署到函数应用程序的相关部分。
按照说明获取您的发布配置文件用户名和密码here
$creds = Invoke-AzureRmResourceAction -ResourceGroupName YourResourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName YourWebApp/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
调用 Kudu REST API 将您的函数推送到函数 app
$username = '<publish username>' #IMPORTANT: use single quotes as username may contain $
$password = "<publish password>"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiUrl = "https://<yourFunctionApp>.scm.azurewebsites.net/api/zip/site/wwwroot"
$filePath = "<yourFunctionName>.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method PUT -InFile $filePath -ContentType "multipart/form-data"