Firebase functions in same project but multiple apps - firebase

In same Firebase project I have a node app with several functions and another app with only scheduled functions (because for some reason, I encountered side effects if deployed together in same app).
Each time I deploy the app with only scheduled functions, it tells me that other functions are not present in the source code (obviously) and asks me if I want to delete them.
Is there a way to tag functions as permanent and avoid each time to have to chose to not delete them ?

When you deploy Cloud Functions through the Firebase CLI, it expects that you pass it a index.js/index.ts that contains all the functions for that entire project.
There is no way to tag certain Cloud Functions as permanent. I usually explicitly tell Cloud Functions what functions I'm deploying in situations such as yours, with firebase deploy --only functions:function1,function2.
For more on this option, see the reference documentation on deploying specific functions. The option to group the functions sounds especially useful for your scenario, as you could group them by app.

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.

Prevent firebase functions to always update Node.js 10

How do I prevent Firebase to always update Node JS?
Every time I put:
firebase deploy
It updates to Node.js:
functions: updating Node.js 10 function ssr(us-central1)...
Making it to take so long and using a lot of storage.
I already tried to use firebase deploy --only hosting but it obviously doesn't trigger the function.
I just want that firebase resets the SSR function without updating node.
I have done some research too and I didn't find anything.
Your source code is rebuilt every deployment on Cloud Functions. It's part of the deployment process:
Deployments work by uploading an archive containing your function's source code to a Google Cloud Storage bucket. Once the source code has been uploaded, Cloud Build automatically builds your code into a container image and pushes that image to Container Registry. Cloud Functions uses that image to create the container that executes your function.
The storage size you're mentioned defines the size of the execution environment. It includes the runtime, the operating system, packages, and a library that invokes your function. As mentioned above, even if you deploy a 10MB source code, it doesn't mean that the total size of the image will be 10MB. Storage is needed for the built image as well.
--only hosting flag deploys your static sites on Firebase. This flag is not intended for deploying functions. Maybe you're referring on specifying function names like --only functions:funcName
To answer your question, you can't. It's not possible to update your code and skip updating the execution environment of the function. You may be able to do that if you deployed your code on a VM but Cloud Functions is serverless and managed by Google. Because container images are immutable, it's not possible to edit a revision. In order to apply changes to your function, it has to be rebuilt every deployment.
Deployment time and storage is a valid concern, that's why devs are usually recommended testing their function locally first, before deploying it to Firebase. You can do that with Cloud Functions Emulator.

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

structure firebase functions into multiple runtimes

I've been using firebase ecosystem for over 2 years but as it google lacks decent documentation i often come here to ask very basic things that we should learn right after "hello world".
When using firebase functions i try to modularize it to keep it readable and easy to maintain. the way i managed to do it was by having an "index" file and multiple subfiles which contains the logic for complex functions...
although it works very well, my index file is getting super long since i'm having more and more functions and it also needs to deal with some configuration for each of those specific functions...
i was messing around firebase dashboard https://console.cloud.google.com/functions/list? and i found that is possible to create a new function over this online form... when doing it the firebase backeend somehow create a new "runtime" for this function. I mean each function created by this form has its own "index.js" "package.json"
how can i do this without need to create every function from this form?
how can i simple code a new function ecosystem, deploy it using firebase cli and have this separeted structure for it?
All Cloud Functions are logically isolated from each other at all times at runtime. While they might share some common code at deployment, they don't share anything else.
The Firebase CLI requires that all your functions be defined in a single entrypoint, which is your index.js. That is just how it works. If you don't like that, you can deploy functions individually using gcloud, but you will not be able to use the firebase-functions module to declare and implement your function. gcloud uses different conventions.
If you want to continue to deploy with the Firebase CLI, you can add the new function to your index.js. It can be deployed separately from your other functions using the --only argument. For example, if your new function is called "fn":
firebase deploy --only functions:fn
This will deploy just fn and none of the other functions defined in your index. You can read about this and more options in the Firebase CLI documentation for deploying functions.
If you abosolutely do not want to have all your functions in a single index.js, you can split the definitions among multiple files, and require or import them into the main index.js. It's up to you how you want to organize your source file, using the facilities provided by nodejs and JavaScript.

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.

Resources