Skip to content

Commit

Permalink
Provide runtime config in Node discovery (#4541)
Browse files Browse the repository at this point in the history
* Provide runtime config in Node discovery

* Changelog
  • Loading branch information
inlined committed May 11, 2022
1 parent 514bba3 commit 4b2242e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,2 +1,3 @@
- Fix bug where functions failed to deploy if Runtime Config is accessed at global scope (#4541)
- Updates [firebase-frameworks](https://github.com/FirebaseExtended/firebase-framework-tools) to 0.4.2 addressing several issues with the web frameworks integration.
- Adds `hosting.source` to configuration schema as an allowed property.
26 changes: 17 additions & 9 deletions src/deploy/functions/runtimes/node/index.ts
Expand Up @@ -92,15 +92,23 @@ export class Delegate {
return Promise.resolve(() => Promise.resolve());
}

serve(port: number, envs: backend.EnvironmentVariables): Promise<() => Promise<void>> {
serve(
port: number,
config: backend.RuntimeConfigValues,
envs: backend.EnvironmentVariables
): Promise<() => Promise<void>> {
const env: Record<string, string | undefined> = {
...envs,
PORT: port.toString(),
FUNCTIONS_CONTROL_API: "true",
HOME: process.env.HOME,
PATH: process.env.PATH,
};
if (Object.keys(config || {}).length) {
env.CLOUD_RUNTIME_CONFIG = JSON.stringify(config);
}
const childProcess = spawn("./node_modules/.bin/firebase-functions", [this.sourceDir], {
env: {
...envs,
PORT: port.toString(),
FUNCTIONS_CONTROL_API: "true",
HOME: process.env.HOME,
PATH: process.env.PATH,
},
env,
cwd: this.sourceDir,
stdio: [/* stdin=*/ "ignore", /* stdout=*/ "pipe", /* stderr=*/ "inherit"],
});
Expand Down Expand Up @@ -157,7 +165,7 @@ export class Delegate {
if (!discovered) {
const getPort = promisify(portfinder.getPort) as () => Promise<number>;
const port = await getPort();
const kill = await this.serve(port, env);
const kill = await this.serve(port, config, env);
try {
discovered = await discovery.detectFromPort(port, this.projectId, this.runtime);
} finally {
Expand Down

0 comments on commit 4b2242e

Please sign in to comment.