Azure函数:对于远程构建和从包运行的困惑

huangapple go评论79阅读模式
英文:

Azure function: confusion about remote build and run from package

问题

阅读Azure函数文档时遇到了一些困惑,需要澄清一下:

在远程构建中,文档中提到:

当应用在Linux上进行远程构建时,它们会从部署包中运行。

要使函数能够从包中运行:

要使函数应用能够从包中运行,请将WEBSITE_RUN_FROM_PACKAGE设置添加到函数应用设置中。WEBSITE_RUN_FROM_PACKAGE设置可以有以下值之一:

推荐使用1(适用于高级计划)。

而在一般考虑事项中,最后一条说:

如果您的项目需要使用远程构建,请不要使用WEBSITE_RUN_FROM_PACKAGE应用设置。而是添加SCM_DO_BUILD_DURING_DEPLOYMENT=true部署自定义应用设置。对于Linux,还要添加ENABLE_ORYX_BUILD=true设置。

这里似乎有矛盾之处:

  1. 在Linux上进行远程构建时,它们会从部署包中运行。
  2. 要使其能够从包中运行,我们需要WEBSITE_RUN_FROM_PACKAGE=1
  3. 但是,如果您的项目需要使用远程构建,请不要使用WEBSITE_RUN_FROM_PACKAGE应用设置。

我可能对概念有误解。能否有人提供一些澄清?

为了搞清楚这些问题,我想澄清几个问题:

  1. 当Azure进行远程构建时,构建过程的结果文件是什么?文件的格式是什么?这个文件具体存储在哪里?
英文:

Reading through the documents of Azure function:

Deployment options

Run from package file

I have some confusions that need to be clarified:

In Remote build, it says:

> When apps are built remotely on Linux, they run from the deployment package.

To Enable functions to run from a package:

> To enable your function app to run from a package, add a
> WEBSITE_RUN_FROM_PACKAGE setting to your function app settings. The
> WEBSITE_RUN_FROM_PACKAGE setting can have one of the following values:
>
> and 1 is recommended for premium plan

And in general considerations, it says in the last bullet point:

> If your project needs to use remote build, don't use the
> WEBSITE_RUN_FROM_PACKAGE app setting. Instead add the
> SCM_DO_BUILD_DURING_DEPLOYMENT=true deployment customization app
> setting. For Linux, also add the ENABLE_ORYX_BUILD=true setting.

Isn't there a contradiction?

  1. In Linux, when remote build, they run from deployment package.

  2. To enable to run from package, we need WEBSITE_RUN_FROM_PACKAGE=1

  3. But, If your project needs to use remote build, don't use the WEBSITE_RUN_FROM_PACKAGE app setting.

I must have got my concepts wrong. Could someone offer some clarification?

To sort things out, I want to clarify a few questions:

  1. When Azure performs remote build, what is the resultant file of the build process? What is the format of the file? Where exactly is this file stored?

答案1

得分: 1

远程构建在进行zip部署时指的是在远程构建服务器上构建函数应用的代码。

这在以下情况下使用:如果您的函数应用中有任何需要编译或需要在部署之前执行其他构建步骤的依赖项。

使用SCM_DO_BUILD_DURING_DEPLOYMENT=trueENABLE_ORYX_BUILD=true的远程构建:

Azure函数:对于远程构建和从包运行的困惑

  1. 当您将函数部署到Azure时,它会使用远程构建服务器来构建您的函数应用,该服务器配备了所需的构建工具、运行时环境和依赖项,以正确编译和打包您的代码。

  2. 远程构建服务器通过安装所需的依赖项和软件包将代码编译为部署包,并将该包部署到Azure函数应用的运行时环境中。

  3. 当调用您的函数应用时,它直接从在远程服务器上构建的部署包中运行,其中包含所有依赖项和编译代码,以正确执行函数。

由于应用是在远程构建并作为一个包部署的,因此不需要手动添加WEBSITE_RUN_FROM_PACKAGE设置。

