firebase-tools-with-isolate 15.30.2 → 15.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/auth-import.js +18 -10
- package/lib/commands/crashlytics-sourcemap-upload.js +2 -1
- package/lib/commands/ext-migrate.js +1 -1
- package/lib/crashlytics/sourcemap.js +35 -5
- package/lib/database/import.js +6 -7
- package/lib/deploy/functions/build.js +0 -1
- package/lib/deploy/functions/containerCleaner.js +1 -7
- package/lib/deploy/functions/params.js +8 -26
- package/lib/deploy/functions/prepare.js +2 -2
- package/lib/deploy/functions/runtimes/python/index.js +48 -17
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/functionsEmulatorUtils.js +0 -4
- package/lib/experiments.js +12 -7
- package/lib/extensions/export.js +21 -11
- package/lib/extensions/replacements.json +15 -22
- package/lib/frameworks/next/index.js +6 -8
- package/lib/functions/kits/install.js +19 -5
- package/lib/functions/python.js +82 -0
- package/lib/gcp/resourceManager.js +1 -1
- package/lib/management/projects.js +14 -0
- package/lib/streamJson.js +36 -0
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +6 -11
- package/templates/init/functions/typescript/index-kit.ts +1 -1
- package/lib/deploy/functions/ensureCloudBuildEnabled.js +0 -1
- package/lib/deploy/functions/runtimes/discovery/mockDiscoveryServer.js +0 -14
- package/lib/firestore/checkDatabaseType.js +0 -24
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.command = void 0;
|
|
4
4
|
const csv_parse_1 = require("csv-parse");
|
|
5
|
-
const Chain = require("stream-chain");
|
|
6
5
|
const clc = require("colorette");
|
|
7
6
|
const fs = require("fs-extra");
|
|
8
|
-
const Pick = require("stream-json/filters/Pick");
|
|
9
|
-
const StreamArray = require("stream-json/streamers/StreamArray");
|
|
10
7
|
const command_1 = require("../command");
|
|
11
8
|
const error_1 = require("../error");
|
|
12
9
|
const logger_1 = require("../logger");
|
|
13
10
|
const projectUtils_1 = require("../projectUtils");
|
|
14
11
|
const requirePermissions_1 = require("../requirePermissions");
|
|
12
|
+
const streamJson_1 = require("../streamJson");
|
|
15
13
|
const accountImporter_1 = require("../accountImporter");
|
|
16
14
|
const MAX_BATCH_SIZE = 1000;
|
|
17
15
|
exports.command = new command_1.Command("auth:import [dataFile]")
|
|
@@ -79,10 +77,12 @@ exports.command = new command_1.Command("auth:import [dataFile]")
|
|
|
79
77
|
});
|
|
80
78
|
}
|
|
81
79
|
else {
|
|
80
|
+
const { chain, pick, streamArray } = await (0, streamJson_1.loadStreamJson)();
|
|
82
81
|
userListArr = await new Promise((resolve, reject) => {
|
|
83
|
-
const pipeline =
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
const pipeline = chain([
|
|
83
|
+
inStream,
|
|
84
|
+
pick.withParser({ filter: /^users$/ }),
|
|
85
|
+
streamArray(),
|
|
86
86
|
({ value }) => {
|
|
87
87
|
counter++;
|
|
88
88
|
const user = (0, accountImporter_1.validateUserJson)(value);
|
|
@@ -97,14 +97,22 @@ exports.command = new command_1.Command("auth:import [dataFile]")
|
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
]);
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
let completed = false;
|
|
101
|
+
const onDone = () => {
|
|
102
|
+
if (completed) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
completed = true;
|
|
102
106
|
if (currentBatch.length) {
|
|
103
107
|
batches.push(currentBatch);
|
|
108
|
+
currentBatch = [];
|
|
104
109
|
}
|
|
105
110
|
resolve(batches);
|
|
106
|
-
}
|
|
107
|
-
|
|
111
|
+
};
|
|
112
|
+
pipeline.once("error", reject);
|
|
113
|
+
pipeline.once("finish", onDone);
|
|
114
|
+
pipeline.once("end", onDone);
|
|
115
|
+
pipeline.resume();
|
|
108
116
|
});
|
|
109
117
|
}
|
|
110
118
|
logger_1.logger.debug(`Preparing to import ${counter} user records in ${userListArr.length} batches.`);
|
|
@@ -41,7 +41,8 @@ exports.command = new command_1.Command("crashlytics:sourcemap:upload [mappingFi
|
|
|
41
41
|
ignoreStrings: ["node_modules", ".git"],
|
|
42
42
|
maxDepth: 20,
|
|
43
43
|
});
|
|
44
|
-
const
|
|
44
|
+
const baseDir = path.basename(filePath) === ".next" ? path.dirname(filePath) : filePath;
|
|
45
|
+
const mappings = await (0, sourcemap_1.findSourceMapMappings)(files, baseDir);
|
|
45
46
|
const result = await (0, sourcemap_1.uploadSourceMaps)(mappings, {
|
|
46
47
|
projectId,
|
|
47
48
|
bucketName,
|
|
@@ -94,7 +94,7 @@ exports.command = new command_1.Command("ext:migrate")
|
|
|
94
94
|
throw new error_1.FirebaseError(`Failed to deploy. Please fix and retry with firebase deploy --only functions:${kitInstanceId}. After success you may remove the old extension with firebase ext:uninstall ${plan.instanceId} --project ${projectId} --immediate`, { original: err instanceof Error ? err : undefined, exit: 1 });
|
|
95
95
|
}
|
|
96
96
|
const shouldUninstall = await (0, prompt_1.confirm)({
|
|
97
|
-
message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. Uninstall it now?`,
|
|
97
|
+
message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. It can take a few minutes for Eventarc to fully provision and new kits to react to events. Uninstall it now?`,
|
|
98
98
|
default: false,
|
|
99
99
|
nonInteractive: options.nonInteractive,
|
|
100
100
|
force: options.force,
|
|
@@ -24,6 +24,8 @@ const utils_1 = require("../utils");
|
|
|
24
24
|
const gcs = require("../gcp/storage");
|
|
25
25
|
const archiveFile_1 = require("../archiveFile");
|
|
26
26
|
exports.CONCURRENCY = 25;
|
|
27
|
+
const ANGULAR_DIST_DIR = "dist";
|
|
28
|
+
const ANGULAR_BROWSER_DIR = "browser";
|
|
27
29
|
function checkGoogleAppID(options) {
|
|
28
30
|
if (!options.app) {
|
|
29
31
|
throw new error_1.FirebaseError("set --app <appId> to a valid Firebase application id, e.g. 1:00000000:android:0000000");
|
|
@@ -287,9 +289,15 @@ async function uploadSourceMaps(mappings, request) {
|
|
|
287
289
|
}
|
|
288
290
|
async function uploadMap(request, attemptsRemaining = 0) {
|
|
289
291
|
const { projectId, mappingFile, obfuscatedFilePath, bucketName, appVersion, options } = request;
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
292
|
+
const rootDir = options.projectRoot ?? process.cwd();
|
|
293
|
+
const relativeToRoot = path.relative(rootDir, mappingFile);
|
|
294
|
+
const resolvedCheckPath = path.resolve(rootDir, relativeToRoot);
|
|
295
|
+
const filePath = !fs.existsSync(resolvedCheckPath) && fs.existsSync(mappingFile) ? mappingFile : relativeToRoot;
|
|
296
|
+
const pathSegments = obfuscatedFilePath.split(path.sep);
|
|
297
|
+
const browserIndex = pathSegments.lastIndexOf(ANGULAR_BROWSER_DIR);
|
|
298
|
+
const isAngularBuildDir = filePath.split(path.sep).includes(ANGULAR_DIST_DIR);
|
|
299
|
+
const normalizedSegments = isAngularBuildDir && browserIndex !== -1 ? pathSegments.slice(browserIndex + 1) : pathSegments;
|
|
300
|
+
const obfuscatedPath = normalizedSegments
|
|
293
301
|
.map((p) => (p === ".next" ? "_next" : p))
|
|
294
302
|
.filter((p) => p !== "dev")
|
|
295
303
|
.join("/");
|
|
@@ -338,22 +346,44 @@ async function uploadMap(request, attemptsRemaining = 0) {
|
|
|
338
346
|
function normalizeFileName(fileName) {
|
|
339
347
|
return fileName.replaceAll(/\//g, "-");
|
|
340
348
|
}
|
|
349
|
+
function isAlreadyExistsError(e) {
|
|
350
|
+
if (e.status !== 400) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
const message = e.message.toLowerCase();
|
|
354
|
+
const bodyMessage = (e.context?.body?.error?.message ?? "").toLowerCase();
|
|
355
|
+
return message.includes("already exists") || bodyMessage.includes("already exists");
|
|
356
|
+
}
|
|
341
357
|
async function registerSourceMap(sourceMap) {
|
|
342
358
|
const client = new apiv2_1.Client({
|
|
343
359
|
urlPrefix: "https://firebasetelemetryadmin.googleapis.com",
|
|
344
360
|
auth: true,
|
|
345
361
|
apiVersion: "v1alpha",
|
|
346
362
|
});
|
|
347
|
-
|
|
363
|
+
const patchSourceMap = async () => {
|
|
348
364
|
await client.patch(sourceMap.name, sourceMap, { queryParams: { allowMissing: "true" } });
|
|
349
365
|
logger_1.logger.debug(`Registered source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service`);
|
|
366
|
+
};
|
|
367
|
+
try {
|
|
368
|
+
await patchSourceMap();
|
|
350
369
|
}
|
|
351
370
|
catch (e) {
|
|
352
371
|
if (e instanceof error_1.FirebaseError) {
|
|
353
372
|
if (e.status === 409) {
|
|
354
373
|
return;
|
|
355
374
|
}
|
|
375
|
+
if (isAlreadyExistsError(e)) {
|
|
376
|
+
try {
|
|
377
|
+
logger_1.logger.debug(`Source map ${sourceMap.obfuscatedFilePath} already exists, deleting and re-registering`);
|
|
378
|
+
await client.delete(sourceMap.name);
|
|
379
|
+
await patchSourceMap();
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
catch (retryErr) {
|
|
383
|
+
throw new error_1.FirebaseError(`Failed to register source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service:\n${retryErr instanceof Error ? retryErr.message : String(retryErr)}`, { original: retryErr instanceof Error ? retryErr : undefined });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
356
386
|
}
|
|
357
|
-
throw new error_1.FirebaseError(`Failed to register source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service:\n${e instanceof Error ? e.message : String(e)}
|
|
387
|
+
throw new error_1.FirebaseError(`Failed to register source map ${sourceMap.obfuscatedFilePath} with Firebase Telemetry service:\n${e instanceof Error ? e.message : String(e)}`, { original: e instanceof Error ? e : undefined });
|
|
358
388
|
}
|
|
359
389
|
}
|
package/lib/database/import.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Chain = require("stream-chain");
|
|
4
3
|
const clc = require("colorette");
|
|
5
|
-
const Filter = require("stream-json/filters/Filter");
|
|
6
4
|
const stream = require("stream");
|
|
7
|
-
const StreamObject = require("stream-json/streamers/StreamObject");
|
|
8
5
|
const apiv2_1 = require("../apiv2");
|
|
9
6
|
const error_1 = require("../error");
|
|
7
|
+
const streamJson_1 = require("../streamJson");
|
|
10
8
|
const utils_1 = require("../utils");
|
|
11
9
|
class BatchChunks extends stream.Transform {
|
|
12
10
|
constructor(maxSize, opts) {
|
|
@@ -109,7 +107,8 @@ class DatabaseImporter {
|
|
|
109
107
|
", then rerun this command.", { exit: 2 });
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
|
-
readAndWriteChunks() {
|
|
110
|
+
async readAndWriteChunks() {
|
|
111
|
+
const { chain, filter, streamObject } = await (0, streamJson_1.loadStreamJson)();
|
|
113
112
|
const { dbUrl, payloadSize } = this;
|
|
114
113
|
const chunkData = this.chunkData.bind(this);
|
|
115
114
|
const doWriteBatch = this.doWriteBatch.bind(this);
|
|
@@ -132,13 +131,13 @@ class DatabaseImporter {
|
|
|
132
131
|
};
|
|
133
132
|
return new Promise((resolve, reject) => {
|
|
134
133
|
const responses = [];
|
|
135
|
-
const pipeline =
|
|
134
|
+
const pipeline = chain([
|
|
136
135
|
this.inStream,
|
|
137
|
-
|
|
136
|
+
filter.withParser({
|
|
138
137
|
filter: this.computeFilterString(this.dataPath) || (() => true),
|
|
139
138
|
pathSeparator: "/",
|
|
140
139
|
}),
|
|
141
|
-
|
|
140
|
+
streamObject(),
|
|
142
141
|
]);
|
|
143
142
|
pipeline
|
|
144
143
|
.on("error", (err) => reject(new error_1.FirebaseError(`Invalid data; couldn't parse JSON object, array, or value. ${err.message}`, {
|
|
@@ -92,7 +92,6 @@ async function resolveBackend(opts) {
|
|
|
92
92
|
userEnvs: envWithTypes(opts.build.params, opts.userEnvs),
|
|
93
93
|
codebase: opts.codebase,
|
|
94
94
|
nonInteractive: opts.nonInteractive,
|
|
95
|
-
force: opts.force,
|
|
96
95
|
isEmulator: opts.isEmulator,
|
|
97
96
|
});
|
|
98
97
|
return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DockerHelper = exports.ContainerRegistryCleaner = exports.
|
|
3
|
+
exports.DockerHelper = exports.ContainerRegistryCleaner = exports.ArtifactRegistryCleaner = void 0;
|
|
4
4
|
exports.cleanupBuildImages = cleanupBuildImages;
|
|
5
5
|
exports.listGcfPaths = listGcfPaths;
|
|
6
6
|
exports.deleteGcfArtifacts = deleteGcfArtifacts;
|
|
@@ -134,12 +134,6 @@ ArtifactRegistryCleaner.POLLER_OPTIONS = {
|
|
|
134
134
|
apiVersion: artifactregistry.API_VERSION,
|
|
135
135
|
masterTimeout: 5 * 60 * 1000,
|
|
136
136
|
};
|
|
137
|
-
class NoopArtifactRegistryCleaner extends ArtifactRegistryCleaner {
|
|
138
|
-
cleanupFunction() {
|
|
139
|
-
return Promise.resolve();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.NoopArtifactRegistryCleaner = NoopArtifactRegistryCleaner;
|
|
143
137
|
class ContainerRegistryCleaner {
|
|
144
138
|
constructor() {
|
|
145
139
|
this.helpers = {};
|
|
@@ -16,7 +16,6 @@ const logger_1 = require("../../logger");
|
|
|
16
16
|
const error_1 = require("../../error");
|
|
17
17
|
const prompt_1 = require("../../prompt");
|
|
18
18
|
const secrets_1 = require("../../functions/secrets");
|
|
19
|
-
const build = require("./build");
|
|
20
19
|
const functional_1 = require("../../functional");
|
|
21
20
|
const secretManager = require("../../gcp/secretManager");
|
|
22
21
|
const storage_1 = require("../../gcp/storage");
|
|
@@ -169,7 +168,7 @@ function canSatisfyParam(param, value) {
|
|
|
169
168
|
(0, functional_1.assertExhaustive)(param);
|
|
170
169
|
}
|
|
171
170
|
async function resolveParams(opts) {
|
|
172
|
-
const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false,
|
|
171
|
+
const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false, isEmulator = false, } = opts;
|
|
173
172
|
const paramValues = populateDefaultParams(firebaseConfig);
|
|
174
173
|
const secretRefs = {};
|
|
175
174
|
const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
|
|
@@ -181,7 +180,7 @@ async function resolveParams(opts) {
|
|
|
181
180
|
const [needSecret, needPrompt] = (0, functional_1.partition)(outstanding, (param) => param.type === "secret");
|
|
182
181
|
if (!isEmulator) {
|
|
183
182
|
for (const param of needSecret) {
|
|
184
|
-
secretRefs[param.name] = await ensureSecret(param, firebaseConfig.projectId, nonInteractive
|
|
183
|
+
secretRefs[param.name] = await ensureSecret(param, firebaseConfig.projectId, nonInteractive);
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
if (nonInteractive && needPrompt.length > 0) {
|
|
@@ -234,7 +233,7 @@ function populateDefaultParams(config) {
|
|
|
234
233
|
}
|
|
235
234
|
return defaultParams;
|
|
236
235
|
}
|
|
237
|
-
async function ensureSecret(secretParam, projectId, nonInteractive
|
|
236
|
+
async function ensureSecret(secretParam, projectId, nonInteractive) {
|
|
238
237
|
const resourceId = secretParam.resourceId || secretParam.name;
|
|
239
238
|
const version = secretParam.version || "latest";
|
|
240
239
|
let secretAlreadyExisted = false;
|
|
@@ -245,25 +244,6 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
|
|
|
245
244
|
"Set this secret before deploying:\n" +
|
|
246
245
|
`\tfirebase functions:secrets:set ${resourceId}${secretParam.format === "json" ? " --format=json --data-file <file.json>" : ""}`);
|
|
247
246
|
}
|
|
248
|
-
if (experiments.isEnabled("secretEnvParams") && typeof secretParam.resourceId === "undefined") {
|
|
249
|
-
if (force) {
|
|
250
|
-
logger_1.logger.info(`--force: Using default resource ID for secret ${secretParam.name}`);
|
|
251
|
-
secretParam.resourceId = secretParam.name;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
secretParam.resourceId = await (0, prompt_1.input)({
|
|
255
|
-
default: secretParam.name,
|
|
256
|
-
message: `What resource ID do you want to use for the backing Secret resource for secret param ${secretParam.name}?`,
|
|
257
|
-
validate: (id) => {
|
|
258
|
-
if (new RegExp(`^${build.GCP_SECRET_ID_PATTERN}$`).test(id)) {
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
return "GCP Secret identifiers must contain only letters, numbers, underscores, and hyphens.";
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
return ensureSecret(secretParam, projectId, nonInteractive, force);
|
|
266
|
-
}
|
|
267
247
|
const label = secretParam.label || secretParam.name;
|
|
268
248
|
const notice = `The value for this secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}.`;
|
|
269
249
|
const desc = secretParam.description ? `${secretParam.description} ${notice}` : notice;
|
|
@@ -289,7 +269,8 @@ async function ensureSecret(secretParam, projectId, nonInteractive, force) {
|
|
|
289
269
|
secretAlreadyExisted = true;
|
|
290
270
|
}
|
|
291
271
|
const secretRefString = typeof version === "undefined" ? resourceId : `${resourceId}:${version}`;
|
|
292
|
-
if (experiments.isEnabled("secretEnvParams")
|
|
272
|
+
if (experiments.isEnabled("secretEnvParams") &&
|
|
273
|
+
experiments.isEnabled("writeDefaultSecretBindings")) {
|
|
293
274
|
if (!secretParam.inLocalEnvironment && secretAlreadyExisted) {
|
|
294
275
|
logger_1.logger.info(`Onetime (firebase-tools x.y.z+): storing a reference to existing secret ${secretParam.name}=${secretRefString} in .env files.`);
|
|
295
276
|
}
|
|
@@ -504,7 +485,7 @@ async function promptText(prompt, textInput, resolvedDefault, enforceNonEmpty =
|
|
|
504
485
|
}
|
|
505
486
|
async function promptSelect(prompt, input, resolvedDefault, converter) {
|
|
506
487
|
const response = await (0, prompt_1.select)({
|
|
507
|
-
default: resolvedDefault,
|
|
488
|
+
default: resolvedDefault?.toString(),
|
|
508
489
|
message: prompt,
|
|
509
490
|
instructions: "(Use arrow keys to navigate, and Enter to confirm your choice)",
|
|
510
491
|
choices: input.select.options.map((option) => {
|
|
@@ -523,13 +504,14 @@ async function promptSelect(prompt, input, resolvedDefault, converter) {
|
|
|
523
504
|
return converted;
|
|
524
505
|
}
|
|
525
506
|
async function promptSelectMultiple(prompt, input, resolvedDefault, enforceNonEmpty = false, converter) {
|
|
507
|
+
const preselected = new Set((resolvedDefault ?? []).map(String));
|
|
526
508
|
const response = await (0, prompt_1.checkbox)({
|
|
527
509
|
default: resolvedDefault,
|
|
528
510
|
message: prompt,
|
|
529
511
|
instructions: "(Press Space to select, and Enter to confirm your choices)",
|
|
530
512
|
choices: input.multiSelect.options.map((option) => {
|
|
531
513
|
return {
|
|
532
|
-
checked:
|
|
514
|
+
checked: preselected.has(option.value.toString()),
|
|
533
515
|
name: option.label,
|
|
534
516
|
value: option.value.toString(),
|
|
535
517
|
};
|
|
@@ -218,11 +218,11 @@ async function prepare(context, options, payload) {
|
|
|
218
218
|
userEnvs,
|
|
219
219
|
codebase,
|
|
220
220
|
nonInteractive: options.nonInteractive,
|
|
221
|
-
force: options.force,
|
|
222
221
|
isEmulator: false,
|
|
223
222
|
});
|
|
224
223
|
functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
|
|
225
|
-
if (experiments.isEnabled("secretEnvParams")
|
|
224
|
+
if (experiments.isEnabled("secretEnvParams") &&
|
|
225
|
+
experiments.isEnabled("writeDefaultSecretBindings")) {
|
|
226
226
|
functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
|
|
227
227
|
}
|
|
228
228
|
let hasEnvsFromParams = false;
|
|
@@ -13,6 +13,10 @@ const logger_1 = require("../../../../logger");
|
|
|
13
13
|
const python_1 = require("../../../../functions/python");
|
|
14
14
|
const error_1 = require("../../../../error");
|
|
15
15
|
const functional_1 = require("../../../../functional");
|
|
16
|
+
const utils_1 = require("../../../../utils");
|
|
17
|
+
const FORCE_KILL_DELAY_MS = 10000;
|
|
18
|
+
const SHUTDOWN_TIMEOUT_MS = 15000;
|
|
19
|
+
const QUITQUITQUIT_TIMEOUT_MS = 5000;
|
|
16
20
|
async function tryCreateDelegate(context) {
|
|
17
21
|
const requirementsTextPath = path.join(context.sourceDir, "requirements.txt");
|
|
18
22
|
if (!(await (0, util_1.promisify)(fs.exists)(requirementsTextPath))) {
|
|
@@ -120,31 +124,58 @@ class Delegate {
|
|
|
120
124
|
};
|
|
121
125
|
const args = [this.bin, `"${path.join(modulesDir, "private", "serving.py")}"`];
|
|
122
126
|
logger_1.logger.debug(`Running admin server with args: ${JSON.stringify(args)} and env: ${JSON.stringify(envWithAdminPort)} in ${this.sourceDir}`);
|
|
123
|
-
const childProcess = (0, python_1.runWithVirtualEnv)(args, this.sourceDir, envWithAdminPort
|
|
127
|
+
const childProcess = (0, python_1.runWithVirtualEnv)(args, this.sourceDir, envWithAdminPort, {
|
|
128
|
+
detached: !utils_1.IS_WINDOWS,
|
|
129
|
+
});
|
|
124
130
|
childProcess.stdout?.on("data", (chunk) => {
|
|
125
131
|
logger_1.logger.info(chunk.toString("utf8"));
|
|
126
132
|
});
|
|
127
133
|
childProcess.stderr?.on("data", (chunk) => {
|
|
128
134
|
logger_1.logger.error(chunk.toString("utf8"));
|
|
129
135
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}, 10000);
|
|
142
|
-
clearTimeout(quitTimeout);
|
|
143
|
-
return new Promise((resolve, reject) => {
|
|
144
|
-
childProcess.once("exit", resolve);
|
|
145
|
-
childProcess.once("error", reject);
|
|
136
|
+
const exited = new Promise((resolve) => {
|
|
137
|
+
childProcess.once("exit", () => resolve());
|
|
138
|
+
childProcess.once("error", () => resolve());
|
|
139
|
+
});
|
|
140
|
+
(0, python_1.trackVirtualEnvChild)(childProcess);
|
|
141
|
+
return Promise.resolve(() => this.shutdownAdmin(childProcess, port, exited));
|
|
142
|
+
}
|
|
143
|
+
async shutdownAdmin(childProcess, port, exited) {
|
|
144
|
+
try {
|
|
145
|
+
await fetch(`http://127.0.0.1:${port}/__/quitquitquit`, {
|
|
146
|
+
signal: AbortSignal.timeout(QUITQUITQUIT_TIMEOUT_MS),
|
|
146
147
|
});
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
logger_1.logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
|
|
151
|
+
}
|
|
152
|
+
const forceKill = setTimeout(() => {
|
|
153
|
+
if (childProcess.pid) {
|
|
154
|
+
logger_1.logger.debug(`Discovery admin server on port ${port} did not shut down when asked. Force-killing it.`);
|
|
155
|
+
(0, python_1.killProcessTree)(childProcess.pid);
|
|
156
|
+
}
|
|
157
|
+
}, FORCE_KILL_DELAY_MS);
|
|
158
|
+
let giveUp;
|
|
159
|
+
const timedOut = new Promise((resolve) => {
|
|
160
|
+
giveUp = setTimeout(() => resolve(false), SHUTDOWN_TIMEOUT_MS);
|
|
147
161
|
});
|
|
162
|
+
try {
|
|
163
|
+
const exitedCleanly = await Promise.race([exited.then(() => true), timedOut]);
|
|
164
|
+
if (exitedCleanly) {
|
|
165
|
+
(0, python_1.untrackVirtualEnvChild)(childProcess);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
logger_1.logger.debug(`Discovery admin server on port ${port} survived being force-killed. ` +
|
|
169
|
+
`Continuing without it; it may need to be cleaned up manually.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
clearTimeout(forceKill);
|
|
174
|
+
clearTimeout(giveUp);
|
|
175
|
+
childProcess.stdout?.destroy();
|
|
176
|
+
childProcess.stderr?.destroy();
|
|
177
|
+
childProcess.unref();
|
|
178
|
+
}
|
|
148
179
|
}
|
|
149
180
|
async discoverBuild(_configValues, envs) {
|
|
150
181
|
let discovered = await discovery.detectFromYaml(this.sourceDir, this.projectId, this.runtime);
|
|
@@ -54,36 +54,36 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
|
57
|
-
"version": "3.4.
|
|
58
|
-
"expectedSize":
|
|
59
|
-
"expectedChecksum": "
|
|
60
|
-
"expectedChecksumSHA256": "
|
|
61
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.
|
|
62
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
57
|
+
"version": "3.4.21",
|
|
58
|
+
"expectedSize": 33807728,
|
|
59
|
+
"expectedChecksum": "c9830bf36efd861a179a7d0f1b476d96",
|
|
60
|
+
"expectedChecksumSHA256": "3862f23631fa99ea5114fd59b968b081bab5ac372867591b2d421864f4b30cf7",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.21",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.21"
|
|
63
63
|
},
|
|
64
64
|
"darwin_arm64": {
|
|
65
|
-
"version": "3.4.
|
|
66
|
-
"expectedSize":
|
|
67
|
-
"expectedChecksum": "
|
|
68
|
-
"expectedChecksumSHA256": "
|
|
69
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.
|
|
70
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
65
|
+
"version": "3.4.21",
|
|
66
|
+
"expectedSize": 31900354,
|
|
67
|
+
"expectedChecksum": "06baade26a1f16728b6278c5b39166a7",
|
|
68
|
+
"expectedChecksumSHA256": "b5df8bb2c55535d77a07b90f4c8120975afb3bac39bacfc74cb945fb8e828378",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.21",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.21"
|
|
71
71
|
},
|
|
72
72
|
"win32": {
|
|
73
|
-
"version": "3.4.
|
|
74
|
-
"expectedSize":
|
|
75
|
-
"expectedChecksum": "
|
|
76
|
-
"expectedChecksumSHA256": "
|
|
77
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.
|
|
78
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
73
|
+
"version": "3.4.21",
|
|
74
|
+
"expectedSize": 33837056,
|
|
75
|
+
"expectedChecksum": "dbe075ff9320eb9783481f74beccafee",
|
|
76
|
+
"expectedChecksumSHA256": "72ddbf8418f54d5e7827204ac3ac88c80a42e445ee0afd1a021cb2dad9196eb0",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.21",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.21.exe"
|
|
79
79
|
},
|
|
80
80
|
"linux": {
|
|
81
|
-
"version": "3.4.
|
|
82
|
-
"expectedSize":
|
|
83
|
-
"expectedChecksum": "
|
|
84
|
-
"expectedChecksumSHA256": "
|
|
85
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.
|
|
86
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
81
|
+
"version": "3.4.21",
|
|
82
|
+
"expectedSize": 32927928,
|
|
83
|
+
"expectedChecksum": "5b42b3b114d52bec9962f5ba2f8548c7",
|
|
84
|
+
"expectedChecksumSHA256": "504a5a751a4e3ac6851d6e5dc70caefee698570ead7fe2ef324019dc54c6c473",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.21",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.21"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.extractParamsFromPath = extractParamsFromPath;
|
|
4
4
|
exports.isValidWildcardMatch = isValidWildcardMatch;
|
|
5
5
|
exports.trimSlashes = trimSlashes;
|
|
6
|
-
exports.removePathSegments = removePathSegments;
|
|
7
6
|
exports.parseRuntimeVersion = parseRuntimeVersion;
|
|
8
7
|
exports.parseVersionString = parseVersionString;
|
|
9
8
|
exports.compareVersionStrings = compareVersionStrings;
|
|
@@ -47,9 +46,6 @@ function trimSlashes(str) {
|
|
|
47
46
|
.filter((c) => c)
|
|
48
47
|
.join("/");
|
|
49
48
|
}
|
|
50
|
-
function removePathSegments(path, count) {
|
|
51
|
-
return trimSlashes(path).split("/").slice(count).join("/");
|
|
52
|
-
}
|
|
53
49
|
function parseRuntimeVersion(runtime) {
|
|
54
50
|
if (!runtime) {
|
|
55
51
|
return undefined;
|
package/lib/experiments.js
CHANGED
|
@@ -81,8 +81,8 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
81
81
|
kits: {
|
|
82
82
|
shortDescription: "Enable Functions Kits.",
|
|
83
83
|
fullDescription: "Adds support for Function Kits.",
|
|
84
|
-
public:
|
|
85
|
-
default:
|
|
84
|
+
public: true,
|
|
85
|
+
default: true,
|
|
86
86
|
},
|
|
87
87
|
emulatoruisnapshot: {
|
|
88
88
|
shortDescription: "Load pre-release versions of the emulator UI",
|
|
@@ -207,9 +207,9 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
207
207
|
public: true,
|
|
208
208
|
},
|
|
209
209
|
secretEnvParams: {
|
|
210
|
-
shortDescription: "Enable
|
|
211
|
-
default:
|
|
212
|
-
public:
|
|
210
|
+
shortDescription: "Enable reading the backing resource binding for a Functions secret param from .env",
|
|
211
|
+
default: true,
|
|
212
|
+
public: true,
|
|
213
213
|
},
|
|
214
214
|
extdeprecationwarnings: {
|
|
215
215
|
shortDescription: "Show deprecation warnings for Firebase Extensions CLI commands.",
|
|
@@ -218,8 +218,8 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
218
218
|
},
|
|
219
219
|
extMigrationFeatures: {
|
|
220
220
|
shortDescription: "Enable features intended to assist with the migration of Extension instances to Kits.",
|
|
221
|
-
default:
|
|
222
|
-
public:
|
|
221
|
+
default: true,
|
|
222
|
+
public: true,
|
|
223
223
|
},
|
|
224
224
|
fdcapimigration: {
|
|
225
225
|
shortDescription: "Enable the FDC API schema migration path.",
|
|
@@ -227,6 +227,11 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
227
227
|
default: false,
|
|
228
228
|
public: false,
|
|
229
229
|
},
|
|
230
|
+
writeDefaultSecretBindings: {
|
|
231
|
+
shortDescription: "Write Cloud Secret Manager bindings to the default resource ID to .env.",
|
|
232
|
+
default: false,
|
|
233
|
+
public: false,
|
|
234
|
+
},
|
|
230
235
|
});
|
|
231
236
|
function isValidExperiment(name) {
|
|
232
237
|
return Object.keys(exports.ALL_EXPERIMENTS).includes(name);
|
package/lib/extensions/export.js
CHANGED
|
@@ -121,16 +121,30 @@ function resolveMigratedMemory(liveSystemParams = {}, specSystemParams = []) {
|
|
|
121
121
|
}
|
|
122
122
|
return v2 ?? v1;
|
|
123
123
|
}
|
|
124
|
+
function resolveLiveSecret(specParam, liveParams) {
|
|
125
|
+
const val = liveParams[specParam.param];
|
|
126
|
+
if (!val && !specParam.required) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
if (!val) {
|
|
130
|
+
throw new error_1.FirebaseError(`Secret ${specParam.param} was defined in the extension spec, but is missing in live deployed secrets.`, { exit: 1 });
|
|
131
|
+
}
|
|
132
|
+
return val;
|
|
133
|
+
}
|
|
124
134
|
function functionsEnvFromInstance(instance) {
|
|
125
135
|
const liveParams = instance.config?.params || {};
|
|
126
136
|
const liveSystemParams = instance.config?.systemParams || {};
|
|
127
137
|
const specParams = instance.config?.source?.spec?.params || [];
|
|
128
138
|
const specSystemParams = instance.config?.source?.spec?.systemParams || [];
|
|
129
139
|
const envs = {};
|
|
130
|
-
|
|
140
|
+
for (const specParam of specParams) {
|
|
131
141
|
if (specParam.type === "SECRET") {
|
|
142
|
+
const val = resolveLiveSecret(specParam, liveParams);
|
|
143
|
+
if (!val) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
132
146
|
const renamed = "FIREBASE_SECRET_REF_" + specParam.param;
|
|
133
|
-
envs[renamed] =
|
|
147
|
+
envs[renamed] = val;
|
|
134
148
|
}
|
|
135
149
|
else if (specParam.param in liveParams) {
|
|
136
150
|
envs[specParam.param] = liveParams[specParam.param];
|
|
@@ -138,7 +152,7 @@ function functionsEnvFromInstance(instance) {
|
|
|
138
152
|
else {
|
|
139
153
|
envs[specParam.param] = specParam.default ?? "";
|
|
140
154
|
}
|
|
141
|
-
}
|
|
155
|
+
}
|
|
142
156
|
for (const [sysParamName, sysParamValue] of Object.entries(liveSystemParams)) {
|
|
143
157
|
if (MEMORY_PARAMS.has(sysParamName)) {
|
|
144
158
|
continue;
|
|
@@ -181,12 +195,9 @@ async function secretsNeedingEjection(instance) {
|
|
|
181
195
|
const liveParams = instance.config?.params || {};
|
|
182
196
|
const secretParams = (instance.config?.source?.spec?.params ?? []).filter((p) => p.type === "SECRET");
|
|
183
197
|
const checks = secretParams.map(async (specParam) => {
|
|
184
|
-
const
|
|
185
|
-
const resourceName = liveParams[secretName];
|
|
198
|
+
const resourceName = resolveLiveSecret(specParam, liveParams);
|
|
186
199
|
if (!resourceName) {
|
|
187
|
-
|
|
188
|
-
secretName +
|
|
189
|
-
" was defined in the extension spec, but is missing in live deployed secrets.", { exit: 1 });
|
|
200
|
+
return undefined;
|
|
190
201
|
}
|
|
191
202
|
const match = resourceName.match(secretManager_1.SECRET_VERSION_NAME_REGEX);
|
|
192
203
|
if (!match?.groups) {
|
|
@@ -208,10 +219,9 @@ async function ejectSecretsFromInstance(instance) {
|
|
|
208
219
|
if (specParam.type !== "SECRET") {
|
|
209
220
|
continue;
|
|
210
221
|
}
|
|
211
|
-
const
|
|
212
|
-
const resourceName = liveParams[secretName];
|
|
222
|
+
const resourceName = resolveLiveSecret(specParam, liveParams);
|
|
213
223
|
if (!resourceName) {
|
|
214
|
-
|
|
224
|
+
continue;
|
|
215
225
|
}
|
|
216
226
|
const match = resourceName.match(secretManager_1.SECRET_VERSION_NAME_REGEX);
|
|
217
227
|
if (!match?.groups) {
|