-
Notifications
You must be signed in to change notification settings - Fork 938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firebase deploy trigger functions with dotenv not working #4614
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
The current solution does not inject environment variables during deploy time. For roadmap reasons (largely our alignment with Firebase Extensions) we need our "discovery" phase to happen without project-specific details like environment variables. Instead we have an upcoming feature where you can declare a parameter to your application and the deploy process will work with you to resolve those parameters. You can follow along the status of that feature request here |
We didn't remove Runtime Config from the discovery phase for reverse compatibility reasons, though it is going away in general (no ETA yet). We don't populate dotenv files during the discovery phase because our reconciliation between Functions and Extensions requires us to be able to determine the shape of the deployment generically outside the context of the project/environment variables. We'll do this by capturing dependencies on, for example, the storage bucket as a "parameter". This parameter will be enforced at deploy time (e.g. while interactive you'll be prompted for any missing values and in non-interactive mode a deployment will fail). It will be backed by dotenv files in Cloud Functions for Firebase and by the backend server in the case of Firebase Extensions. |
Thank you for explanation, @inlined. The documentation specifically suggests to use global variables to reuse objects in future invocations. I wanted to initialize an instance of a bot object providing it with a TOKEN from the environment variables, but the current behaviour makes it impossible. Therefore, I have to resort to the lazy initialization from the function body. At least there is a workaround. But the documentation seems a bit misleading in this light. Moreover, even after the parameters will come to the scene, still the deployment may fail due to the limitations of the deployment environment. For example, network access may be restricted. Am I clear? But I guess we cannot avoid this global context execution... At least some clarification may be added to the above mentioned documentation. |
Yes, I would recommend checking the status of an environment variable before doing global initialization. So instead of:
change to
We are considering giving a startup callback as well so you can have code that runs only when a new instance is launched in production. |
[REQUIRED] Environment info
firebase-tools:
11.0.1
Platform:
macOS
[REQUIRED] Test case
I have added a .env file providing some variables:
STORAGE_UPLOAD_BUCKET=mycustombucket
Then i want to use this variable to create a trigger:
The problem is that STORAGE_UPLOAD_BUCKET is not defined during the time of deployment, so the trigger gets deployed for the default bucket, not matter the value of STORAGE_UPLOAD_BUCKET.
But during runtime of the function it is then set.
The same problem exists for other triggers: You cannot use environment variables in firestore trigger paths.
The text was updated successfully, but these errors were encountered: