firebase functions deployment in batches - firebase

I am using github action to deploy firebase functions with command like so:
firebase deploy --only functions --non-interactive --token ${{ secrets.FIREBASE_TOKEN }}
however currently all my triggered github action instances to firebase function deploy fail, i believe its due to the cloud build process timing out because the high count of functions building and attempting to deploy at once. In my case 50+
How exactly can i deploy firebase functions in batches using github action?
Ideally, it would read the export functions from main index.js file of functions and deploy 25 functions at a time with some delay3(i.e 30 seconds) in between.
I am aware i can do this by hardcoding function names but i was hoping to do keep the github action simple and independent of function names.

Related

Get a list of modified firebase cloud functions names for my CICD pipelines

I am trying to find a way where I'll be able to get the names of modified cloud functions names with respect to local functions. That way I'll be able to only deploy those functions which are modified in my CICD pipelines
For example, I have a function called createUser and manageUser. Now right now if I run firebase deploy --only functions it will deploy both of these functions but what if my changes were only in manageUser. I want to be able to detect it and output a command like this firebase deploy --only "functions:manageUser"
I tried searching but couldn't find a solution. There were options of using git and file changes but that will cause issues for me because there are many developers in my team deploying functions from their own branches.

Will Firebase replace all my cloud functions?

In our organization, we have a repo for all cloud-functions. They are all in Python. We've had to create another cloud-function and we've decided to write it in NodeJS.
This new cloud-function is in a new repo, in a new project. There's no relationship between the old functions and the new one.
I've read that if I use firebase deploy --only functions, it will deploy all functions in the index.js file, but I'm not sure if it will remove the other ones, since there is nothing in my index.js file about the other cloud-functions written in Python.
Is it safe to deploy my new function with firebase deploy --only functions? I don't want to replace the other functions, just add my new function.
Thanks!
If you run firebase deploy or firebase deploy --only functions, Firebase will likely replace all the Cloud Functions in the project.
If you want to only deploy a single function, or a group of functions, you can specify that as an additional argument:
firebase deploy --only functions:yourNewFunction
Also see the Firebase documentation on deploying specific functions.
I just tested this out, whenever deploying functions by using firebase deploy or firebase deploy --only functions and the index.js does not find the name of a function it will display this message:
The following functions are found in your project but do not exist in your local source code:
<function_name>(<region>)
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
If a function has the same name as one of the Cloud Functions already deployed it will replace the older function. But if it has a different name it should not be replaced and you should be safe. If you still feel unsure feel free to test this out with quick start functions.

Excluding a function when deploying firebase cloud functions

I have 2 environment: development and production.
In the development environment I would like to have a couple of extra functions which due to their nature cannot be deployed to prod.
How can I achieve this without having two almost identical cloud function files?
I know one can name the functions when deploying them, but I cannot find a way to exclude a function.
Posting as community wiki as per #Myk Willis, if you're using gcloud functions deploy, each function is specified individually. Exclude functions from production simply by not deploying them.
As per the OP, when using Firebase tools, the doc recommends to deploy functions individually when the number of functions exceed 5.
This command explicitly specifies the functions to be deployed on the project:
firebase deploy --only functions:yourFunction1,functions:yourFuntion2

Don't delete firebase cloud funtions

I'm configuring CD process on gitlab to google cloud functions (firebase).
Also i have 3 envs (development, staging and production) and i want to deploy each function with matching postfix (_development, _staging).
When i deploy functions to development, for instance, from my local machine with command
firebase deploy --only functions
it always asks me
Would you like to proceed with deletion? Selecting no will continue the rest of the deployments.
And i choose "No", because i don't want to delete existing functions with other postfixes. But on gitlab there is no possibility to enter "No" and it decides to delete all that functions as default.
Is there some solution to not delete existing functions in cloud? Probably some flag in deploy command?
The way you are managing environments is not recommended by the Firebase team. You should be using different projects to isolate the different environments as described in the documentation.
But if you absolutely can't make any changes to what you're doing, what you will have to do is call out the names of each function to deploy, as described in the documentation:
By default, the Firebase CLI deploys all of the functions inside
index.js at the same time. If your project contains more than 5
functions, we recommend that you use the --only flag with specific
function names to deploy only the functions that you've edited.
Deploying specific functions this way speeds up the deployment process
and helps you avoid running into deployment quotas. For example:
$ firebase deploy --only functions:addMessage,functions:makeUppercase
Or, you can use function groups.

How to deploy some functions to Cloud Functions for Firebase without affecting some other functions?

When I run
firebase deploy --only functions
it reads the index.js file and updates all functions exported from that file. If on the previous deploy there was a function named a, and in the current deploy there is no such function, a will be deleted.
In other words, the effect is the same as if all existing functions were deleted and then the all functions from the current index.js file were added.
Is it possible to add/update/delete individual functions?
Firebase CLI tools 3.8.0 has added the ability to deploy specific functions.
firebase deploy --only functions:func1,functions:func2
--only <targets>
only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions,
can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2").
When filtering based on export groups (the exported module object keys), use dots to specify group names
(e.g. "--only functions:group1.subgroup1,functions:group2)"
The following way worked for me to deploy a particular function without affecting my other functions, where specificFunctionName is the function I wanted to deploy
firebase deploy --only functions:specificFunctionName
To copy the command quickly in terminal:
firebase deploy --only functions:
firebaser here
There is currently no way to deploy a single function with the Firebase CLI. Running `firebase deploy` will deploy all functions.
We've recently discussed deploying subsets of the functions, but it's not available at the moment - nor can we give a ballpark of if/when it might be.
Update Since Firebase CLI release the ability to deploy single functions is available. See yuku's answer.
firebase deploy --only "functions:<fileName>.<functionName>"
example folder structure:
functions
node_modules
index.js
smsNotification.js
...
You can redeploy just a function in a file with
firebase deploy --only "functions:smsNotification.sendChatNotif"
You can redploy all functions in a file with
firebase deploy --only "functions:smsNotification"
I never managed to get it working (and have no codebase property in my firebase.json) until I tried what #Sergey Mell mentioned in his comment :
firebase deploy --only "functions:func1,functions:func2"
The surrounding double quotes was what solved the issue.
In case anyone still can't make it work using firebase deploy --only functions:func1,functions:func2, it's probably because you're probably using codebases, "codebase": "my-codebase", in your firebase.json. Took me a while to diagnose but after removing that codebase property, deploying only some functions using the --only flag worked for me
This one gave me the missing package. Although package was included but I had to reinstall the mentioned package.
firebase --debug deploy --only functions:[functionName]

Resources