【问题标题】:GCloud Error: Source code size exceeds the limitGCloud 错误:源代码大小超出限制
【发布时间】:2017-12-19 17:59:40
【问题描述】:

我正在做 api.ai tutorial 的基本实现和对话设置教程来制作聊天机器人,当我尝试使用命令部署该功能时:

gcloud beta functions deploy --stage-bucket venky-bb7c4.appspot.com --trigger-http

(其中 'venky-bb7c4.appspot.com' 是存储桶名称) 它返回以下错误消息:

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Source code size exceeds the limit

我已经搜索但没有找到任何答案,我不知道错误在哪里。 这是教程中出现的JS文件:

    /
 HTTP Cloud Function.

 @param {Object} req Cloud Function request context.
 @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
  response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working


res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
  res.send(JSON.stringify({ "speech": response, "displayText": response 
  //"speech" is the spoken version of the response, "displayText" is the visual version
  }));
};

【问题讨论】:

  • 你找到解决办法了吗?

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


【解决方案1】:

我在部署云功能时遇到了类似的问题。对我有用的是指定 js 文件源文件夹。

gcloud functions deploy functionName --trigger-http **--source path_to_project_root_folder**

还要确保在 .gcloudignore 中包含所有不必要的文件夹。

【讨论】:

    【解决方案2】:

    我尝试使用源选项或从 index.js 文件夹进行部署,但仍然存在不同的问题。

    如果上传的代码很大,通常会发生此错误。在我的测试中,我发现超过 100MB 会导致上述错误。

    然而, 要解决此问题,有两种解决方案。

    1. 更新 .gcloudignore 以忽略您的函数不需要的文件夹
    2. 如果选项 1 仍然无法解决,您需要在存储中创建一个存储桶并使用 --stage-bucket 选项提及它。

    创建一个用于部署的新存储桶(一次性)

    gsutil mb my-cloud-functions-deployment-bucket
    
    

    您创建的存储桶必须是唯一的,否则它会抛出已创建的存储桶

    部署

    gcloud 函数部署订阅者-firestoreDatabaseChange
    --trigger-topic firestore-database-change
    --region us-central1
    --runtime nodejs10
    --update-env-vars "REDIS_HOST=10.128.0.2"
    --stage-bucket my-cloud-functions-deployment-bucket

    【讨论】:

      【解决方案3】:

      这些都不适合我。我能够解决这个问题的方法是确保我从我的项目目录(包含 index.js 的目录)运行部署

      【讨论】:

        【解决方案4】:

        确保包文件夹有一个 .gitignore 文件(不包括 node_modules)。

        最新版本的 gcloud 需要它才能不加载 node_modules。我的代码大小从 119MB 变为 17Kb。

        添加 .gitignore 文件后,日志也会打印出来

        created .gcloudignore file. See `gcloud topic gcloudignore` for details.
        

        【讨论】:

          【解决方案5】:

          该命令使用当前目录(node_modules 子目录除外)的全部内容创建 zip,而不仅仅是 JS 文件(这是因为您的函数可能会使用其他资源)。

          您看到的错误是因为目录中(未压缩)文件的大小大于 512MB。

          解决此问题的最简单方法是将 .js 文件移动到其自己的目录并从那里进行部署(如果您希望工作目录与目录不同,可以使用 --local-path 指向包含源文件的目录带函数源)。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-01-08
            • 2023-01-23
            • 1970-01-01
            • 1970-01-01
            • 2021-08-21
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多