当 main.py 和 requirements.txt 不在同一目录中时如何部署 google 云函数

How to deploy google cloud function when main.py and requirements.txt aren't in the same directory

我的目录结构如下所示:

src/
    main.py
requirements.txt

由于周围好像没有any configurabilityrequirements.txt,所以我只好在外层目录运行宁gcloud functions deploy,我希望 --entry-point 标志可以给我一些回旋余地,让我可以在 src 内瞄准 main.py。不幸的是,它似乎只定义了一个方法名。

那么除了强制 main.pyrequirements.txt 位于同一目录之外,还有什么方法可以使这项工作正常进行吗?

供参考,我正在尝试的命令 运行 和相应的错误消息:

gcloud functions deploy refresh_classes --entry-point main --runtime python37 --trigger-resource send_refresh --trigger-event google.pubsub.topic.publish --timeout 540s

Deploying function (may take a while - up to 2 minutes)...failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: File main.py that is expected to define function doesn't exist

我怀疑这种约定出现在 Cloud Functions 中,因为在其他语言(例如 Golang,Java)中,源目录(按照惯例)不仅足以描述源代码,而且足以描述项目的描述符( go.modpom.xml 等)定义了外部包。在 Python 中,这些可能会断开连接。

您是否尝试过创建一个从 ./requirements.txt./src/requirements.txt 的 link?这可能行不通,因为 link 的源在“源”的上下文之外,但它可能会起作用。

否则,你可能会倒霉。

单独配置 gcloud 或没有其他源文件是不可能的。 Cloud Functions 需要一个 source 目录,其中包含 requirements.txtmain.py.