Skip to content

Commit 451bb5c

Browse files
Allow users to bypass Runtime Config API calls during function deploys (#8944)
* feat: introduce mode where function deploy to never call runtime config API. * fix few issues * run formatter * style nits * Handle missing credentials gracefully in internaltesting:functions:discover Default to runtimeConfigApiEnabled=false when API check fails (e.g., no credentials) * Update src/deploy/functions/prepare.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Simplify runtime config loading implementation - Remove maybeLoadCodebasesWithConfig function and inline logic - Remove two-pass discovery strategy that had backward compatibility issues - Simplify to a straightforward on/off switch controlled by experiment flag - Remove unnecessary unit tests for the removed function - Update internaltesting:functions:discover to use simplified approach The experiment now serves as a migration flag: - Enabled (default): Loads runtime config for backward compatibility - Disabled: Skips runtime config entirely as part of deprecation path * reformat * Remove unused someEndpoint function from build.ts This function was added during two-pass discovery implementation but is no longer needed --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 98ad168 commit 451bb5c

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/commands/internaltesting-functions-discover.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { normalizeAndValidate } from "../functions/projectConfig";
66
import { getProjectAdminSdkConfigOrCached } from "../emulator/adminSdkConfig";
77
import { needProjectId } from "../projectUtils";
88
import { FirebaseError } from "../error";
9+
import * as ensureApiEnabled from "../ensureApiEnabled";
10+
import { runtimeconfigOrigin } from "../api";
11+
import * as experiments from "../experiments";
12+
import { getFunctionsConfig } from "../deploy/functions/prepareFunctionsUpload";
913

1014
export const command = new Command("internaltesting:functions:discover")
1115
.description("discover function triggers defined in the current project directory")
@@ -18,9 +22,35 @@ export const command = new Command("internaltesting:functions:discover")
1822
"Admin SDK config unexpectedly undefined - have you run firebase init?",
1923
);
2024
}
21-
const builds = await loadCodebases(fnConfig, options, firebaseConfig, {
22-
firebase: firebaseConfig,
23-
});
24-
logger.info(JSON.stringify(builds, null, 2));
25-
return builds;
25+
26+
let runtimeConfig: Record<string, unknown> = { firebase: firebaseConfig };
27+
const allowFunctionsConfig = experiments.isEnabled("dangerouslyAllowFunctionsConfig");
28+
29+
if (allowFunctionsConfig) {
30+
try {
31+
const runtimeConfigApiEnabled = await ensureApiEnabled.check(
32+
projectId,
33+
runtimeconfigOrigin(),
34+
"runtimeconfig",
35+
/* silent=*/ true,
36+
);
37+
38+
if (runtimeConfigApiEnabled) {
39+
runtimeConfig = { ...runtimeConfig, ...(await getFunctionsConfig(projectId)) };
40+
}
41+
} catch (err) {
42+
logger.debug("Could not check Runtime Config API status, assuming disabled:", err);
43+
}
44+
}
45+
46+
const wantBuilds = await loadCodebases(
47+
fnConfig,
48+
options,
49+
firebaseConfig,
50+
runtimeConfig,
51+
undefined, // no filters
52+
);
53+
54+
logger.info(JSON.stringify(wantBuilds, null, 2));
55+
return wantBuilds;
2656
});

src/deploy/functions/prepare.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as runtimes from "./runtimes";
1010
import * as supported from "./runtimes/supported";
1111
import * as validate from "./validate";
1212
import * as ensure from "./ensure";
13+
import * as experiments from "../../experiments";
1314
import {
1415
functionsOrigin,
1516
artifactRegistryDomain,
@@ -86,17 +87,18 @@ export async function prepare(
8687
// Get the Firebase Config, and set it on each function in the deployment.
8788
const firebaseConfig = await functionsConfig.getFirebaseConfig(options);
8889
context.firebaseConfig = firebaseConfig;
89-
let runtimeConfig: Record<string, unknown> = { firebase: firebaseConfig };
90-
if (checkAPIsEnabled[1]) {
91-
// If runtime config API is enabled, load the runtime config.
92-
const config = await getFunctionsConfig(projectId);
93-
runtimeConfig = { ...runtimeConfig, ...config };
94-
context.hasRuntimeConfig = Object.keys(config).length > 0;
95-
}
9690

9791
context.codebaseDeployEvents = {};
9892

99-
// ===Phase 1. Load codebases from source.
93+
// ===Phase 1. Load codebases from source with optional runtime config.
94+
let runtimeConfig: Record<string, unknown> = { firebase: firebaseConfig };
95+
const allowFunctionsConfig = experiments.isEnabled("dangerouslyAllowFunctionsConfig");
96+
97+
// Load runtime config if experiment allows it and API is enabled
98+
if (allowFunctionsConfig && checkAPIsEnabled[1]) {
99+
runtimeConfig = { ...runtimeConfig, ...(await getFunctionsConfig(projectId)) };
100+
}
101+
100102
const wantBuilds = await loadCodebases(
101103
context.config,
102104
options,

0 commit comments

Comments
 (0)