Firebase Cloud Functions V2 – 部署时出错

huangapple go评论67阅读模式
英文:

Firebase Cloud Functions V2 - Error when deploying

问题

以下是您提供的内容的中文翻译:

按照文档进行了必要的设置,但每次尝试部署函数时,调试错误显示:

无法创建触发器 projects/***********/locations/us-central1/triggers/******-967155:
"Permission denied while using the Eventarc Service Agent",对于资源状态无效。如果您最近开始使用Eventarc,可能需要几分钟才能将所有必要的权限传播到Service Agent。否则,请验证是否具有Eventarc Service Agent角色。

无法创建Cloud Run服务 onrelationadded. spec.template.spec.containers.resources.limits.cpu:cpu的值无效。对于指定的值,maxScale不得超过10。请考虑在具有更大容量的区域中运行您的工作负载,减少每个实例请求的cpu,或者如果您看到接近此限制的持续使用情况,则请求增加该区域的配额。

从V1过来,我以前从未见过这个错误,经过一番搜索,我发现与IAM & ADMIN相关。检查了服务默认管理器权限,并尝试启用Functions Editor/Admin权限,但仍然没有成功。

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/LSiLA.png

命令:firebase deploy --only functions

响应:

正在部署函数
正在运行命令:npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  函数:已完成前部署脚本的运行。
i  函数:正在准备默认的代码库以进行部署
i  函数:确保已启用所需的API cloudfunctions.googleapis.com...
i  函数:确保已启用所需的API cloudbuild.googleapis.com...
i  artifactregistry:确保已启用所需的API artifactregistry.googleapis.com...
✔  函数:已启用所需的API cloudbuild.googleapis.com
✔  artifactregistry:已启用所需的API artifactregistry.googleapis.com
✔  函数:已启用所需的API cloudfunctions.googleapis.com
i  函数:正在准备上传的函数目录...
i  函数:打包 /User/ ******/******/****(125.52 KB)以上传
i  函数:确保已启用所需的API run.googleapis.com...
i  函数:确保已启用所需的API eventarc.googleapis.com...
i  函数:确保已启用所需的API pubsub.googleapis.com...
i  函数:确保已启用所需的API storage.googleapis.com...
✔  函数:已启用所需的API pubsub.googleapis.com
✔  函数:已启用所需的API eventarc.googleapis.com
✔  函数:已启用所需的API storage.googleapis.com
✔  函数:已启用所需的API run.googleapis.com
i  函数:为pubsub.googleapis.com生成服务标识...
i  函数:为eventarc.googleapis.com生成服务标识...
✔  函数:成功上传函数文件夹
i  函数:在RelationAdded(us-central1)上创建Node.js 18(2nd Gen)函数...
⚠  函数:您当前项目的配额不允许当前最大实例设置为100。要么减少此函数的最大实例,要么在https://cloud.google.com/run/quotas上请求增加基础Cloud Run服务的配额。
⚠  函数:您可以在函数运行时选项中调整最大实例值:
        setGlobalOptions({maxInstances: 10})
无法创建函数 projects/****/locations/us-central1/functions/Added/user

以下函数部署出现错误:
        AddedUser(us-central1)
i  函数:清理构建文件...

错误:部署函数时出错

请注意,代码部分未进行翻译,如您要求的那样。如果需要进一步的信息或帮助,请随时提出。

英文:

Followed the docs and did the setup as needed, whenever trying to deploy a function, the debug error says

