Repository navigation
Make environment variables on function instances be accessible during trigger parsing - #3422
Conversation
…ger parsing.
We move the logic for setting up environment variables for function instances from post-trigger parsing to pre-trigger parsing. This makes environment variables accessible during trigger parsing, e.g.
const myFunc = functions.runWith({minInstances: process.env.TIER == "PROD" ? 20 : 0})...
(Of course, there isn't a way for users to specify environment variables for now. That may change soon.)
| ): Promise<TriggerAnnotation[]> { | ||
| return new Promise((resolve, reject) => { | ||
| const env = _.cloneDeep(process.env); | ||
| const env = { ..._.cloneDeep(process.env), ...envs } as NodeJS.ProcessEnv; |
There was a problem hiding this comment.
This may be a breaking change, but I actually think we shouldn't ever have been carrying forward process.env. It was always weird undefined behavior before and I'd be OK dropping it for now. IMO, we should be populating exactly the env they'll be getting in production.
There was a problem hiding this comment.
oh, as a nit, you don't need _.cloneDeep anymore since you're already cloning with the splat operator and this is just a simple map so there's no recursive cloning to do.
| entryPoint: annotation.entryPoint, | ||
| runtime: runtime, | ||
| trigger: trigger, | ||
| environmentVariables: envs, |
There was a problem hiding this comment.
Hmm.. this gives me a bit of pause. If we're requiring project-level env, should env be a backend attribute and not a FunctionSpec attribute?
There was a problem hiding this comment.
Woo that's an excellent point! Thanks - will address.
2a439b3 to
57da423
Compare
… trigger parsing (firebase#3422) We move the logic for setting up environment variables for function instances from post-trigger parsing to pre-trigger parsing. This makes environment variables accessible during trigger parsing, e.g. ``` const myFunc = functions.runWith({minInstances: process.env.TIER == "PROD" ? 20 : 0})... ``` (Of course, there isn't a way for users to specify environment variables for now. That may change soon.) This change simply refactors existing logic - nothing new is introduced and function deploys should work exactly as it is done today. *Warning* There is technically a breaking change where we no longer pass caller's `process.env` when forking a process to parse function triggers in user's source code. We think this is removing what was previously an undefined behavior but recognize we may be breaking someone's workflow. We will soon propose a support for setting project-level environment variables more easily.
We move the logic for setting up environment variables for function instances from post-trigger parsing to pre-trigger parsing. This makes environment variables accessible during trigger parsing, e.g.
(Of course, there isn't a way for users to specify environment variables for now. That may change soon.)
This change simply refactors existing logic - nothing new is introduced and function deploys should work exactly as it is done today.
Warning There is technically a breaking change where we no longer pass caller's
process.envwhen forking a process to parse function triggers in user's source code. We think this is removing what was previously an undefined behavior but recognize we may be breaking someone's workflow. We will soon propose a support for setting project-level environment variables more easily.