gpt4 book ai didi

firebase - 如何在忽略现有功能的同时部署 Cloud Functions?

转载 作者:行者123 更新时间:2023-12-02 01:29:13 25 4
gpt4 key购买 nike

假设我的 Firebase 项目中有以下四个函数:

openDoor(europe-west1)
closeDoor(europe-west1)
openWindow(europe-west1)
closeWindow(europe-west1)

现在,这些函数存在于两个独立的 Node 包中,即一个包含 openDoorcloseDoor另一个包含 openWindowcloseWindow

错误

如果我尝试从带有门功能的包中运行 firebase deploy,将抛出以下错误(在非交互模式下):

Error: The following functions are found in your project but do not exist in your local source code:
openWindow(europe-west1)
closeWindow(europe-west1)

这是一个问题,因为它会取消任何尝试部署这些功能的 CD 工作流。

强制删除

有一个选项可以强制删除任何现有函数:

  -f, --force              delete Cloud Functions missing from the current 
working directory without confirmation

但是,我想要相反的。我想保留所有现有功能。

理论解决方法

我发现一种理论上可行的解决方法是:

yes N | firebase deploy --interactive

管道 N 到交互式部署命令,它将回答 N 到删除提示:

The following functions are found in your project but do not exist in your local source code:
openWindow(europe-west1)
closeWindow(europe-west1)

If you are renaming a function or changing its region, it is recommended that you create the new function first before deleting the old one to prevent event loss. For more info, visit https://firebase.google.com/docs/functions/manage-functions#modify

? Would you like to proceed with deletion? Selecting no will continue the rest of the deployments. (y/N)

现在的问题是我正在使用https://github.com/w9jds/firebase-action部署功能,这意味着我需要有一个内置的 Firebase 解决方案。

最佳答案

您可以使用新的 codebases feature in Firebase .

通过指定 codebase在你的firebase.json functions配置,问题解决。 Firebase CLI 将不再提示您删除其他功能,因为它只考虑相同的功能 codebase .

如果您的 firebase.json以前看起来像这样:

{
"functions": {
"source": "cloud_functions",
"ignore": [...],
"predeploy": [...],
"postdeploy": [...]
}
}

你只需要加上"codebase": "<name>"到配置:

{
"functions": {
"source": "cloud_functions",
"codebase": "window",
"ignore": [...],
"predeploy": [...],
"postdeploy": [...]
}
}

部署现在看起来像这样:

i  functions: updating Node.js 16 function window:openWindow(europe-west1)...
i functions: updating Node.js 16 function window:closeWindow(europe-west1)...

请注意,实际的函数名称​​不会改变,即函数仍然只会被调用 openWindow (没有前缀)在 Firebase/Google Cloud Console 中。所以这基本上是问题的完美解决方案。

关于firebase - 如何在忽略现有功能的同时部署 Cloud Functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73698920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com