Cannot create trigger projects/***********/locations/us-central1/triggers/******-967155: 
Invalid resource state for \"\": Permission denied while using the Eventarc Service Agent. If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent. Otherwise, verify that it has Eventarc Service Agent role."

Could not create Cloud Run service onrelationadded. spec.template.spec.containers.resources.limits.cpu: Invalid value specified for cpu. For the specified value, maxScale may not exceed 10.\nConsider running your workload in a region with greater capacity, decreasing your requested cpu-per-instance, or requesting an increase in quota for this region if you are seeing sustained usage near this limit

Coming from the V1 I never saw this error before, after looking a lil bit I found its related to IAM & ADMIN . checked the service default manager permission and tried to enable permission as Functions Editor/Admin but still without success

Firebase Cloud Functions V2 – 部署时出错

Command : firebase deploy --only functions

Response:


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  functions: Finished running predeploy script.
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged /User/ ******/******/**** (125.52 KB) for uploading
i  functions: ensuring required API run.googleapis.com is enabled...
i  functions: ensuring required API eventarc.googleapis.com is enabled...
i  functions: ensuring required API pubsub.googleapis.com is enabled...
i  functions: ensuring required API storage.googleapis.com is enabled...
✔  functions: required API pubsub.googleapis.com is enabled
✔  functions: required API eventarc.googleapis.com is enabled
✔  functions: required API storage.googleapis.com is enabled
✔  functions: required API run.googleapis.com is enabled
i  functions: generating the service identity for pubsub.googleapis.com...
i  functions: generating the service identity for eventarc.googleapis.com...
✔  functions: functions folder uploaded successfully
i  functions: creating Node.js 18 (2nd Gen) function onRelationAdded(us-central1)...
⚠  functions: Your current project quotas don't allow for the current max instances setting of 100. Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service at https://cloud.google.com/run/quotas.
⚠  functions: You can adjust the max instances value in your function's runtime options:
        setGlobalOptions({maxInstances: 10})
Failed to create function projects/****/locations/us-central1/functions/Added/user

Functions deploy had errors with the following functions:
        AddedUser(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions ```

</details>


# 答案1
**得分**: 11

为了显式减少V2版本中所有函数的默认实例数量,需要使用`firebase-functions/v2`包中的`setGlobalOptions`函数。

```javascript
import { setGlobalOptions } from "firebase-functions/v2";

// 为所有函数设置最大实例数为10
setGlobalOptions({ maxInstances: 10 });

如果您不使用ES模块,请使用以下代码:

const { setGlobalOptions } = require("firebase-functions/v2");
setGlobalOptions({ maxInstances: 10 });
英文:

To explicitly reduce the default number of instances for all functions in V2,
need to use the setGlobalOptions function from the firebase-functions/v2 package.

import { setGlobalOptions } from &quot;firebase-functions/v2&quot;;

// Set the maximum instances to 10 for all functions
setGlobalOptions({ maxInstances: 10 });

Use below code if you are not using ES module

const {setGlobalOptions} = require(&quot;firebase-functions/v2&quot;);
setGlobalOptions({maxInstances: 10});

答案2

得分: 3

如果这是您的v2首次部署,那么您可能只需要等待。在我的情况下,Cloud Run大约花了30分钟来创建一个新的服务。

要双重检查是否是您的情况,请访问https://console.cloud.google.com/functions,打开您的函数,并检查是否显示“正在创建Cloud Run服务”状态。

日志甚至说:由于这是您首次使用v2函数,我们需要更长的时间来完成所有设置,请在几分钟内重试部署。

但我没有预料到“几分钟”会持续半个小时。Reddit上有人提到,根据他们的经验,这可能需要0.5到1小时不等。

英文:

If this is your first deployment of v2, then it's likely all you need to do is wait. In my case, it took approximately 30 minutes for Cloud Run to create a new service.

To double-check if this is your case, go to https://console.cloud.google.com/functions, open your function, and check if it shows the "Creating Cloud Run Service" status.

Logs even say: since this is your first time using functions v2, we need a little bit longer to finish setting everything up, please retry the deployment in a few minutes.

But I didn't expect "a few minutes" to last half of an hour. Someone on Reddit mentioned it that it can take anywhere between 0.5 to 1h from their experience

huangapple
  • 本文由 发表于 2023年6月9日 01:31:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定