linux - 无法使用 CLI 将 Azure Function 发布到 Linux

标签 linux azure visual-studio azure-functions

我目前正在 BitBucket 中创建一个构建管道,以摆脱我们当前的“右键单击 -> 发布”策略。我已经迁移了一些托管在 Windows 上的功能,没有问题。我们在 Linux 应用服务计划上有一个功能,不幸的是在发布后它无法从包中运行。

# Publish to a folder
dotnet publish "azure/$FUNCTION_NAME/$FUNCTION_NAME.csproj" -c Release -o publish/$FUNCTION_NAME

# Create a zip file
md artifacts
powershell Compress-Archive publish/$FUNCTION_NAME/** artifacts/$FUNCTION_NAME.zip

# Deploy the zip file to Azure
az functionapp deploy -g $AZURE_RESOURCE_GROUP -n $AZURE_RESOURCE_NAME --src-path artifacts/$FUNCTION_NAME.zip

这几乎与 Azure Functions 文档页面上列出的步骤完全相同。发布到 Linux 时,没有错误,它只是什么也不做。在Azure门户中,应用程序中的所有函数仍然列出,并且host.json和function.json文件似乎可以被识别,但我无法再测试/运行该函数。对 HTTP 端点的每个请求都会返回 404 状态。

我尝试查看日志,没有用户界面我有点迷失,但我确实找到了这些消息:

/home/LogFiles/kudu/deployment/5fd0c28b328b-ec52daf9-7903-466a-bfe1-5c1c658ab72b.txt

::::::::::::::
5fd0c28b328b-ec52daf9-7903-466a-bfe1-5c1c658ab72b.txt
::::::::::::::
2022-05-02T01:41:14  Fetching changes.
2022-05-02T01:41:30  Updating submodules.
2022-05-02T01:41:31  Preparing deployment for commit id '35555aaa-2'.
2022-05-02T01:41:32  Skipping build. Project type: Run-From-Zip
2022-05-02T01:41:32  Skipping post build. Project type: Run-From-Zip
2022-05-02T01:41:32  Requesting site restart
2022-05-02T01:41:33  Requesting site restart. Attempt #1
2022-05-02T01:41:33  Successfully requested a restart. Attempt #1
2022-05-02T01:41:34  Updating /home/data/SitePackages/packagename.txt with deployment 20220502014112.zip
2022-05-02T01:41:35  Deployment successful.
2022-05-02T01:41:38  An unknown error has occurred. Check the diagnostic log for details.

2022-05-02T02-02-31Z-ff1a2fe5e9.log

2022-05-02T02:02:31.309 [Warning] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

从 Visual Studio 中重新发布可以解决该问题,因此这绝对是我发布方式的问题。 Visual Studio 中的发布配置文件具有 <IsLinux>true</IsLinux>属性,我怀疑这也是我需要以某种方式为 Azure CLI 指定的属性。

最佳答案

我推断肯定有两种可能性:

  • 我上传 zip 文件的方法与 Visual Studio 使用的方法不同
  • 我创建的 zip 文件与 Visual Studio 生成的文件不同

我查看了 MSBuild tasks in the SDK以查看单击“发布”时 Visual Studio 执行的操作。由此,我发现zip文件是由Visual Studio在 obj/Release/net6.0/PubTmp 中生成的。文件夹。它将 zip 文件发布到 https://{FUNCTION}.scm.azurewebsites.net/api/zipdeploy部署时。我用 PostMan 手动测试了这一点,得到了以下结果:

<表类=“s-表”> <标题> 部署方法 来源 结果 <正文> POST /api/zipdeploy obj/Release/net6.0/PubTmp 成功 POST /api/zipdeploy dotnet publish + powershell Compress-Archive 失败 az functionapp deploy obj/Release/net6.0/PubTmp 成功 az functionapp deploy dotnet publish + powershell Compress-Archive 失败

该表显示,仅当我使用从命令行生成的 zip 时,部署才会失败。我用 WinMerge 比较了两者,但它说它们是相同的,所以我不知道发生了什么。显然,两个 zip 文件之间一定存在一些差异,否则它们都可以正常部署。

我决定尝试将其报告为错误,因此我尝试在新的空项目中重新创建该问题,并且立即遇到了多个其他不相关的问题:

  • 在 Azure 门户中,当我创建新的 Function App 时,它不允许我重新使用现有的 Linux 应用服务计划。我必须通过 Visual Studio 创建它
  • 发布新项目后,唯一的功能是项目模板中的默认 HTTP 触发器,部署失败
  • 连续发布失败,因为部署仍处于锁定状态
  • 在 Kudu 中浏览文件的端点抛出异常,堆栈跟踪提到尝试使用 Windows 路径

我花了很多时间对此进行调查,并得出结论,目前还不值得尝试在 Linux 上托管。这令人失望,我希望他们能够解决这些问题。

关于linux - 无法使用 CLI 将 Azure Function 发布到 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72091678/

相关文章:

linux - 命令完成后继续执行linux shell脚本

linux - grepping 数据 Apache access.log

c++ - 内存访问回调?

c# - 尝试从 Visual Studio 2017 本地运行 Azure Function App 会出现 'func.exe does not exist' 错误

c++ - "Unresolved external symbol"用于在 header 中内联声明的模板化函数

c# - 运行时调试不起作用。

linux - 在树莓派上安装 Lazarus

azure - 为 Azure 中的服务器网络创建开发和生产环境的正确方法是什么?

azure - SAS for CloudBlob容器内的目录或路径

C++ std::库之间的异常