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

Provide runtime config in Node discovery #4541

Merged
merged 3 commits into from May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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