I happen to have over 100 cloud functions. I occasionally add new sets of functions to it. Is there a sort of flag that can deploy newly added set of functions only? Eg
firebase deploy --only functions --new
PS: I know I can specify the newly added functions to be deployed in the command. However most times it is hard to track the new functions and all I want to do is deploy newly added functions
No, such a flag is not available in the CLI.
You could maybe take advantage of the option that allows grouping functions into export groups in your /functions/index.js file. Grouping functions allows you to deploy multiple functions using a single command. In other words, you would create a new group for each set of new functions. See the CLI Reference for more details.
Related
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.
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.
I can create process.env variables from https://console.cloud.google.com/functions
but I've to create this variables for each and every firebase cloud functions which is inefficient.
How can I create these process.env variables from code? while deploying cloud functions from my machine? If I can set it up from GUI then there must be a way to set it up from CLI/code.
Firebase does not directly support setting process environment variables. Currently, the only way to provide configuration at the time of deployment is using a different kind of environment configuration, which is not really the same as process env vars that you're showing in the screenshot.
If you want to set process environment variable for functions deployed with the Firebase CLI, you will have to use the method that you've already discovered. If you want to set them at the time of deployment, you will have to use Google Cloud's command line "gcloud" instead, which means you won't be able to take advantage of the firebase-functions API or the Firebase CLI at all. You just have to choose between the two.
Update: Feb 16, 2022
This can now be done from the code using .env, see answer.
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.
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.