Download or sync Firebase Functions to local environment - firebase

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.

Related

How do you set variables, based on environment, for Firebase Cloud Functions?

Similar question to
How do you setup local environment variables for Cloud Functions for Firebase, but specifically looking how to setup environment variables that differ between development and production.
For example,
Say I would typically have:
.env
REACT_APP_DOMAIN: https://foo-bar.web.app/
.env.development
REACT_APP_DOMAIN: http://localhost:3000/
How would one create a similar setup for Firebase Cloud Functions?
I have an answer to my own question, though I don't think it's optimal.
In the Firebase's local-emulator documentation, they have this section:
Set up functions configuration (optional)
If you're using custom functions configuration variables, first run the command to get your custom config (run this within the functions directory) in your local environment:
firebase functions:config:get > .runtimeconfig.json
If using Windows PowerShell, replace the above with:
firebase functions:config:get | ac .runtimeconfig.json
Though poorly explained, this is just creating a json file .runtimeconfig.json, which contains your firebase config variables. The variables in this file are then used by the Firebase emulator, in place of what is stored in Firestore. This is better explained in this github repo ticket.
Now knowing this, .runtimeconfig.json can be used in a similar manner that .env.development is. Instead of using the command they suggest, you can just manually update it as you need (or use their command to pull down your firebase variables and then modify them as needed).
You access/use those local variables in the exact same way you would normally access Firebase variables, functions.config().foo.bar.
When deployed, they'll reference your variables as set on Firebase. When in development (through firebase emulator), they'll reference what you have in .runtimeconfig.json.

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 CLI - How to Manage Cloud Functions

Using the firebase-cli you can easily deploy functions and show the logs. But I have yet to find the option to download or retrieve cloud functions.
I've dug through quiet a bit of the -h commands and nothing yet.
Is it possible to download / retrieve a projects cloud functions through the firebase-cli? I tend to switch between computers from home to work and I need to go to the console to copy the source code and redeploy.
The Firebase CLI doesn't provide a way to get deployed code. It's expected that you use some form of source control for managing code between developers and machines.

Firebase commandline to list functions from GCP firebase

I have 100ds of functions deployed to firebase and I would like to know if I can list the remote functions on my machine using the firebase command line tools.
I want to see the list of functions deployed.
What I am trying to solve is:
Batch deploy functions to avoid deployment limit.
Deployment error when function deleted/renamed locally and then deploying whole functions.
Thanks!
I got the exact answer from Google support.
Currently, Firebase CLI doesn’t have any command to list deployed functions, whereas “gcloud functions list” CLI from Cloud SDK shows the list instead.
More details found here
While it doesn't seem to be documented here, you can list all deployed Cloud Functions when you have firebase-tools installed with firebase functions:list. The command is also mentioned in firebase --help.
Verified with firebase-tools version 10.5.0
At the time of writing this answer, there is no CLI command that allows listing all the deployed functions for your project. The available commands can be found here: https://firebase.google.com/docs/cli/#commands
However, note that you can list the deployed functions in the Google Cloud console (not the Firebase one) by opening: https://console.cloud.google.com/functions/list?project=your_project_name

Firebase deploy after test to production environment

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.

Resources