Google Cloud Functions:缺少 main.py

Rap*_*ael 5 google-cloud-storage google-cloud-platform

尝试使用以下命令将 Python 项目部署到 Google Cloud 函数时

\n

gcloud functions deploy my_function --entry-point reply --runtime python38 --trigger-http --allow-unauthenticated

\n

我明白了

\n
\n

正在部署函数(可能需要一段时间 - 最多 2 分钟)...\xe2\xa0\x9b
\n有关 Cloud Build Stackdriver 日志,请访问:\nhttps://[...]\n正在部署函数(可能需要一段时间 -最多 2 分钟)...失败。
\n错误:(gcloud.functions.deploy) 操作错误:代码 = 3,消息 = 构建\n失败:缺少 main.py 且未指定 GOOGLE_FUNCTION_SOURCE。\n请在 main.py 中创建该函数,或指定\nGOOGLE_FUNCTION_SOURCE 指向该文件包含\n函数;错误 ID:5c04ec9c

\n
\n

main.py但我的文件夹里确实有一个文件。

\n

我检查了平台,文件main.py没有上传,而文件夹内的文件正在上传。

\n

Rap*_*ael 3

解决方案是从以下位置省略这一行.gcloudignore

#!include:.gitignore
Run Code Online (Sandbox Code Playgroud)

我真的不明白为什么。

我的.gitignore是:

.*
*.json
Run Code Online (Sandbox Code Playgroud)

  • 对于其他以相同错误结束的人:这里有问题的行似乎是“.gcloudignore”中的“.*”。我的意图是忽略所有点文件,但实际上它(也)忽略当前目录中的所有文件。因此“main.py”被忽略。奇怪的是,“gcloud meta list-files-for-upload”正确报告“main.py”包含在上传中,但它没有显示在云构建日志中,即不是上传到的源存档的一部分谷歌云构建。 (2认同)