Firebase functions - is it possible to deploy functions:config variables without depoying all the functions? - firebase

I have added a new environment variable to the functions:config.
I have some cloud functions that are not ready to be deployed to production yet.
How can I deploy the env variable without deploying all the functions?
It tells me to use:
firebase deploy --only functions

What you're trying to do is not possible. The functions config env vars are essentially part of each individual function's deployment. They don't exist separately from the function - they are part of the function and are packaged up along with it when you deploy.
To put it another way, you can think of the vars as part of the code of your function. If you change the code or vars at all, the entire thing needs to be redeployed.

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

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.

Firebase deploy only functions process

If I have two Firebase functions (fire1 and fire2) that share a helper function (doSum), will deploying with firebase deploy --only functions:fire1 change the environment of fire2?
No, each function is fully indepndent of each other. Each deployed function gets its own copy of the entire deployed project. A deploy of a single function will not in any way affect the code deployed for any other function.

Resources