azure-functions - Azure 函数 - 应用服务计划 - 安装 git 包

标签 azure-functions azure-app-service-plans gitpython azure-function-app

我已经编写了一个 Azure Funciton API(使用 python 运行时)来自动化我们正在做的一些工作的 git checkin 过程(使用 gitPython)。它在我的本地环境中运行良好。但是,当我尝试将其发布到 azure 函数时,API 失败了。

 ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet

Stack:   File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
    mod = importlib.import_module(fullmodname)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/site/wwwroot/tableauwkbcheckin/__init__.py", line 7, in <module>
    import git
  File "/home/site/wwwroot/.python_packages/lib/site-packages/git/__init__.py", line 85, in <module>
    raise ImportError('Failed to initialize: {0}'.format(exc))

原因是 GitPython 依赖于导入 azure 函数的系统上的“git”可执行文件。

我的问题是:如何使用应用服务计划在 Azure 功能上安装 git。一般情况下,如果我们需要额外的包来安装和使用function app,如何在azure function中实现。

作为解决方法,我在导入 git 之前使用 os.system() 安装 git 二进制文件。

最佳答案

我相信这是使用 custom containers with functions 的好案例.由于您将构建容器,因此可以确保安装所有外部依赖项。

另一种方法是运送 git可执行文件作为 function package 的一部分并设置 GIT_PYTHON_GIT_EXECUTABLE应用程序设置为 %HOME%\site\wwwroot\<path-to-git-in-your-package> ( window )或 $HOME/site/wwwroot/<path-to-git-in-your-package> (Linux)

关于azure-functions - Azure 函数 - 应用服务计划 - 安装 git 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61017950/

相关文章:

azure - ActivityTrigger持久功能: max execution time limit via Azure Function App and Consumption plan

c# - Azure Functions - Host.json 不适用于 Azure 应用程序设置

azure - 无法删除 Azure 应用服务计划

azure - 如何按计划扩大或缩小 Azure 应用服务实例大小?

python - 如何使用python从git存储库下载单个文件

python - 使用 gitpython 获取 commit 的简短 sha

azure - 我应该如何将后端解决方案链接到 IoT 中心

powershell - Azure 函数中的 PNP PowerShell 在某个时间间隔内快速触发时失败

azure - 来自 Azure Web App 的一个实例的 HTTP 502

python - 如何使用 GitPython 获取提交中文件的源代码?