I have cloud functions set up for a project that will be used by multiple projects. I understand that you can deploy those functions to different projects using firebase use and adding/using aliases. Is there a way to deploy the functions to all known project aliases?
There is nothing built in to the Firebase CLI to do this as each project is considered to be a fully separate environment. You can use the --project <alias_or_project_id> flag to deploy to different aliases without having to switch using firebase use:
firebase deploy --project alias1
firebase deploy --project alias2
firebase deploy --project alias3
You could write a shell script to do all of those one after another or in parallel.
The Firebase CLI doesn't have a command for that. You can write a shell script or some other program to automate the execution of firebase deploy as many times as needed for each project you want to deploy.
Related
I am working on a Firebase project that currently uses several Cloud Functions.
The thing is that I want to download or sync the Cloud Functions to the local environment on my laptop.
I mean some command using firebase-tools or another like:
git clone [project name]
git fetch [something]
Usually, we create some cloud functions using the Firebase Console, and I would like to have these functions locally to edit these when needed and deploy them again.
I know that firebase-tools have these two commands, but it is only for configurations:
functions:config:clone [options]
functions:config:get [options]
There's no provided solution for automatically copying or synchronizing functions that have already been deployed. You can certain get the source code for deployed functions, but the Firebase CLI will not automate that process for you.
Ideally, you will want to manage all of your functions from the same source control and CLI in order to deal with them all consistent. Editing functions from the console is primarily a convenience, not a proper deployment mechanism.
I experimented with firebase functions for the init part and it has created a folder for me. Now when I deploy each time it also picks up the functions folder. When I remove the functions folder I get an error, when deploying. How do I deploy everything but functions?
firebase deploy has a parameter --except . So to deploy everything except functions you can run:
firebase deploy --except functions
You can use the only option/flag, for example firebase deploy --only hosting,storage, see the CLI doc.
You can also use deploy targets which "are short-name identifiers (that you define yourself) for Firebase resources in your Firebase project".
Check to make sure that you have removed the implicit reference to the function in your index.js and then running firebase deploy should do the trick. If you want to explicitly delete the function completely, you can use the firebase functions:delete <myFunction> and then delete the functions folder. You can find more details in the doc here
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.
I have created 2 separate projects in Firebase one for the TEST (development) and one for the actual PROD(unction) environment.
I have create a hosting project and am also using Firebase functions that I have successfully deployed and tested on the Firebase TEST project (using the command line as described in the docs).
What is the best / easiest way to now publish to the Firebase PROD project?
Get familiar with the way the Firebase CLI lets you attach a workspace to multiple projects. You can use firebase use --add on the command line to add a project alias, then firebase use [project] to switch between projects for deployment.
You can find the documentation for managing aliases here.
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]