I need to update some parameters that I keep in the config file for the Firebase functions via programs such that without me needing to manually deploy the function again the parameters value is updated and the appropriate functions are deployed again.
I have tried Google Cloud Build and Cloud Run. I can re deploy a function but I can't seem to be able to update the config.json before deploying the function.
It's not possible to change any of the content or configuration after deployment without deploying again. If you require dynamically modifiable configuration, you're going to have to provide that for yourself via a database query or something that the function can do at runtime to see if there is an update
Related
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.
How do I prevent Firebase to always update Node JS?
Every time I put:
firebase deploy
It updates to Node.js:
functions: updating Node.js 10 function ssr(us-central1)...
Making it to take so long and using a lot of storage.
I already tried to use firebase deploy --only hosting but it obviously doesn't trigger the function.
I just want that firebase resets the SSR function without updating node.
I have done some research too and I didn't find anything.
Your source code is rebuilt every deployment on Cloud Functions. It's part of the deployment process:
Deployments work by uploading an archive containing your function's source code to a Google Cloud Storage bucket. Once the source code has been uploaded, Cloud Build automatically builds your code into a container image and pushes that image to Container Registry. Cloud Functions uses that image to create the container that executes your function.
The storage size you're mentioned defines the size of the execution environment. It includes the runtime, the operating system, packages, and a library that invokes your function. As mentioned above, even if you deploy a 10MB source code, it doesn't mean that the total size of the image will be 10MB. Storage is needed for the built image as well.
--only hosting flag deploys your static sites on Firebase. This flag is not intended for deploying functions. Maybe you're referring on specifying function names like --only functions:funcName
To answer your question, you can't. It's not possible to update your code and skip updating the execution environment of the function. You may be able to do that if you deployed your code on a VM but Cloud Functions is serverless and managed by Google. Because container images are immutable, it's not possible to edit a revision. In order to apply changes to your function, it has to be rebuilt every deployment.
Deployment time and storage is a valid concern, that's why devs are usually recommended testing their function locally first, before deploying it to Firebase. You can do that with Cloud Functions Emulator.
I want to use Firebase cloud functions but when I try to init exists project I get error.
This is the error "Error: HTTP Error: 403, The caller does not have permission"
I created project before and then I moved project folder. When I had tried deploy, it wasn't work. I don't remember which error I got. And then I tried init same project but I got this error.
I tried logout and login again but it wasn't work.
I deleted "firebase-tools" but it wasn't work too.
And after I tried on different computer and I got same error.
And also I have Firebase Admin permission.
The firebase init command initializes/enables the project to use Cloud Functions for Firebase. Owners or Editors should use this command. Owners/Editors have higher permissions which allows APIs to be enabled (e.g. allowing the project to create VMs, Cloud Functions, or create a NoSQL Database).
Therefore I think you should perform this operation with Owner/Editor role.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.
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.
Is there a way to delete an app via Firebase CLI?
Our CI creates a temporary Firebase app for a feature branch (based on the CI build number), and then runs tests on it. At the end it needs to delete the app. I'm not entirely sure how this is done. firebase disable:hosting just disables hosting and does not delete the app. This is similar to how we would have used Heroku review apps or Heroku forked apps. A similar CI workflow can also be achieved on Google App engine via versions.
Any pointers would be much appreciated.
The correct command is firebase hosting:disable, which make your site offline. You can not remove your project, instead you can overwrite it by creating a new one with firebase init.
More info here https://firebase.google.com/docs/cli/.
There is currently no public API to delete a Firebase backend.
The recommended practice is to use the same database for testing and (if needed) put each run in its own node under the root. So instead of creating/deleting a new database, you're just create/deleting a node in a single database.
Using the command firebase use <alias> --unaliasand then delete the project from the console https://console.firebase.google.com/
Check before the list of commands with the command -h