Excluding a function when deploying firebase cloud functions - firebase

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

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.

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

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.

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.

Firebase functions in same project but multiple apps

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.

microservice deployment in firebase hosting for an app

I've built an app with polymer 2.0 and polymerfire and deployed it into firebase hosting. This part is smooth.
But I wanted to maintain all my cloud functions as separate modules / separate projects and deploy them independently into firebase hosting. As per the Google IO 2017 talks, it is advised to go microservice style for the cloud functions.
The problem I am facing:
Whenever I deploy an individual module, it erases all the previously deployed cloud functions. Meaning firebase deploy from a project with only firebase functions enabled, will erase all the other cloud functions and deploy the ones declared in this project.
In a nutshell, it looks like I need to create a single monolith with the complete web application, all the cloud functions all in one single fat project and deploy the whole thing. This defeats the point of being microservice style!
Please advise if I am missing something important in the whole setup procedure?
You can deploy/undeploy individual functions with the Firebase tools/CLI version 3.8 or higher by specifying what function(s) to update: firebase deploy --only functions:function1,function2. It will still deploy all the code in your project, since the CLI doesn't "know" what file(s) are needed for each specific function. But it will then only update the function(s) that you specify.

Resources