【问题标题】:Google Cloud Functions: missing main.py谷歌云函数:缺少 main.py
【发布时间】:2021-05-06 16:21:21
【问题描述】:

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

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

我明白了

部署功能(可能需要一段时间 - 最多 2 分钟)...⠛
如需 Cloud Build Stackdriver 日志,请访问: https://[...] 部署功能(可能需要一段时间 - 最多 2 分钟)...失败。
错误:(gcloud.functions.deploy)操作错误:代码=3,消息=构建 失败:缺少 main.py 和 GOOGLE_FUNCTION_SOURCE 未指定。 在 main.py 中创建函数或指定 GOOGLE_FUNCTION_SOURCE 指向包含 功能;错误 ID:5c04ec9c

但我的文件夹中有一个main.py 文件。

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

【问题讨论】:

    标签: google-cloud-platform google-cloud-storage


    【解决方案1】:

    解决方案是从.gcloudignore 中省略这一行:

    #!include:.gitignore
    

    我真的不明白为什么。

    我的.gitignore 是:

    .*
    *.json
    

    【讨论】:

    • 对于以相同错误结束的其他人:这里的违规行似乎是.gcloudignore 中的.*。我的意图是忽略所有点文件,但实际上它(也)忽略了当前目录中的所有文件。因此main.py 被忽略。奇怪的是 gcloud meta list-files-for-upload 正确报告 main.py 包含在上传中,但它没有显示在云构建日志中,即不是上传到 Google Cloud Build 的源存档的一部分。
    • 我在尝试使用.* 排除点文件时遇到了同样的问题。问题似乎是gcloud functions deploy 在内部将./ 添加到路径,然后.* 匹配前导. 部分(详细程度设置为调试它报告Skipping file [./main.py])。我的解决方法是改用 .?* 模式。
    【解决方案2】:

    .gcloudignore 的内容对我很有帮助。我从其他已经有这个自动生成文件的项目中复制了它。

    文件名:.gcloudignore

    # This file specifies files that are *not* uploaded to Google Cloud Platform
    # using gcloud. It follows the same syntax as .gitignore, with the addition of
    # "#!include" directives (which insert the entries of the given .gitignore-style
    # file at that point).
    #
    # For more information, run:
    #   $ gcloud topic gcloudignore
    #
    .gcloudignore
    # If you would like to upload your .git directory, .gitignore file or files
    # from your .gitignore file, remove the corresponding line
    # below:
    .git
    .gitignore
    node_modules
    

    【讨论】:

      猜你喜欢
      • 2014-02-11
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 2019-02-15
      • 2018-12-07
      • 2018-10-02
      • 2021-01-22
      相关资源
      最近更新 更多