假设我的Firebase项目中有以下四个函数:
openDoor(europe-west1)
closeDoor(europe-west1)
openWindow(europe-west1)
closeWindow(europe-west1)
现在,这些函数存在于两个独立的Node包中,即一个包含openDoor
和closeDoor
,另一个包含openWindow
和closeWindow
。
错误
如果我尝试从具有门功能的包运行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解决方案。
您可以使用Firebase中的新代码库功能。
通过在firebase.json
functions
配置中指定codebase
,可以解决此问题。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)...
请注意,实际函数名称并没有更改,即该函数仍将仅在Firebase/Google Cloud控制台中被称为openWindow
(没有前缀(。因此,这基本上是这个问题的完美解决方案。
或者,您也可以在执行部署时指定函数名称。
firebase deploy --only functions:openDoor,functions:closeDoor