firebase-tools 15.28.1 → 15.28.2
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/apphosting/backend.js +44 -10
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apphosting/repo.js +1 -1
- package/lib/apphosting/rollout.js +1 -1
- package/lib/commands/ext-export.js +25 -29
- package/lib/commands/ext-migrate.js +36 -0
- package/lib/commands/functions-kits-install.js +21 -401
- package/lib/commands/functions-kits-uninstall.js +266 -0
- package/lib/commands/index.js +4 -0
- package/lib/config.js +34 -0
- package/lib/dataconnect/client.js +2 -2
- package/lib/deploy/functions/ensure.js +29 -19
- package/lib/deploy/functions/prepare.js +8 -1
- package/lib/deploy/functions/release/fabricator.js +19 -3
- package/lib/deploy/functions/release/planner.js +8 -0
- package/lib/extensions/listExtensions.js +27 -3
- package/lib/extensions/migrate.js +171 -0
- package/lib/extensions/replacementRegistry.js +39 -4
- package/lib/extensions/replacements.json +7 -7
- package/lib/functions/kits/env.js +38 -0
- package/lib/functions/kits/index.js +19 -0
- package/lib/functions/kits/install.js +709 -0
- package/lib/requireTosAcceptance.js +2 -1
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/schema/firebase-config.json +1 -1
|
@@ -7,6 +7,7 @@ exports.createGitRepoLink = createGitRepoLink;
|
|
|
7
7
|
exports.ensureAppHostingComputeServiceAccount = ensureAppHostingComputeServiceAccount;
|
|
8
8
|
exports.promptNewBackendId = promptNewBackendId;
|
|
9
9
|
exports.createBackend = createBackend;
|
|
10
|
+
exports.defaultComputeServiceAccountExists = defaultComputeServiceAccountExists;
|
|
10
11
|
exports.setDefaultTrafficPolicy = setDefaultTrafficPolicy;
|
|
11
12
|
exports.deleteBackendAndPoll = deleteBackendAndPoll;
|
|
12
13
|
exports.promptLocation = promptLocation;
|
|
@@ -39,7 +40,7 @@ const DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME = "firebase-app-hosting-compute";
|
|
|
39
40
|
const apphostingPollerOptions = {
|
|
40
41
|
apiOrigin: (0, api_1.apphostingOrigin)(),
|
|
41
42
|
apiVersion: apphosting_1.API_VERSION,
|
|
42
|
-
masterTimeout:
|
|
43
|
+
masterTimeout: 60 * 60 * 1000,
|
|
43
44
|
maxBackoff: 10000,
|
|
44
45
|
};
|
|
45
46
|
async function tlsReady(url) {
|
|
@@ -190,6 +191,10 @@ async function createGitRepoLink(projectId, location, connectionId) {
|
|
|
190
191
|
await githubConnections.linkGitHubRepository(projectId, location, connectionId);
|
|
191
192
|
}
|
|
192
193
|
async function ensureAppHostingComputeServiceAccount(projectId, serviceAccount) {
|
|
194
|
+
await verifyRuntimeServiceAccountAccess(projectId, serviceAccount);
|
|
195
|
+
await provisionDefaultComputeServiceAccount(projectId);
|
|
196
|
+
}
|
|
197
|
+
async function verifyRuntimeServiceAccountAccess(projectId, serviceAccount) {
|
|
193
198
|
const sa = serviceAccount || defaultComputeServiceAccountEmail(projectId);
|
|
194
199
|
const name = `projects/${projectId}/serviceAccounts/${sa}`;
|
|
195
200
|
try {
|
|
@@ -206,7 +211,6 @@ async function ensureAppHostingComputeServiceAccount(projectId, serviceAccount)
|
|
|
206
211
|
throw new error_1.FirebaseError("Unexpected error occurred while testing for IAM service account permissions", { original: err });
|
|
207
212
|
}
|
|
208
213
|
}
|
|
209
|
-
await provisionDefaultComputeServiceAccount(projectId);
|
|
210
214
|
}
|
|
211
215
|
async function promptNewBackendId(projectId, location) {
|
|
212
216
|
while (true) {
|
|
@@ -266,13 +270,8 @@ async function createBackend(projectId, location, backendId, serviceAccount, rep
|
|
|
266
270
|
return await createBackendAndPoll();
|
|
267
271
|
}
|
|
268
272
|
async function provisionDefaultComputeServiceAccount(projectId) {
|
|
269
|
-
|
|
270
|
-
await
|
|
271
|
-
}
|
|
272
|
-
catch (err) {
|
|
273
|
-
if ((0, error_1.getErrStatus)(err) !== 409) {
|
|
274
|
-
throw err;
|
|
275
|
-
}
|
|
273
|
+
if (!(await defaultComputeServiceAccountExists(projectId))) {
|
|
274
|
+
await createDefaultComputeServiceAccount(projectId);
|
|
276
275
|
}
|
|
277
276
|
try {
|
|
278
277
|
await (0, resourceManager_1.addServiceAccountToRoles)(projectId, defaultComputeServiceAccountEmail(projectId), [
|
|
@@ -283,14 +282,49 @@ async function provisionDefaultComputeServiceAccount(projectId) {
|
|
|
283
282
|
], true);
|
|
284
283
|
}
|
|
285
284
|
catch (err) {
|
|
286
|
-
|
|
285
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
286
|
+
if (status === 400) {
|
|
287
287
|
(0, utils_1.logWarning)("Your App Hosting compute service account is still being provisioned in the background. If you encounter an error, please try again after a few moments.");
|
|
288
288
|
}
|
|
289
|
+
else if (status === 403) {
|
|
290
|
+
(0, utils_1.logWarning)("Failed to grant roles to the default App Hosting compute service account. Make sure you " +
|
|
291
|
+
"have the resourcemanager.projects.setIamPolicy permission. If the service account " +
|
|
292
|
+
"already has these roles, this warning can be safely ignored.");
|
|
293
|
+
}
|
|
289
294
|
else {
|
|
290
295
|
throw err;
|
|
291
296
|
}
|
|
292
297
|
}
|
|
293
298
|
}
|
|
299
|
+
async function defaultComputeServiceAccountExists(projectId) {
|
|
300
|
+
try {
|
|
301
|
+
await iam.getServiceAccount(projectId, defaultComputeServiceAccountEmail(projectId));
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
306
|
+
if (status === 404 || status === 403) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
throw err;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async function createDefaultComputeServiceAccount(projectId) {
|
|
313
|
+
try {
|
|
314
|
+
await iam.createServiceAccount(projectId, DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME, "Default service account used to run builds and deploys for Firebase App Hosting", "Firebase App Hosting compute service account");
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
318
|
+
if (status === 403) {
|
|
319
|
+
(0, utils_1.logWarning)("Failed to create the default App Hosting compute service account. Make sure you have " +
|
|
320
|
+
"the iam.serviceAccounts.create permission. If the service account already exists, " +
|
|
321
|
+
"this warning can be safely ignored.");
|
|
322
|
+
}
|
|
323
|
+
else if (status !== 409) {
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
294
328
|
async function setDefaultTrafficPolicy(projectId, location, backendId, codebaseBranch) {
|
|
295
329
|
const traffic = {
|
|
296
330
|
rolloutPolicy: {
|
|
@@ -48,7 +48,7 @@ function parseConnectionName(name) {
|
|
|
48
48
|
const devConnectPollerOptions = {
|
|
49
49
|
apiOrigin: (0, api_1.developerConnectOrigin)(),
|
|
50
50
|
apiVersion: "v1",
|
|
51
|
-
masterTimeout:
|
|
51
|
+
masterTimeout: 60 * 60 * 1000,
|
|
52
52
|
maxBackoff: 10000,
|
|
53
53
|
};
|
|
54
54
|
function extractRepoSlugFromUri(cloneUri) {
|
package/lib/apphosting/repo.js
CHANGED
|
@@ -36,7 +36,7 @@ function parseConnectionName(name) {
|
|
|
36
36
|
const gcbPollerOptions = {
|
|
37
37
|
apiOrigin: (0, api_1.cloudbuildOrigin)(),
|
|
38
38
|
apiVersion: "v2",
|
|
39
|
-
masterTimeout:
|
|
39
|
+
masterTimeout: 60 * 60 * 1000,
|
|
40
40
|
maxBackoff: 10000,
|
|
41
41
|
};
|
|
42
42
|
function extractRepoSlugFromUri(remoteUri) {
|
|
@@ -14,7 +14,7 @@ const backend_1 = require("./backend");
|
|
|
14
14
|
const apphostingPollerOptions = {
|
|
15
15
|
apiOrigin: (0, api_1.apphostingOrigin)(),
|
|
16
16
|
apiVersion: apphosting.API_VERSION,
|
|
17
|
-
masterTimeout:
|
|
17
|
+
masterTimeout: 60 * 60 * 1000,
|
|
18
18
|
maxBackoff: 10000,
|
|
19
19
|
};
|
|
20
20
|
const GIT_COMMIT_SHA_REGEX = /^(?:[0-9a-f]{40}|[0-9a-f]{7})$/;
|
|
@@ -29,16 +29,15 @@ const experiments = require("../experiments");
|
|
|
29
29
|
exports.command = new command_1.Command("ext:export")
|
|
30
30
|
.description("export Extension instances installed on a project to a local Firebase directory")
|
|
31
31
|
.option(`--mode <target>`, `experimental: controls the target system of the export (supports "extensions", "functions")`)
|
|
32
|
-
.option(
|
|
33
|
-
.option(
|
|
32
|
+
.option("--instance <instanceId>", "scope the export to the single instance with the specified instance id")
|
|
33
|
+
.option("-k, --kit-instance <kitId>", "write the .env export from --mode functions to the config path for a kit instance currently defined in firebase.json")
|
|
34
34
|
.option(`--outputDir <path>`, `override the .env export from --mode functions to a specific arbitrary path`)
|
|
35
35
|
.before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.list"])
|
|
36
36
|
.before(extensionsHelper_1.ensureExtensionsApiEnabled)
|
|
37
37
|
.before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
|
|
38
38
|
.withForce()
|
|
39
39
|
.action(async (options) => {
|
|
40
|
-
if (experiments.isEnabled("extMigrationFeatures") &&
|
|
41
|
-
(options.mode === "functions" || options.mode === "kits")) {
|
|
40
|
+
if (experiments.isEnabled("extMigrationFeatures") && options.mode === "functions") {
|
|
42
41
|
await fnHandler(options);
|
|
43
42
|
}
|
|
44
43
|
else {
|
|
@@ -53,10 +52,10 @@ async function extHandler(options) {
|
|
|
53
52
|
logger_1.logger.info(`No extension instances installed on ${projectId}, so there is nothing to export.`);
|
|
54
53
|
return;
|
|
55
54
|
}
|
|
56
|
-
if (options.
|
|
57
|
-
have = have.filter((s) => s.instanceId === options.
|
|
55
|
+
if (options.instance) {
|
|
56
|
+
have = have.filter((s) => s.instanceId === options.instance);
|
|
58
57
|
if (have.length === 0) {
|
|
59
|
-
logger_1.logger.info(`No extension instances installed on ${projectId} match specified instance ID ${options.
|
|
58
|
+
logger_1.logger.info(`No extension instances installed on ${projectId} match specified instance ID ${options.instance}.`);
|
|
60
59
|
return;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -97,31 +96,25 @@ async function extHandler(options) {
|
|
|
97
96
|
(0, etags_1.saveEtags)(options.rc, projectId, have);
|
|
98
97
|
}
|
|
99
98
|
async function fnHandler(options) {
|
|
100
|
-
if (!options.
|
|
99
|
+
if (!options.instance) {
|
|
101
100
|
logger_1.logger.info(`ext:export must specify an --instance <instanceId> option when exporting to Functions. Use ext:list to find your instance IDs.`);
|
|
102
101
|
return;
|
|
103
102
|
}
|
|
104
103
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
105
|
-
const instance = await (0, extensionsApi_1.getInstance)(projectId, options.
|
|
104
|
+
const instance = await (0, extensionsApi_1.getInstance)(projectId, options.instance);
|
|
106
105
|
if (typeof instance === "undefined") {
|
|
107
|
-
logger_1.logger.info(`No extension matching instance ID ${options.
|
|
106
|
+
logger_1.logger.info(`No extension matching instance ID ${options.instance} found`);
|
|
108
107
|
return;
|
|
109
108
|
}
|
|
110
109
|
if (instance.state !== "ACTIVE" && !options.force) {
|
|
111
|
-
throw new error_1.FirebaseError(`Extension ${options.
|
|
110
|
+
throw new error_1.FirebaseError(`Extension ${options.instance} is in state ${instance.state}. To export a non-ACTIVE extension, use the --force option.`);
|
|
112
111
|
}
|
|
113
112
|
const instanceId = (0, utils_1.last)(instance.name.split("/")) ?? "";
|
|
114
|
-
if (instanceId !== options.
|
|
113
|
+
if (instanceId !== options.instance) {
|
|
115
114
|
return;
|
|
116
115
|
}
|
|
117
|
-
let secretCount = 0;
|
|
118
116
|
const convertedEnv = (0, export_1.functionsEnvFromInstance)(instance);
|
|
119
|
-
|
|
120
|
-
if (key.startsWith("FIREBASE_SECRET_REF_")) {
|
|
121
|
-
secretCount += 1;
|
|
122
|
-
}
|
|
123
|
-
console.log(`${key}=${convertedEnv[key]}`);
|
|
124
|
-
}
|
|
117
|
+
const secretCount = Object.keys(convertedEnv).filter((key) => key.startsWith("FIREBASE_SECRET_REF_")).length;
|
|
125
118
|
const writeLocation = kitExportTarget(instanceId, projectId, options);
|
|
126
119
|
if ((0, env_1.hasUserEnvs)(writeLocation)) {
|
|
127
120
|
logger_1.logger.info(`Exported extensions config appears to already exist in /${instanceId}, aborting write.`);
|
|
@@ -129,7 +122,7 @@ async function fnHandler(options) {
|
|
|
129
122
|
else {
|
|
130
123
|
(0, utils_2.logBullet)(clc.cyan(clc.bold("functions: ")) +
|
|
131
124
|
`Saving exported extensions config as a Function Kits .env file`);
|
|
132
|
-
(0, fs_1.mkdirSync)((0, path_1.
|
|
125
|
+
(0, fs_1.mkdirSync)((0, path_1.resolve)(writeLocation.projectDir, writeLocation.configDir ?? instanceId), {
|
|
133
126
|
recursive: true,
|
|
134
127
|
});
|
|
135
128
|
(0, env_1.writeUserEnvs)(convertedEnv, writeLocation);
|
|
@@ -151,13 +144,14 @@ async function fnHandler(options) {
|
|
|
151
144
|
}
|
|
152
145
|
function kitExportTarget(instanceId, projectId, options) {
|
|
153
146
|
const firebaseConfig = config_1.Config.load(options, true);
|
|
147
|
+
const cwd = options.cwd ?? process.cwd();
|
|
154
148
|
if (typeof options.outputDir !== "undefined") {
|
|
155
149
|
return {
|
|
156
150
|
functionsSource: instanceId,
|
|
157
|
-
configDir: String(options.outputDir),
|
|
151
|
+
configDir: (0, path_1.resolve)(cwd, String(options.outputDir)),
|
|
158
152
|
projectId: projectId,
|
|
159
153
|
isEmulator: false,
|
|
160
|
-
projectDir:
|
|
154
|
+
projectDir: cwd,
|
|
161
155
|
};
|
|
162
156
|
}
|
|
163
157
|
if (typeof options.kitInstance !== "undefined") {
|
|
@@ -170,23 +164,25 @@ function kitExportTarget(instanceId, projectId, options) {
|
|
|
170
164
|
if (!(0, projectConfig_1.isKitConfig)(fn)) {
|
|
171
165
|
continue;
|
|
172
166
|
}
|
|
173
|
-
for (const [
|
|
174
|
-
if (
|
|
167
|
+
for (const [kitInstanceId, configDirPath] of Object.entries(fn.instances)) {
|
|
168
|
+
if (kitInstanceId === options.kitInstance) {
|
|
169
|
+
const projectDir = options.projectRoot ?? cwd;
|
|
175
170
|
return {
|
|
176
171
|
functionsSource: instanceId,
|
|
177
|
-
configDir: String(
|
|
172
|
+
configDir: (0, path_1.resolve)(projectDir, String(configDirPath)),
|
|
178
173
|
projectId: projectId,
|
|
179
174
|
isEmulator: false,
|
|
180
|
-
projectDir:
|
|
175
|
+
projectDir: projectDir,
|
|
181
176
|
};
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
179
|
}
|
|
180
|
+
throw new error_1.FirebaseError(`Could not find kit instance "${options.kitInstance}" in firebase.json.`);
|
|
185
181
|
}
|
|
186
182
|
if (typeof options.projectRoot !== "undefined") {
|
|
187
183
|
return {
|
|
188
184
|
functionsSource: instanceId,
|
|
189
|
-
configDir: (0, path_1.
|
|
185
|
+
configDir: (0, path_1.resolve)(options.projectRoot, instanceId),
|
|
190
186
|
projectId: projectId,
|
|
191
187
|
isEmulator: false,
|
|
192
188
|
projectDir: options.projectRoot,
|
|
@@ -195,10 +191,10 @@ function kitExportTarget(instanceId, projectId, options) {
|
|
|
195
191
|
else {
|
|
196
192
|
return {
|
|
197
193
|
functionsSource: instanceId,
|
|
198
|
-
configDir: instanceId,
|
|
194
|
+
configDir: (0, path_1.resolve)(cwd, instanceId),
|
|
199
195
|
projectId: projectId,
|
|
200
196
|
isEmulator: false,
|
|
201
|
-
projectDir:
|
|
197
|
+
projectDir: cwd,
|
|
202
198
|
};
|
|
203
199
|
}
|
|
204
200
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
|
|
6
|
+
const command_1 = require("../command");
|
|
7
|
+
const projectUtils_1 = require("../projectUtils");
|
|
8
|
+
const extensionsHelper_1 = require("../extensions/extensionsHelper");
|
|
9
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
10
|
+
const migrate_1 = require("../extensions/migrate");
|
|
11
|
+
const kits_1 = require("../functions/kits");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
exports.command = new command_1.Command("ext:migrate")
|
|
15
|
+
.description("migrate an extension instance to a function kit")
|
|
16
|
+
.option("-p, --package <package>", "optional kit package override to use")
|
|
17
|
+
.option("-i, --ext-instance <instanceId>", "extension instance ID to migrate")
|
|
18
|
+
.option("-e, --extension <extensionRef>", "extension reference or name to migrate")
|
|
19
|
+
.before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.list"])
|
|
20
|
+
.before(extensionsHelper_1.ensureExtensionsApiEnabled)
|
|
21
|
+
.before(checkMinRequiredVersion_1.checkMinRequiredVersion, "extMinVersion")
|
|
22
|
+
.action(async (options) => {
|
|
23
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
24
|
+
if (options.package) {
|
|
25
|
+
(0, kits_1.validateNpmPackageName)(options.package);
|
|
26
|
+
}
|
|
27
|
+
const plan = await (0, migrate_1.createMigrationPlan)(projectId, {
|
|
28
|
+
package: options.package,
|
|
29
|
+
extInstance: options.extInstance,
|
|
30
|
+
extension: options.extension,
|
|
31
|
+
nonInteractive: options.nonInteractive,
|
|
32
|
+
});
|
|
33
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Selected instance ${clc.bold(plan.instanceId)} (${plan.kitPackage}) for migration.`);
|
|
34
|
+
logger_1.logger.info("TODO: Draw the rest of the owl");
|
|
35
|
+
return plan;
|
|
36
|
+
});
|