【问题标题】:Azure Function - App service plan - Installing git packageAzure Function - 应用服务计划 - 安装 git 包
【发布时间】:2020-04-03 18:09:25
【问题描述】:

我已经编写了一个 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。一般来说,如果我们需要安装任何额外的包供函数应用使用,如何在azure函数中完成。

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

【问题讨论】:

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


    【解决方案1】:

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

    另一种方法是将git 可执行文件作为function package 的一部分提供,并将GIT_PYTHON_GIT_EXECUTABLE 应用设置设置为%HOME%\site\wwwroot\&lt;path-to-git-in-your-package&gt;(Windows)或$HOME/site/wwwroot/&lt;path-to-git-in-your-package&gt;(Linux)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      相关资源
      最近更新 更多