Skip to content
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

Functions Emulator does not load enviroment variables/parameters from .env.local #5314

Closed
sceee opened this issue Dec 8, 2022 · 2 comments
Closed

Comments

@sceee
Copy link
Contributor

sceee commented Dec 8, 2022

[REQUIRED] Environment info

firebase-tools: 11.17.0

Platform: Windows

[REQUIRED] Test case

Relates to #5313

  • Have an empty .env file:
  • Have a .env.my-project-id file:
# Keep this empty so that the emulator at startup asks for the value as defining IS_STAGING=true here would prevent the emulator from starting because of the issue described at the bottom of https://github.com/firebase/firebase-tools/issues/5313
  • Have a .env.my-staging-project-id file:
IS_STAGING=true
  • Have .env.local file:
FUNCTIONS_EMULATOR=true

Have a function in that references this parameter's value from .env.local:

...
if (defineBoolean('FUNCTIONS_EMULATOR').value() === true) {
...
}
...

Have some test that calls a Cloud Function.

[REQUIRED] Steps to reproduce

  1. Execute the test run with firebase emulators:exec --import=./testdata/emulatordata \"npm test\"

-> The test just "silently" fails as it executes the wrong code as it seems the FUNCTIONS_EMULATOR parameter is not set correctly (based on the .env.local file) but there is no warning/output that it could not be loaded.

  1. Just "start" the Firebase emulator using firebase emulators:start --import=./testdata/emulatordata --project default
    -> It emits that it did not load the .env.local file:
? Enter a boolean value for IS_STAGING: false
i  functions: Loaded environment variables from .env, .env.my-project-id.
i  functions: Loaded environment variables from .env, .env.my-project-id.
i  functions: Writing new parameter values to disk: .env.my-project-id

[REQUIRED] Expected behavior

  • It loads the .env.local file when using the emulator.
  • If it could not find a used environment variable, the warning for the missing variable is also emitted when executing the tests using firebase emulators:exec and not just when using firebase emulators:start.

[REQUIRED] Actual behavior

  • It does not load the .env.local file when using the emulator.
  • The warning of the "missing" environment variable is not emitted when executing the tests using firebase emulators:exec.
@sceee
Copy link
Contributor Author

sceee commented Dec 8, 2022

This also seems to apply for a .secret.local file - it also does not seem to be loaded when using the emulator.
According to firebase-debug.log, it seems that even a secret that is defined in the .secret.local file is loaded from Google Cloud Secret Manager as there are log entries like

[debug] [2022-12-08T10:22:58.610Z] <<< [apiv2][status] GET https://secretmanager.googleapis.com/v1/projects/py-project-id/secrets/MY_SECRET 200

@aalej
Copy link
Contributor

aalej commented Dec 9, 2022

Hi @sceee, thanks for the information you provided. It seems like this ticket and #5313 is similar to the issue reported in #5219. With this, I’ll be closing this issue. If you have any other information you would like to add, please add them to #5219.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants