我已经编写了一个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”可执行文件。
我的问题是:如何使用App服务计划在Azure函数上安装git。通常,如果我们需要功能应用程序安装和使用任何其他软件包,那么如何在azure函数中进行安装。
作为一种解决方法,我在导入git之前使用os.system()安装git二进制文件。
答案 0 :(得分:0)
我认为这是使用custom containers with functions的一个很好的例子。由于将要构建容器,因此可以确保安装所有外部依赖项。
另一种选择是将git
可执行文件作为function package的一部分发布,并将GIT_PYTHON_GIT_EXECUTABLE
应用设置设置为%HOME%\site\wwwroot\<path-to-git-in-your-package>
(Windows)或$HOME/site/wwwroot/<path-to-git-in-your-package>
(Linux)