【发布时间】:2020-07-07 04:07:55
【问题描述】:
- 我正在使用 Python 使用 Google Cloud Function。其他几个功能正在生产中。
- 但是,为此,我另外创建了一个自定义 Python 包,该包在 github 上作为 private 存储库提供。
- 我需要在 Google Function 中安装包
我做了什么
- 我使用
functions-framework在本地运行 Google 函数 - 我有一个 requirements.txt,其中有一个包的链接。这是通过将以下行添加到
requirements.txt来完成的:
-e git+https://github.com/<repo>/<project>#egg=<project>
- 我运行
pip install -r requirements.txt。并且包安装成功。 - 现在在函数的 python 代码中使用
import <pkg-name>可以正常工作,我可以访问所有函数。
将功能推送到云端时的挑战
- 根据文档,要将 Cloud 功能推送到 Google Cloud,我发出以下命令:
gcloud functions \
deploy <function-name> \
--trigger-http \
--entry-point <entry-function> \
--runtime python37 \
--project=<my-project>
正如预期的那样,这会产生错误,因为它无法访问 git 中的私有仓库。
我创建了一个谷歌云存储库并将其链接到 git 存储库,希望以某种方式我可以在 requirements.txt 中指定它。就是不知道怎么弄。
我尝试在 Google Cloud Function 中为用户名和密码设置环境变量(这不是一个好主意,我同意),并在
requirements.txt中将它们指定为:
-e git+https://${AUTH_USER}:${AUTH_PASSWORD}@github.com/<repo>/<project>#egg=<project>
这也报错了。
任何帮助或指导将不胜感激。
【问题讨论】:
标签: python pip google-cloud-functions