Azure函数:对于远程构建和从包运行的困惑

WEBSITE_RUN_FROM_PACKAGE(无远程构建):

从包中运行是指函数应用在运行时使用部署包的内容,无论是在远程构建还是zip部署场景中,都是如此。然而,创建和管理部署包的方式在远程构建和zip部署场景中有所不同。

Azure函数:对于远程构建和从包运行的困惑

Azure函数:对于远程构建和从包运行的困惑

  1. 在使用zip部署部署函数时,函数应用的源代码、依赖项和所有所需文件将被打包成一个zip文件。然后,将该zip文件上传到Azure中的函数目标环境。之后,Azure将内容部署到函数应用的运行时环境中。

  2. 通常,Azure Functions会尝试直接从源代码位置(site/wwwroot)运行。

  3. 在函数应用=>设置=>配置中设置WEBSITE_RUN_FROM_PACKAGE=1,让Azure从通过zip部署上传的部署包中运行应用,而不是从源代码运行。

>1. 当Azure执行远程构建时,构建过程的结果文件是什么?文件的格式是什么?这个文件存储在哪里?

检查远程构建后函数应用的文件:

  • 进入函数应用的KUDU站点,调试控制台=>Bash
  • 导航到路径data\SitePackages,如下所示:
  • 与packagename.txt一起,将可用的与函数相关的zip文件。

Azure函数:对于远程构建和从包运行的困惑

检查函数应用的文件(无远程构建/zip部署):

Azure函数:对于远程构建和从包运行的困惑

英文:

Remote build while doing the zip deployment refers to building the function app's code on a remote build server.

This is used in case if you any dependencies in your function app which needs to be compiled or requires additional build steps before getting deployed.

Remote build with SCM_DO_BUILD_DURING_DEPLOYMENT=true and ENABLE_ORYX_BUILD=true:

Azure函数:对于远程构建和从包运行的困惑

  1. When you deploy your function to Azure, it uses a remote build server to build your function app which is equipped with the required build tools, runtime environments, and dependencies to compile and package your code correctly.

  2. The remote build server compiles the code by installing required dependencies and packages into a deployment package and deploy the package to your Azure Function App runtime environment.

  3. When your function app is invoked, it runs directly from the deployment package that was built on the remote server with all the dependencies and compiled code to execute the function properly.

As the app is built remotely and deployed as a package, it already runs from the deployment package. So, adding the setting WEBSITE_RUN_FROM_PACKAGE manually isn't required.

Azure函数:对于远程构建和从包运行的困惑

WEBSITE_RUN_FROM_PACKAGE(without remote build):

Running from a package refers to the function app's use of the deployment package's contents during runtime in both cases. However, the way the deployment package is created and managed differs between remote build and zip deployment scenarios.

Azure函数:对于远程构建和从包运行的困惑

Azure函数:对于远程构建和从包运行的困惑

  1. While deploying the function using zip deployment, the function app's source code, dependencies, and al the required files will be packaged into a zip file. Then, the zip file is uploaded to the Function's target environment in Azure. After that, Azure deploys the contents to your function app's runtime environment.

  2. Generally, Azure Functions tries to run directly from the source code location(site/wwwroot).

  3. The setting WEBSITE_RUN_FROM_PACKAGE=1 in function app=>settings=>configuration lets Azure to run the app from the uploaded deployment package which was uploaded through zip deployment instead of source code.

>1. When Azure performs remote build, what is the resultant file of the build process? What is the format of the file? Where exactly is this file stored?

To check the files of your function app after remote build:

  • Go to KUDU site of your function app, Debug Console=>Bash
  • Navigate to the path data\SitePackages as shown below:
  • The function related zip files will be available along with the packagename.txt.

Azure函数:对于远程构建和从包运行的困惑

To check the files of your function app(without remote build/ Zip deployment):

Azure函数:对于远程构建和从包运行的困惑

huangapple
  • 本文由 发表于 2023年8月9日 14:29:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865114.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定