firebase-tools 15.34.1 → 15.35.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/api.js +2 -4
- package/lib/apphosting/constants.js +1 -4
- package/lib/apphosting/utils.js +0 -26
- package/lib/commands/apps-android-sha-create.js +1 -1
- package/lib/commands/apps-android-sha-delete.js +1 -1
- package/lib/commands/apps-android-sha-list.js +1 -1
- package/lib/commands/{crashlytics-onboard-web.js → crashlytics-setup.js} +5 -5
- package/lib/commands/crashlytics-sourcemap-upload.js +4 -0
- package/lib/commands/emulators-start.js +2 -2
- package/lib/commands/index.js +5 -6
- package/lib/commands/run-services-get.js +19 -0
- package/lib/commands/run-services-list.js +11 -0
- package/lib/crashlytics/alerts.js +1 -0
- package/lib/crashlytics/firebasetelemetry.js +5 -3
- package/lib/crashlytics/onboarding.js +15 -23
- package/lib/crashlytics/reports.js +46 -17
- package/lib/crashlytics/sourcemap.js +19 -5
- package/lib/dataconnect/dataplaneClient.js +0 -10
- package/lib/deploy/apphosting/deploy.js +20 -41
- package/lib/deploy/apphosting/localBuild.js +49 -0
- package/lib/deploy/apphosting/prepare.js +12 -25
- package/lib/deploy/apphosting/release.js +1 -1
- package/lib/deploy/apphosting/util.js +27 -4
- package/lib/deploy/functions/containerCleaner.js +1 -142
- package/lib/deploy/functions/functionsDeployHelper.js +0 -4
- package/lib/deploy/functions/release/fabricator.js +6 -3
- package/lib/deploy/functions/validate.js +1 -1
- package/lib/deploy/run/deploy.js +26 -43
- package/lib/deploy/run/get.js +30 -0
- package/lib/deploy/run/list.js +38 -0
- package/lib/deploy/run/prereqs.js +0 -3
- package/lib/deploy/run/util.js +9 -0
- package/lib/emulator/commandUtils.js +105 -23
- package/lib/emulator/dataconnect/pgliteServer.js +1 -0
- package/lib/emulator/downloadableEmulatorInfo.json +22 -22
- package/lib/emulator/downloadableEmulators.js +43 -5
- package/lib/emulator/firestoreEmulator.js +5 -0
- package/lib/emulator/functionsEmulator.js +22 -7
- package/lib/emulator/pubsubEmulator.js +64 -11
- package/lib/emulator/storage/rules/manager.js +31 -15
- package/lib/emulator/storage/rules/runtime.js +1 -0
- package/lib/emulator/taskQueue.js +5 -4
- package/lib/experiments.js +0 -5
- package/lib/extensions/emulator/specHelper.js +0 -4
- package/lib/extensions/extensionsApi.js +0 -8
- package/lib/extensions/extensionsHelper.js +1 -71
- package/lib/extensions/runtimes/common.js +0 -12
- package/lib/extensions/secretsUtils.js +0 -24
- package/lib/extensions/updateHelper.js +2 -88
- package/lib/frameworks/angular/utils.js +3 -2
- package/lib/frameworks/next/utils.js +0 -11
- package/lib/fsAsync.js +34 -20
- package/lib/functions/kits/install.js +37 -337
- package/lib/functions/kits/sources/directory.js +59 -0
- package/lib/functions/kits/sources/index.js +19 -0
- package/lib/functions/kits/sources/npm.js +274 -0
- package/lib/functions/kits/sources/types.js +12 -0
- package/lib/gcp/artifactregistry.js +0 -5
- package/lib/gcp/cloudlogging.js +0 -54
- package/lib/gcp/iam.js +0 -4
- package/lib/gcp/pubsub.js +0 -14
- package/lib/gcp/storage.js +2 -1
- package/lib/init/features/aitools/promptUpdater.js +3 -2
- package/lib/init/features/run.js +3 -7
- package/lib/mcp/errors.js +1 -1
- package/lib/mcp/resources/guides/crashlytics_reports.js +33 -71
- package/lib/mcp/tools/crashlytics/reports.js +25 -30
- package/lib/mcp/util/dataconnect/converter.js +0 -29
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +9 -6
- package/lib/apphosting/repo.js +0 -243
- package/lib/deploy/hosting/args.js +0 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = default_1;
|
|
4
|
-
const fs = require("fs");
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const error_1 = require("../../error");
|
|
7
6
|
const gcs = require("../../gcp/storage");
|
|
@@ -10,8 +9,6 @@ const projectUtils_1 = require("../../projectUtils");
|
|
|
10
9
|
const utils_1 = require("../../utils");
|
|
11
10
|
const util = require("./util");
|
|
12
11
|
const experiments = require("../../experiments");
|
|
13
|
-
const logger_1 = require("../../logger");
|
|
14
|
-
const constants_1 = require("../../apphosting/constants");
|
|
15
12
|
async function default_1(context, options) {
|
|
16
13
|
if (Object.entries(context.backendConfigs).length === 0) {
|
|
17
14
|
return;
|
|
@@ -54,46 +51,28 @@ async function default_1(context, options) {
|
|
|
54
51
|
}));
|
|
55
52
|
await Promise.all(Object.values(context.backendConfigs).map(async (cfg) => {
|
|
56
53
|
const rootDir = options.projectRoot ?? process.cwd();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
outputFiles = localBuild?.outputFiles;
|
|
65
|
-
localBuildScratchDir = localBuild?.localBuildScratchDir;
|
|
66
|
-
if (!outputFiles || !localBuildScratchDir) {
|
|
67
|
-
throw new error_1.FirebaseError(`No local build output files found for ${cfg.backendId}`);
|
|
68
|
-
}
|
|
54
|
+
const isLocalBuild = cfg.localBuild;
|
|
55
|
+
let archive;
|
|
56
|
+
if (isLocalBuild) {
|
|
57
|
+
experiments.assertEnabled("apphostinglocalbuilds", "App Hosting local builds");
|
|
58
|
+
archive = context.backendLocalBuilds[cfg.backendId]?.archive;
|
|
59
|
+
if (!archive) {
|
|
60
|
+
throw new error_1.FirebaseError(`No local build output files found for ${cfg.backendId}`);
|
|
69
61
|
}
|
|
70
|
-
const zippedSourcePath = isLocalBuild
|
|
71
|
-
? await util.createLocalBuildTarArchive(cfg, localBuildScratchDir, outputFiles ?? [])
|
|
72
|
-
: await util.createSourceDeployArchive(cfg, rootDir);
|
|
73
|
-
(0, utils_1.logLabeledBullet)("apphosting", `Zipped ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}`);
|
|
74
|
-
const backendLocation = context.backendLocations[cfg.backendId];
|
|
75
|
-
if (!backendLocation) {
|
|
76
|
-
throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
|
|
77
|
-
}
|
|
78
|
-
(0, utils_1.logLabeledBullet)("apphosting", `Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`);
|
|
79
|
-
const bucketName = bucketsPerLocation[backendLocation];
|
|
80
|
-
const { bucket, object } = await gcs.uploadObject({
|
|
81
|
-
file: zippedSourcePath,
|
|
82
|
-
stream: fs.createReadStream(zippedSourcePath),
|
|
83
|
-
}, bucketName, isLocalBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP, isLocalBuild ? constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES : undefined);
|
|
84
|
-
(0, utils_1.logLabeledBullet)("apphosting", `Uploaded at gs://${bucket}/${object}`);
|
|
85
|
-
context.backendStorageUris[cfg.backendId] =
|
|
86
|
-
`gs://${bucketName}/${path.basename(zippedSourcePath)}`;
|
|
87
62
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
63
|
+
const zippedSourcePath = archive ?? (await util.createSourceDeployArchive(cfg, rootDir));
|
|
64
|
+
if (!archive) {
|
|
65
|
+
(0, utils_1.logLabeledBullet)("apphosting", `Zipped source for backend ${cfg.backendId}`);
|
|
66
|
+
}
|
|
67
|
+
const backendLocation = context.backendLocations[cfg.backendId];
|
|
68
|
+
if (!backendLocation) {
|
|
69
|
+
throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
|
|
97
70
|
}
|
|
71
|
+
(0, utils_1.logLabeledBullet)("apphosting", `Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`);
|
|
72
|
+
const bucketName = bucketsPerLocation[backendLocation];
|
|
73
|
+
const { bucket, object } = await util.uploadArchive(zippedSourcePath, bucketName, !!isLocalBuild);
|
|
74
|
+
(0, utils_1.logLabeledBullet)("apphosting", `Uploaded at gs://${bucket}/${object}`);
|
|
75
|
+
context.backendStorageUris[cfg.backendId] =
|
|
76
|
+
`gs://${bucketName}/${path.basename(zippedSourcePath)}`;
|
|
98
77
|
}));
|
|
99
78
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildLocally = buildLocally;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const localbuilds_1 = require("../../apphosting/localbuilds");
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
const fsAsync = require("../../fsAsync");
|
|
9
|
+
const logger_1 = require("../../logger");
|
|
10
|
+
const util_1 = require("./util");
|
|
11
|
+
async function buildLocally(options) {
|
|
12
|
+
const { projectId, projectDir, config, env, scratchDir } = options;
|
|
13
|
+
const { buildFolder, appFolder } = (0, util_1.buildDirectory)(projectDir, config.rootDir);
|
|
14
|
+
const scratchBuildFolder = path.join(scratchDir, path.relative(projectDir, buildFolder));
|
|
15
|
+
try {
|
|
16
|
+
await prepareLocalBuildScratchDirectory(projectDir, scratchDir, config);
|
|
17
|
+
const { outputFiles, buildConfig } = await (0, localbuilds_1.localBuild)(projectId, scratchBuildFolder, env, {
|
|
18
|
+
nonInteractive: options.nonInteractive,
|
|
19
|
+
allowLocalBuildSecrets: options.allowLocalBuildSecrets,
|
|
20
|
+
rootDir: appFolder,
|
|
21
|
+
});
|
|
22
|
+
const archive = await (0, util_1.createLocalBuildTarArchive)(config, scratchBuildFolder, outputFiles);
|
|
23
|
+
return { archive, rootDirectory: appFolder, buildConfig };
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
try {
|
|
27
|
+
fs.rmSync(scratchDir, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger_1.logger.debug(`Failed to clean up local build directory ${scratchDir}: ${(0, error_1.getErrMsg)(err)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function prepareLocalBuildScratchDirectory(rootDir, localBuildScratchDir, cfg) {
|
|
35
|
+
const ignore = (0, util_1.resolveIgnorePatterns)(cfg);
|
|
36
|
+
fs.rmSync(localBuildScratchDir, { recursive: true, force: true });
|
|
37
|
+
fs.mkdirSync(localBuildScratchDir, { recursive: true });
|
|
38
|
+
const filesToCopy = await fsAsync.readdirRecursive({
|
|
39
|
+
path: rootDir,
|
|
40
|
+
ignoreStrings: ignore,
|
|
41
|
+
supportGitIgnore: true,
|
|
42
|
+
});
|
|
43
|
+
for (const file of filesToCopy) {
|
|
44
|
+
const relativePath = path.relative(rootDir, file.name);
|
|
45
|
+
const destPath = path.join(localBuildScratchDir, relativePath);
|
|
46
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
47
|
+
fs.copyFileSync(file.name, destPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -4,14 +4,12 @@ exports.default = default_1;
|
|
|
4
4
|
exports.injectEnvVarsFromApphostingConfig = injectEnvVarsFromApphostingConfig;
|
|
5
5
|
exports.injectAutoInitEnvVars = injectAutoInitEnvVars;
|
|
6
6
|
exports.getBackendConfigs = getBackendConfigs;
|
|
7
|
-
exports.prepareLocalBuildScratchDirectory = prepareLocalBuildScratchDirectory;
|
|
8
7
|
exports.injectAngularEnvVars = injectAngularEnvVars;
|
|
9
8
|
const crypto = require("crypto");
|
|
10
9
|
const fs = require("fs");
|
|
11
10
|
const os = require("os");
|
|
12
11
|
const path = require("path");
|
|
13
|
-
const
|
|
14
|
-
const util_1 = require("./util");
|
|
12
|
+
const localBuild_1 = require("./localBuild");
|
|
15
13
|
const backend_1 = require("../../apphosting/backend");
|
|
16
14
|
const apphosting_1 = require("../../gcp/apphosting");
|
|
17
15
|
const yaml_1 = require("../../apphosting/yaml");
|
|
@@ -163,15 +161,18 @@ async function default_1(context, options) {
|
|
|
163
161
|
const pathHash = crypto.createHash("md5").update(rootDir).digest("hex").substring(0, 8);
|
|
164
162
|
const localBuildScratchDir = path.join(os.tmpdir(), `apphosting-local-build-${cfg.backendId}-${pathHash}`);
|
|
165
163
|
try {
|
|
166
|
-
await
|
|
167
|
-
|
|
164
|
+
const { archive, rootDirectory, buildConfig } = await (0, localBuild_1.buildLocally)({
|
|
165
|
+
projectId,
|
|
166
|
+
projectDir: rootDir,
|
|
167
|
+
config: cfg,
|
|
168
|
+
env: buildEnv[cfg.backendId] || {},
|
|
169
|
+
scratchDir: localBuildScratchDir,
|
|
168
170
|
nonInteractive: options.nonInteractive,
|
|
169
171
|
allowLocalBuildSecrets: !!options.allowLocalBuildSecrets,
|
|
170
|
-
rootDir: cfg.rootDir,
|
|
171
172
|
});
|
|
172
173
|
context.backendLocalBuilds[cfg.backendId] = {
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
archive,
|
|
175
|
+
rootDirectory,
|
|
175
176
|
buildConfig: {
|
|
176
177
|
...buildConfig,
|
|
177
178
|
env: mergeEnvVars(buildConfig.env || [], runtimeEnv[cfg.backendId] || {}),
|
|
@@ -216,7 +217,9 @@ async function injectAutoInitEnvVars(cfg, backends, buildEnv, runtimeEnv) {
|
|
|
216
217
|
const autoinitVars = (0, utils_2.getAutoinitEnvVars)(webappConfig);
|
|
217
218
|
for (const [envVarName, envVarValue] of Object.entries(autoinitVars)) {
|
|
218
219
|
(_a = buildEnv[cfg.backendId])[envVarName] ?? (_a[envVarName] = { value: envVarValue });
|
|
219
|
-
(
|
|
220
|
+
if (envVarName === "FIREBASE_CONFIG") {
|
|
221
|
+
(_b = runtimeEnv[cfg.backendId])[envVarName] ?? (_b[envVarName] = { value: envVarValue });
|
|
222
|
+
}
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
catch (e) {
|
|
@@ -280,22 +283,6 @@ async function ensureAppHostingServiceAgentRoles(projectId, projectNumber) {
|
|
|
280
283
|
(0, utils_1.logLabeledWarning)("apphosting", `Unable to verify App Hosting service agent permissions for ${p4saEmail}. If you encounter a PERMISSION_DENIED error during rollout, please ensure the service agent has the "Storage Object Viewer" role.`);
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
|
-
async function prepareLocalBuildScratchDirectory(rootDir, localBuildScratchDir, cfg) {
|
|
284
|
-
const ignore = (0, util_1.resolveIgnorePatterns)(cfg);
|
|
285
|
-
fs.rmSync(localBuildScratchDir, { recursive: true, force: true });
|
|
286
|
-
fs.mkdirSync(localBuildScratchDir, { recursive: true });
|
|
287
|
-
const filesToCopy = await fsAsync.readdirRecursive({
|
|
288
|
-
path: rootDir,
|
|
289
|
-
ignoreStrings: ignore,
|
|
290
|
-
supportGitIgnore: true,
|
|
291
|
-
});
|
|
292
|
-
for (const file of filesToCopy) {
|
|
293
|
-
const relativePath = path.relative(rootDir, file.name);
|
|
294
|
-
const destPath = path.join(localBuildScratchDir, relativePath);
|
|
295
|
-
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
296
|
-
fs.copyFileSync(file.name, destPath);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
286
|
function isAngularApplication(appDir) {
|
|
300
287
|
const packageJsonPath = path.join(appDir, "package.json");
|
|
301
288
|
if (fs.existsSync(packageJsonPath)) {
|
|
@@ -27,7 +27,7 @@ async function default_1(context, options) {
|
|
|
27
27
|
? {
|
|
28
28
|
locallyBuilt: {
|
|
29
29
|
userStorageUri,
|
|
30
|
-
rootDirectory,
|
|
30
|
+
rootDirectory: localBuild.rootDirectory,
|
|
31
31
|
runCommand: localBuild.buildConfig?.runCommand,
|
|
32
32
|
env: localBuild.buildConfig?.env,
|
|
33
33
|
...(localBuild.buildConfig?.runConfig
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLocalBuildTarArchive = createLocalBuildTarArchive;
|
|
4
4
|
exports.createSourceDeployArchive = createSourceDeployArchive;
|
|
5
|
+
exports.uploadArchive = uploadArchive;
|
|
5
6
|
exports.resolveIgnorePatterns = resolveIgnorePatterns;
|
|
7
|
+
exports.buildDirectory = buildDirectory;
|
|
6
8
|
const archiver = require("archiver");
|
|
7
9
|
const fs = require("fs");
|
|
8
10
|
const path = require("path");
|
|
@@ -11,6 +13,7 @@ const tmp = require("tmp");
|
|
|
11
13
|
const error_1 = require("../../error");
|
|
12
14
|
const logger_1 = require("../../logger");
|
|
13
15
|
const fsAsync = require("../../fsAsync");
|
|
16
|
+
const gcs = require("../../gcp/storage");
|
|
14
17
|
const utils_1 = require("../../utils");
|
|
15
18
|
const constants_1 = require("../../apphosting/constants");
|
|
16
19
|
async function createLocalBuildTarArchive(config, rootDir, outputFiles, sizeLimitBytes = constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES) {
|
|
@@ -64,23 +67,23 @@ async function createLocalBuildTarArchive(config, rootDir, outputFiles, sizeLimi
|
|
|
64
67
|
}
|
|
65
68
|
return tmpFile;
|
|
66
69
|
}
|
|
67
|
-
async function createSourceDeployArchive(config,
|
|
70
|
+
async function createSourceDeployArchive(config, folderToZip, projectFolder = folderToZip) {
|
|
68
71
|
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
|
|
69
72
|
const fileStream = fs.createWriteStream(tmpFile, {
|
|
70
73
|
flags: "w",
|
|
71
74
|
encoding: "binary",
|
|
72
75
|
});
|
|
73
76
|
const archive = archiver("zip");
|
|
74
|
-
const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
|
|
75
77
|
const ignore = resolveIgnorePatterns(config);
|
|
76
78
|
try {
|
|
77
79
|
const files = await fsAsync.readdirRecursive({
|
|
78
|
-
path:
|
|
80
|
+
path: folderToZip,
|
|
79
81
|
ignoreStrings: ignore,
|
|
80
82
|
supportGitIgnore: true,
|
|
83
|
+
gitIgnoreRoot: projectFolder,
|
|
81
84
|
});
|
|
82
85
|
for (const file of files) {
|
|
83
|
-
const name = path.relative(
|
|
86
|
+
const name = path.relative(folderToZip, file.name);
|
|
84
87
|
archive.file(file.name, {
|
|
85
88
|
name,
|
|
86
89
|
mode: file.mode,
|
|
@@ -93,6 +96,10 @@ async function createSourceDeployArchive(config, rootDir, targetSubDir) {
|
|
|
93
96
|
}
|
|
94
97
|
return tmpFile;
|
|
95
98
|
}
|
|
99
|
+
async function uploadArchive(archive, bucketName, localBuild) {
|
|
100
|
+
const { bucket, object } = await gcs.uploadObject({ file: archive, stream: fs.createReadStream(archive) }, bucketName, localBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP, localBuild ? constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES : undefined);
|
|
101
|
+
return { bucket, object };
|
|
102
|
+
}
|
|
96
103
|
function resolveIgnorePatterns(config, skipDefaultNodeModules = false) {
|
|
97
104
|
const ignore = config.ignore
|
|
98
105
|
? [...config.ignore]
|
|
@@ -103,6 +110,22 @@ function resolveIgnorePatterns(config, skipDefaultNodeModules = false) {
|
|
|
103
110
|
ignore.push(".local_build_*");
|
|
104
111
|
return ignore;
|
|
105
112
|
}
|
|
113
|
+
const MONOREPO_CONFIG_FILES = ["nx.json", "turbo.json"];
|
|
114
|
+
function buildDirectory(projectDir, rootDir = "") {
|
|
115
|
+
const appFolderPath = path.join(projectDir, rootDir);
|
|
116
|
+
const appFolderInProject = path.relative(projectDir, appFolderPath);
|
|
117
|
+
if (appFolderInProject.startsWith("..")) {
|
|
118
|
+
throw new error_1.FirebaseError(`rootDir "${rootDir}" must be inside the project directory.`);
|
|
119
|
+
}
|
|
120
|
+
const segments = appFolderInProject ? appFolderInProject.split(path.sep) : [];
|
|
121
|
+
for (let depth = segments.length; depth >= 0; depth--) {
|
|
122
|
+
const folder = path.join(projectDir, ...segments.slice(0, depth));
|
|
123
|
+
if (MONOREPO_CONFIG_FILES.some((file) => fs.existsSync(path.join(folder, file)))) {
|
|
124
|
+
return { buildFolder: folder, appFolder: segments.slice(depth).join("/") };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { buildFolder: appFolderPath, appFolder: "" };
|
|
128
|
+
}
|
|
106
129
|
async function pipeAsync(from, to) {
|
|
107
130
|
from.pipe(to);
|
|
108
131
|
await from.finalize();
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DockerHelper =
|
|
4
|
-
exports.cleanupBuildImages = cleanupBuildImages;
|
|
3
|
+
exports.DockerHelper = void 0;
|
|
5
4
|
exports.listGcfPaths = listGcfPaths;
|
|
6
5
|
exports.deleteGcfArtifacts = deleteGcfArtifacts;
|
|
7
|
-
const clc = require("colorette");
|
|
8
6
|
const error_1 = require("../../error");
|
|
9
7
|
const api_1 = require("../../api");
|
|
10
8
|
const logger_1 = require("../../logger");
|
|
11
|
-
const artifactregistry = require("../../gcp/artifactregistry");
|
|
12
|
-
const backend = require("./backend");
|
|
13
9
|
const docker = require("../../gcp/docker");
|
|
14
|
-
const utils = require("../../utils");
|
|
15
|
-
const poller = require("../../operation-poller");
|
|
16
10
|
async function retry(func) {
|
|
17
11
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
12
|
const MAX_RETRIES = 3;
|
|
@@ -36,141 +30,6 @@ async function retry(func) {
|
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
async function cleanupBuildImages(haveFunctions, deletedFunctions, cleaners = {}) {
|
|
40
|
-
utils.logBullet(clc.bold(clc.cyan("functions: ")) + "cleaning up build files...");
|
|
41
|
-
const failedDomains = new Set();
|
|
42
|
-
const cleanup = [];
|
|
43
|
-
const arCleaner = cleaners.ar || new ArtifactRegistryCleaner();
|
|
44
|
-
cleanup.push(...haveFunctions.map(async (func) => {
|
|
45
|
-
try {
|
|
46
|
-
await arCleaner.cleanupFunction(func);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
const path = `${func.project}/${func.region}/gcf-artifacts`;
|
|
50
|
-
failedDomains.add(`https://console.cloud.google.com/artifacts/docker/${path}`);
|
|
51
|
-
}
|
|
52
|
-
}));
|
|
53
|
-
cleanup.push(...deletedFunctions.map(async (func) => {
|
|
54
|
-
try {
|
|
55
|
-
await arCleaner.cleanupFunction(func);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
const path = `${func.project}/${func.region}/gcf-artifacts`;
|
|
59
|
-
failedDomains.add(`https://console.cloud.google.com/artifacts/docker/${path}`);
|
|
60
|
-
}
|
|
61
|
-
}));
|
|
62
|
-
const gcrCleaner = cleaners.gcr || new ContainerRegistryCleaner();
|
|
63
|
-
cleanup.push(...[...haveFunctions, ...deletedFunctions].map(async (func) => {
|
|
64
|
-
try {
|
|
65
|
-
await gcrCleaner.cleanupFunction(func);
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
const path = `${func.project}/${docker.GCR_SUBDOMAIN_MAPPING[func.region]}/gcf`;
|
|
69
|
-
failedDomains.add(`https://console.cloud.google.com/gcr/images/${path}`);
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
await Promise.all(cleanup);
|
|
73
|
-
if (failedDomains.size) {
|
|
74
|
-
let message = "Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. ";
|
|
75
|
-
message +=
|
|
76
|
-
"You can attempt to delete these images by redeploying or you can delete them manually at";
|
|
77
|
-
if (failedDomains.size === 1) {
|
|
78
|
-
message += " " + failedDomains.values().next().value;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
message += [...failedDomains].map((domain) => "\n\t" + domain).join("");
|
|
82
|
-
}
|
|
83
|
-
utils.logLabeledWarning("functions", message);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
class ArtifactRegistryCleaner {
|
|
87
|
-
static packagePath(func) {
|
|
88
|
-
const encodedId = func.platform === "gcfv2"
|
|
89
|
-
? ArtifactRegistryCleaner.encodePackageNameV2(func)
|
|
90
|
-
: ArtifactRegistryCleaner.encodePackageNameV1(func);
|
|
91
|
-
return `projects/${func.project}/locations/${func.region}/repositories/gcf-artifacts/packages/${encodedId}`;
|
|
92
|
-
}
|
|
93
|
-
static encodePart(part) {
|
|
94
|
-
return part
|
|
95
|
-
.replace(/_/g, "__")
|
|
96
|
-
.replace(/-/g, "--")
|
|
97
|
-
.replace(/^[A-Z]/, (first) => `${first.toLowerCase()}-${first.toLowerCase()}`)
|
|
98
|
-
.replace(/[A-Z]/g, (upper) => `_${upper.toLowerCase()}`);
|
|
99
|
-
}
|
|
100
|
-
static encodePackageNameV1(func) {
|
|
101
|
-
return ArtifactRegistryCleaner.encodePart(func.id);
|
|
102
|
-
}
|
|
103
|
-
static encodePackageNameV2(func) {
|
|
104
|
-
return [
|
|
105
|
-
ArtifactRegistryCleaner.encodePart(func.project),
|
|
106
|
-
ArtifactRegistryCleaner.encodePart(func.region),
|
|
107
|
-
ArtifactRegistryCleaner.encodePart(func.id),
|
|
108
|
-
].join("__");
|
|
109
|
-
}
|
|
110
|
-
async cleanupFunction(func) {
|
|
111
|
-
let op;
|
|
112
|
-
try {
|
|
113
|
-
op = await artifactregistry.deletePackage(ArtifactRegistryCleaner.packagePath(func));
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
if (err.status === 404) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
throw err;
|
|
120
|
-
}
|
|
121
|
-
if (op.done) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
await poller.pollOperation({
|
|
125
|
-
...ArtifactRegistryCleaner.POLLER_OPTIONS,
|
|
126
|
-
pollerName: `cleanup-${func.region}-${func.id}`,
|
|
127
|
-
operationResourceName: op.name,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.ArtifactRegistryCleaner = ArtifactRegistryCleaner;
|
|
132
|
-
ArtifactRegistryCleaner.POLLER_OPTIONS = {
|
|
133
|
-
apiOrigin: (0, api_1.artifactRegistryDomain)(),
|
|
134
|
-
apiVersion: artifactregistry.API_VERSION,
|
|
135
|
-
masterTimeout: 5 * 60 * 1000,
|
|
136
|
-
};
|
|
137
|
-
class ContainerRegistryCleaner {
|
|
138
|
-
constructor() {
|
|
139
|
-
this.helpers = {};
|
|
140
|
-
}
|
|
141
|
-
helper(location) {
|
|
142
|
-
const subdomain = docker.GCR_SUBDOMAIN_MAPPING[location] || "us";
|
|
143
|
-
if (!this.helpers[subdomain]) {
|
|
144
|
-
const origin = `https://${subdomain}.${(0, api_1.containerRegistryDomain)()}`;
|
|
145
|
-
this.helpers[subdomain] = new DockerHelper(origin);
|
|
146
|
-
}
|
|
147
|
-
return this.helpers[subdomain];
|
|
148
|
-
}
|
|
149
|
-
async cleanupFunction(func) {
|
|
150
|
-
const helper = this.helper(func.region);
|
|
151
|
-
const uuids = (await helper.ls(`${func.project}/gcf/${func.region}`)).children;
|
|
152
|
-
const uuidTags = {};
|
|
153
|
-
const loadUuidTags = [];
|
|
154
|
-
for (const uuid of uuids) {
|
|
155
|
-
loadUuidTags.push((async () => {
|
|
156
|
-
const path = `${func.project}/gcf/${func.region}/${uuid}`;
|
|
157
|
-
const tags = (await helper.ls(path)).tags;
|
|
158
|
-
uuidTags[path] = tags;
|
|
159
|
-
})());
|
|
160
|
-
}
|
|
161
|
-
await Promise.all(loadUuidTags);
|
|
162
|
-
const extractFunction = /^(.*)_version-\d+$/;
|
|
163
|
-
const entry = Object.entries(uuidTags).find(([, tags]) => {
|
|
164
|
-
return tags.find((tag) => extractFunction.exec(tag)?.[1] === func.id);
|
|
165
|
-
});
|
|
166
|
-
if (!entry) {
|
|
167
|
-
logger_1.logger.debug("Could not find image for function", backend.functionName(func));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
await helper.rm(entry[0]);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.ContainerRegistryCleaner = ContainerRegistryCleaner;
|
|
174
33
|
function getHelper(cache, subdomain) {
|
|
175
34
|
if (!cache[subdomain]) {
|
|
176
35
|
cache[subdomain] = new DockerHelper(`https://${subdomain}.${(0, api_1.containerRegistryDomain)()}`);
|
|
@@ -11,7 +11,6 @@ exports.generationDowngradeMessage = generationDowngradeMessage;
|
|
|
11
11
|
exports.targetCodebases = targetCodebases;
|
|
12
12
|
exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
|
|
13
13
|
exports.isCodebaseFiltered = isCodebaseFiltered;
|
|
14
|
-
exports.isEndpointFiltered = isEndpointFiltered;
|
|
15
14
|
exports.isCodebasePartiallyFiltered = isCodebasePartiallyFiltered;
|
|
16
15
|
exports.parseDeleteFilters = parseDeleteFilters;
|
|
17
16
|
exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
|
|
@@ -148,9 +147,6 @@ function isCodebaseFiltered(codebase, filters) {
|
|
|
148
147
|
return noIdChunks && filter.codebase === codebase;
|
|
149
148
|
});
|
|
150
149
|
}
|
|
151
|
-
function isEndpointFiltered(endpoint, filters) {
|
|
152
|
-
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
153
|
-
}
|
|
154
150
|
function isCodebasePartiallyFiltered(codebase, filters) {
|
|
155
151
|
if (!filters) {
|
|
156
152
|
return false;
|
|
@@ -578,8 +578,9 @@ class Fabricator {
|
|
|
578
578
|
invoker = ["public"];
|
|
579
579
|
}
|
|
580
580
|
if (invoker) {
|
|
581
|
+
const invokerUpdate = invoker;
|
|
581
582
|
await this.executor
|
|
582
|
-
.run(() => gcf.setInvokerUpdate(endpoint.project, backend.functionName(endpoint),
|
|
583
|
+
.run(() => gcf.setInvokerUpdate(endpoint.project, backend.functionName(endpoint), invokerUpdate))
|
|
583
584
|
.catch(rethrowAs(endpoint, "set invoker"));
|
|
584
585
|
}
|
|
585
586
|
}
|
|
@@ -653,8 +654,9 @@ class Fabricator {
|
|
|
653
654
|
: [await gce.getDefaultServiceAccount(this.projectNumber)];
|
|
654
655
|
}
|
|
655
656
|
if (invoker) {
|
|
657
|
+
const invokerUpdate = invoker;
|
|
656
658
|
await this.executor
|
|
657
|
-
.run(() => run.setInvokerUpdate(endpoint.project, serviceName,
|
|
659
|
+
.run(() => run.setInvokerUpdate(endpoint.project, serviceName, invokerUpdate))
|
|
658
660
|
.catch(rethrowAs(endpoint, "set invoker"));
|
|
659
661
|
}
|
|
660
662
|
}
|
|
@@ -758,8 +760,9 @@ class Fabricator {
|
|
|
758
760
|
invoker = endpoint.httpsTrigger.invoker === null ? ["public"] : endpoint.httpsTrigger.invoker;
|
|
759
761
|
}
|
|
760
762
|
if (invoker) {
|
|
763
|
+
const invokerUpdate = invoker;
|
|
761
764
|
await this.executor
|
|
762
|
-
.run(() => run.setInvokerUpdate(endpoint.project, serviceName,
|
|
765
|
+
.run(() => run.setInvokerUpdate(endpoint.project, serviceName, invokerUpdate))
|
|
763
766
|
.catch(rethrowAs(endpoint, "set invoker"));
|
|
764
767
|
}
|
|
765
768
|
}
|
|
@@ -229,7 +229,7 @@ function functionIdsAreValid(functions) {
|
|
|
229
229
|
const invalidIds = functions.filter((fn) => !functionName.test(fn.id));
|
|
230
230
|
if (invalidIds.length !== 0) {
|
|
231
231
|
const msg = `${invalidIds.map((f) => f.id).join(", ")} function name(s) can only contain letters, ` +
|
|
232
|
-
`numbers, hyphens, and not exceed
|
|
232
|
+
`numbers, underscores, hyphens, and not exceed 63 characters in length`;
|
|
233
233
|
throw new error_1.FirebaseError(msg);
|
|
234
234
|
}
|
|
235
235
|
}
|
package/lib/deploy/run/deploy.js
CHANGED
|
@@ -6,16 +6,14 @@ exports.localBuildTemplate = localBuildTemplate;
|
|
|
6
6
|
const fs = require("fs");
|
|
7
7
|
const os = require("os");
|
|
8
8
|
const path = require("path");
|
|
9
|
-
const constants_1 = require("../../apphosting/constants");
|
|
10
9
|
const localbuilds_1 = require("../../apphosting/localbuilds");
|
|
11
10
|
const error_1 = require("../../error");
|
|
12
11
|
const artifactregistry = require("../../gcp/artifactregistry");
|
|
13
12
|
const runv2 = require("../../gcp/runv2");
|
|
14
13
|
const gcs = require("../../gcp/storage");
|
|
15
14
|
const getProjectNumber_1 = require("../../getProjectNumber");
|
|
16
|
-
const logger_1 = require("../../logger");
|
|
17
15
|
const utils_1 = require("../../utils");
|
|
18
|
-
const
|
|
16
|
+
const localBuild_1 = require("../apphosting/localBuild");
|
|
19
17
|
const util_1 = require("../apphosting/util");
|
|
20
18
|
const buildEnv_1 = require("./buildEnv");
|
|
21
19
|
const util_2 = require("./util");
|
|
@@ -34,26 +32,22 @@ async function deploy(context, options, payload) {
|
|
|
34
32
|
}
|
|
35
33
|
async function deployRemoteBuild(context, options, svc) {
|
|
36
34
|
const { projectId } = context;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
35
|
+
const { buildFolder, appFolder } = (0, util_1.buildDirectory)(options.config.projectDir, svc.config.rootDir);
|
|
36
|
+
const archive = await (0, util_1.createSourceDeployArchive)(toAppHostingConfig(svc.config), buildFolder, options.config.projectDir);
|
|
37
|
+
const source = await upload(projectId, options, svc.config, archive);
|
|
38
|
+
const image = await buildImage(projectId, svc, source, appFolder);
|
|
39
39
|
const template = revisionTemplate(svc, image, options.message);
|
|
40
40
|
svc.deployed = await rollOut(projectId, svc, template);
|
|
41
41
|
}
|
|
42
42
|
async function deployLocalBuild(context, options, svc) {
|
|
43
43
|
const { projectId } = context;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const template = localBuildTemplate(svc, build, builtApp, message);
|
|
50
|
-
svc.deployed = await rollOut(projectId, svc, template);
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
removeTempPath(scratchDir);
|
|
54
|
-
}
|
|
44
|
+
const build = await buildServiceLocally(context, options, svc);
|
|
45
|
+
const builtApp = await upload(projectId, options, svc.config, build.archive);
|
|
46
|
+
const message = options.message;
|
|
47
|
+
const template = localBuildTemplate(svc, build, builtApp, message);
|
|
48
|
+
svc.deployed = await rollOut(projectId, svc, template);
|
|
55
49
|
}
|
|
56
|
-
async function
|
|
50
|
+
async function buildServiceLocally(context, options, svc) {
|
|
57
51
|
const { config } = svc;
|
|
58
52
|
const { serviceId, region } = config;
|
|
59
53
|
const cfg = toAppHostingConfig(config);
|
|
@@ -64,31 +58,27 @@ async function buildLocally(context, options, svc, scratchDir) {
|
|
|
64
58
|
(0, utils_1.logLabeledBullet)("run", `Reading build secrets ${secrets.join(", ")} with your credentials. Their values may be ` +
|
|
65
59
|
`included in the build output.`);
|
|
66
60
|
}
|
|
67
|
-
await (0,
|
|
68
|
-
|
|
61
|
+
const { archive, buildConfig } = await (0, localBuild_1.buildLocally)({
|
|
62
|
+
projectId: context.projectId,
|
|
63
|
+
projectDir: options.config.projectDir,
|
|
64
|
+
config: cfg,
|
|
65
|
+
env: (0, buildEnv_1.toLocalBuildEnv)(svc.buildEnv || {}),
|
|
66
|
+
scratchDir: fs.mkdtempSync(path.join(os.tmpdir(), `run-local-build-${serviceId}-`)),
|
|
67
|
+
allowLocalBuildSecrets: true,
|
|
68
|
+
});
|
|
69
69
|
const env = (buildConfig.env || [])
|
|
70
70
|
.filter((e) => e.variable &&
|
|
71
71
|
e.value !== undefined &&
|
|
72
72
|
(!e.availability || e.availability.includes("RUNTIME")))
|
|
73
73
|
.map((e) => ({ name: e.variable, value: e.value }));
|
|
74
|
-
return {
|
|
74
|
+
return { archive, runCommand: buildConfig.runCommand, env };
|
|
75
75
|
}
|
|
76
|
-
async function
|
|
76
|
+
async function upload(projectId, options, config, archive) {
|
|
77
77
|
const { serviceId, region } = config;
|
|
78
78
|
const bucketName = await sourceBucket(projectId, options, region);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
(0,
|
|
82
|
-
const { bucket, object } = await gcs.uploadObject({ file: archive, stream: fs.createReadStream(archive) }, bucketName, gcs.ContentType.ZIP);
|
|
83
|
-
return { bucket, object };
|
|
84
|
-
}
|
|
85
|
-
async function uploadBuiltApp(projectId, options, config, scratchDir, build) {
|
|
86
|
-
const { serviceId, region } = config;
|
|
87
|
-
const bucketName = await sourceBucket(projectId, options, region);
|
|
88
|
-
const archive = await (0, util_1.createLocalBuildTarArchive)(toAppHostingConfig(config), scratchDir, build.outputFiles);
|
|
89
|
-
(0, utils_1.logLabeledBullet)("run", `Uploading built app for service ${serviceId} in ${region}...`);
|
|
90
|
-
const { bucket, object } = await gcs.uploadObject({ file: archive, stream: fs.createReadStream(archive) }, bucketName, gcs.ContentType.TAR, constants_1.CLOUD_RUN_SIZE_LIMIT_BYTES);
|
|
91
|
-
return { bucket, object };
|
|
79
|
+
const what = config.localBuild ? "built app" : "source";
|
|
80
|
+
(0, utils_1.logLabeledBullet)("run", `Uploading ${what} for service ${serviceId} in ${region}...`);
|
|
81
|
+
return (0, util_1.uploadArchive)(archive, bucketName, !!config.localBuild);
|
|
92
82
|
}
|
|
93
83
|
async function sourceBucket(projectId, options, region) {
|
|
94
84
|
const baseName = `firebase-run-src-${await (0, getProjectNumber_1.getProjectNumber)(options)}-${region.toLowerCase()}`;
|
|
@@ -104,13 +94,14 @@ async function sourceBucket(projectId, options, region) {
|
|
|
104
94
|
},
|
|
105
95
|
});
|
|
106
96
|
}
|
|
107
|
-
async function buildImage(projectId, svc, source) {
|
|
97
|
+
async function buildImage(projectId, svc, source, appFolder) {
|
|
108
98
|
const { serviceId, region } = svc.config;
|
|
109
99
|
await artifactregistry.ensureDockerRepository(projectId, region, "cloud-run-source-deploy");
|
|
110
100
|
const imageUri = `${region}-docker.pkg.dev/${projectId}/cloud-run-source-deploy/${serviceId}:${Date.now()}`;
|
|
111
101
|
(0, utils_1.logLabeledBullet)("run", `Building service ${serviceId} in ${region}...`);
|
|
112
102
|
const buildpackBuild = {
|
|
113
103
|
environmentVariables: {
|
|
104
|
+
...(appFolder ? { GOOGLE_BUILDABLE: appFolder } : {}),
|
|
114
105
|
...(0, buildEnv_1.nonSecretValues)(svc.buildEnv || {}),
|
|
115
106
|
X_GOOGLE_TARGET_PLATFORM: "fah",
|
|
116
107
|
FIREBASE_OUTPUT_BUNDLE_DIR: "/workspace/.apphosting",
|
|
@@ -232,11 +223,3 @@ function toAppHostingConfig(config) {
|
|
|
232
223
|
localBuild: config.localBuild,
|
|
233
224
|
};
|
|
234
225
|
}
|
|
235
|
-
function removeTempPath(tempPath) {
|
|
236
|
-
try {
|
|
237
|
-
fs.rmSync(tempPath, { recursive: true, force: true });
|
|
238
|
-
}
|
|
239
|
-
catch (err) {
|
|
240
|
-
logger_1.logger.debug(`Failed to clean up ${tempPath}: ${(0, error_1.getErrMsg)(err)}`);
|
|
241
|
-
}
|
|
242
|
-
}
|