We have several 2nd gen functions sharing the same source code. Only one of them needs to be deployed with a different ignore
configuration in firebase.json
.
It’s about 2 MB inside a bin
folder that we want to ignore in all the other functions, except for that one.
Our current firebase.json
looks like this:
"functions": [{
... ...,
"ignore": [
"node_modules",
"firebase-debug.log",
... ...,
"bin" // <==== REMOVE THIS LINE FOR A SPECIFIC FUNCTION ONLY
]
}]
Any ideas on how we could achieve that?
What we’ve tested:
We thought of configuring a different functions[].codebase: 'code2'
, for example, (so we could run firebase deploy --only functions:code2:myBinFunction
), but actually both functions[].source
point to the same folder, so deployment complains with Error: functions.source must be unique but './functions' was used more than once.
We don’t want to split source code to a different folder because they all share many things and to keep maintenance simple. Also, I’m sure anyone in the team will forget and deploy using the wrong codebase and this would need a way to fail if deployed without the bin
folder.
Maybe there’s a totally different approach to this? Thanks in advance
EDIT:
Oh well, configuring functions[].source: 'functions'
in one block, and functions[].source: './functions'
on the other block did the trick to allow deployment. But I still have the problem that I need deployment to fail if the function is deployed from the wrong codebase (i.e., deployed without the bin
folder it needs)
2
Answers
I ended up configuring a
predeploy
and apostdeploy
script to:codebase
is found infirebase.json
, then theignore
list is edited:predeploy
: removebin
folder fromignore
list.postdeploy
: addbin
folder back.The
firebase.json
looks like this:And the script
firebase-deploy.js
considers:We always deploy from
package.json
scripts, so this approach works for us.A bit long but if someone wants the script as a reference, just ask. More info on firebase deploy hooks here.
The way the Firebase CLI was designed for function deployment made the initial assumption that all of the function in a single project directory are deployed together, and they all get the same set of files, which is suitable for a large majority of expected use cases for apps that use Firebase. The fact that the CLI offers you the ability to deploy them separately is mostly just an optimization for occasionally deploying only functions that are known to have changed without having to wait for them all to deploy. If you really do have two sets of functions that must be deployed separately with different sets of files and configurations, then the Firebase CLI is just going to make your life hard.
Best case, you can *create a different project workspace with different sets of files required by each function and manage them separately, but you must be careful that you don’t allow the deployment of one workspace to undo what was deployed in the other. Common code can be
npm install
ed into each project from another location prior to deployment. You will need to know how to work withnpm
in a way that isn’t typical. See the following for ideas: