firebase-tools 15.32.1 → 15.34.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/README.md +9 -0
- package/lib/api.js +4 -2
- package/lib/apphosting/backend.js +1 -1
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +30 -23
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/crashlytics-heapdumps-disable.js +26 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +54 -0
- package/lib/commands/crashlytics-heapdumps-status.js +32 -0
- package/lib/commands/deploy.js +3 -0
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +102 -31
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +7 -0
- package/lib/commands/run-services-update.js +16 -0
- package/lib/crashlytics/onboarding.js +17 -2
- package/lib/crashlytics/profilingManager.js +195 -0
- package/lib/deploy/apphosting/prepare.js +1 -0
- package/lib/deploy/auth/deploy.js +1 -1
- package/lib/deploy/auth/prepare.js +6 -7
- package/lib/deploy/firestore/prepare.js +5 -5
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/executor.js +7 -3
- package/lib/deploy/functions/release/fabricator.js +42 -14
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/deploy/index.js +5 -0
- package/lib/deploy/run/args.js +2 -0
- package/lib/deploy/run/buildEnv.js +72 -0
- package/lib/deploy/run/deploy.js +214 -0
- package/lib/deploy/run/index.js +23 -0
- package/lib/deploy/run/prepare.js +47 -0
- package/lib/deploy/run/prereqs.js +32 -0
- package/lib/deploy/run/release.js +9 -0
- package/lib/deploy/run/update.js +50 -0
- package/lib/deploy/run/util.js +73 -0
- package/lib/emulator/apphosting/serve.js +1 -1
- package/lib/emulator/auth/utils.js +1 -1
- package/lib/emulator/commandUtils.js +7 -3
- package/lib/emulator/dataconnect/pgliteServer.js +1 -1
- package/lib/emulator/dataconnectEmulator.js +1 -1
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +1 -3
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -41
- package/lib/experiments.js +12 -11
- package/lib/firestore/validator.js +1 -1
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +3 -0
- package/lib/functions/env.js +4 -2
- package/lib/functions/projectConfig.js +10 -5
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudsql/permissions.js +21 -32
- package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
- package/lib/gcp/cloudtasks.js +14 -0
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/gcp/storage.js +9 -5
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/init/features/index.js +4 -1
- package/lib/init/features/run.js +159 -0
- package/lib/init/index.js +6 -0
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +12 -9
- package/lib/throttler/throttler.js +1 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +2 -8
- package/schema/firebaserc.json +133 -0
- package/lib/mcp/resources/guides/init_data_connect.js +0 -30
- package/lib/mcp/resources/guides/init_rtdb.js +0 -30
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deploy = deploy;
|
|
4
|
+
exports.revisionTemplate = revisionTemplate;
|
|
5
|
+
exports.localBuildTemplate = localBuildTemplate;
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const constants_1 = require("../../apphosting/constants");
|
|
10
|
+
const localbuilds_1 = require("../../apphosting/localbuilds");
|
|
11
|
+
const error_1 = require("../../error");
|
|
12
|
+
const artifactregistry = require("../../gcp/artifactregistry");
|
|
13
|
+
const runv2 = require("../../gcp/runv2");
|
|
14
|
+
const gcs = require("../../gcp/storage");
|
|
15
|
+
const getProjectNumber_1 = require("../../getProjectNumber");
|
|
16
|
+
const logger_1 = require("../../logger");
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
const prepare_1 = require("../apphosting/prepare");
|
|
19
|
+
const util_1 = require("../apphosting/util");
|
|
20
|
+
const buildEnv_1 = require("./buildEnv");
|
|
21
|
+
const util_2 = require("./util");
|
|
22
|
+
const DEPLOY_MESSAGE_ANNOTATION = "firebase.google.com/deploy-message";
|
|
23
|
+
const ROLLOUT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
24
|
+
const NO_IMAGE = "scratch";
|
|
25
|
+
async function deploy(context, options, payload) {
|
|
26
|
+
for (const svc of payload.run?.services || []) {
|
|
27
|
+
if (svc.config.localBuild) {
|
|
28
|
+
await deployLocalBuild(context, options, svc);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
await deployRemoteBuild(context, options, svc);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function deployRemoteBuild(context, options, svc) {
|
|
36
|
+
const { projectId } = context;
|
|
37
|
+
const source = await uploadSource(projectId, options, svc.config);
|
|
38
|
+
const image = await buildImage(projectId, svc, source);
|
|
39
|
+
const template = revisionTemplate(svc, image, options.message);
|
|
40
|
+
svc.deployed = await rollOut(projectId, svc, template);
|
|
41
|
+
}
|
|
42
|
+
async function deployLocalBuild(context, options, svc) {
|
|
43
|
+
const { projectId } = context;
|
|
44
|
+
const scratchDir = fs.mkdtempSync(path.join(os.tmpdir(), `run-local-build-${svc.config.serviceId}-`));
|
|
45
|
+
try {
|
|
46
|
+
const build = await buildLocally(context, options, svc, scratchDir);
|
|
47
|
+
const builtApp = await uploadBuiltApp(projectId, options, svc.config, scratchDir, build);
|
|
48
|
+
const message = options.message;
|
|
49
|
+
const template = localBuildTemplate(svc, build, builtApp, message);
|
|
50
|
+
svc.deployed = await rollOut(projectId, svc, template);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
removeTempPath(scratchDir);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function buildLocally(context, options, svc, scratchDir) {
|
|
57
|
+
const { config } = svc;
|
|
58
|
+
const { serviceId, region } = config;
|
|
59
|
+
const cfg = toAppHostingConfig(config);
|
|
60
|
+
(0, localbuilds_1.validateLocalBuildNodeVersion)({ runtime: { value: svc.baseImage?.split("/").pop() } }, path.join(options.config.projectDir, cfg.rootDir));
|
|
61
|
+
(0, utils_1.logLabeledBullet)("run", `Starting local build for service ${serviceId} in ${region}`);
|
|
62
|
+
const secrets = (0, buildEnv_1.secretNames)(svc.buildEnv || {});
|
|
63
|
+
if (secrets.length) {
|
|
64
|
+
(0, utils_1.logLabeledBullet)("run", `Reading build secrets ${secrets.join(", ")} with your credentials. Their values may be ` +
|
|
65
|
+
`included in the build output.`);
|
|
66
|
+
}
|
|
67
|
+
await (0, prepare_1.prepareLocalBuildScratchDirectory)(options.config.projectDir, scratchDir, cfg);
|
|
68
|
+
const { outputFiles, buildConfig } = await (0, localbuilds_1.localBuild)(context.projectId, scratchDir, (0, buildEnv_1.toLocalBuildEnv)(svc.buildEnv || {}), { rootDir: config.rootDir, allowLocalBuildSecrets: true });
|
|
69
|
+
const env = (buildConfig.env || [])
|
|
70
|
+
.filter((e) => e.variable &&
|
|
71
|
+
e.value !== undefined &&
|
|
72
|
+
(!e.availability || e.availability.includes("RUNTIME")))
|
|
73
|
+
.map((e) => ({ name: e.variable, value: e.value }));
|
|
74
|
+
return { outputFiles, runCommand: buildConfig.runCommand, env };
|
|
75
|
+
}
|
|
76
|
+
async function uploadSource(projectId, options, config) {
|
|
77
|
+
const { serviceId, region } = config;
|
|
78
|
+
const bucketName = await sourceBucket(projectId, options, region);
|
|
79
|
+
const cfg = toAppHostingConfig(config);
|
|
80
|
+
const archive = await (0, util_1.createSourceDeployArchive)(cfg, path.join(options.config.projectDir, cfg.rootDir));
|
|
81
|
+
(0, utils_1.logLabeledBullet)("run", `Uploading source for service ${serviceId} in ${region}...`);
|
|
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 };
|
|
92
|
+
}
|
|
93
|
+
async function sourceBucket(projectId, options, region) {
|
|
94
|
+
const baseName = `firebase-run-src-${await (0, getProjectNumber_1.getProjectNumber)(options)}-${region.toLowerCase()}`;
|
|
95
|
+
return gcs.upsertBucket({
|
|
96
|
+
product: "run",
|
|
97
|
+
createMessage: `Creating Cloud Storage bucket in ${region} to store Cloud Run source code uploads at ${baseName}...`,
|
|
98
|
+
projectId,
|
|
99
|
+
req: {
|
|
100
|
+
baseName,
|
|
101
|
+
purposeLabel: `run-source-${region.toLowerCase()}`,
|
|
102
|
+
location: region,
|
|
103
|
+
lifecycle: { rule: [{ action: { type: "Delete" }, condition: { age: 30 } }] },
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async function buildImage(projectId, svc, source) {
|
|
108
|
+
const { serviceId, region } = svc.config;
|
|
109
|
+
await artifactregistry.ensureDockerRepository(projectId, region, "cloud-run-source-deploy");
|
|
110
|
+
const imageUri = `${region}-docker.pkg.dev/${projectId}/cloud-run-source-deploy/${serviceId}:${Date.now()}`;
|
|
111
|
+
(0, utils_1.logLabeledBullet)("run", `Building service ${serviceId} in ${region}...`);
|
|
112
|
+
const buildpackBuild = {
|
|
113
|
+
environmentVariables: {
|
|
114
|
+
...(0, buildEnv_1.nonSecretValues)(svc.buildEnv || {}),
|
|
115
|
+
X_GOOGLE_TARGET_PLATFORM: "fah",
|
|
116
|
+
FIREBASE_OUTPUT_BUNDLE_DIR: "/workspace/.apphosting",
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
if (svc.baseImage) {
|
|
120
|
+
buildpackBuild.baseImage = svc.baseImage;
|
|
121
|
+
buildpackBuild.enableAutomaticUpdates = true;
|
|
122
|
+
}
|
|
123
|
+
await runv2.submitBuild(projectId, region, { storageSource: source, imageUri, buildpackBuild });
|
|
124
|
+
return imageUri;
|
|
125
|
+
}
|
|
126
|
+
function revisionTemplate(svc, image, message) {
|
|
127
|
+
const { serviceId, region } = svc.config;
|
|
128
|
+
const template = svc.existing
|
|
129
|
+
? (0, utils_1.cloneDeep)(svc.existing.template)
|
|
130
|
+
: { containers: [{ name: serviceId, image }] };
|
|
131
|
+
delete template.revision;
|
|
132
|
+
const container = (0, util_2.mainContainer)(template);
|
|
133
|
+
if (!container) {
|
|
134
|
+
throw new error_1.FirebaseError(`Service ${serviceId} in ${region} has no containers.`);
|
|
135
|
+
}
|
|
136
|
+
container.image = image;
|
|
137
|
+
if (container.sourceCode) {
|
|
138
|
+
delete container.sourceCode;
|
|
139
|
+
delete container.command;
|
|
140
|
+
}
|
|
141
|
+
if (svc.baseImage) {
|
|
142
|
+
container.baseImageUri = svc.baseImage;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
delete container.baseImageUri;
|
|
146
|
+
}
|
|
147
|
+
if (message) {
|
|
148
|
+
template.annotations = { ...template.annotations, [DEPLOY_MESSAGE_ANNOTATION]: message };
|
|
149
|
+
}
|
|
150
|
+
else if (template.annotations) {
|
|
151
|
+
delete template.annotations[DEPLOY_MESSAGE_ANNOTATION];
|
|
152
|
+
}
|
|
153
|
+
return template;
|
|
154
|
+
}
|
|
155
|
+
function localBuildTemplate(svc, build, builtApp, message) {
|
|
156
|
+
const template = revisionTemplate(svc, NO_IMAGE, message);
|
|
157
|
+
const container = (0, util_2.mainContainer)(template);
|
|
158
|
+
container.sourceCode = { cloudStorageSource: builtApp };
|
|
159
|
+
const command = build.runCommand?.trim();
|
|
160
|
+
if (command) {
|
|
161
|
+
container.command = command.split(/\s+/);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
delete container.command;
|
|
165
|
+
}
|
|
166
|
+
if (build.env.length) {
|
|
167
|
+
const buildNames = new Set(build.env.map((e) => e.name));
|
|
168
|
+
const otherEnv = (container.env || []).filter((e) => !buildNames.has(e.name));
|
|
169
|
+
container.env = [...otherEnv, ...build.env];
|
|
170
|
+
}
|
|
171
|
+
return template;
|
|
172
|
+
}
|
|
173
|
+
function rollOut(projectId, svc, template) {
|
|
174
|
+
if (svc.existing) {
|
|
175
|
+
return deployRevision(svc.existing, template);
|
|
176
|
+
}
|
|
177
|
+
return createNewService(projectId, svc.config, template);
|
|
178
|
+
}
|
|
179
|
+
function createNewService(projectId, config, template) {
|
|
180
|
+
const { serviceId, region } = config;
|
|
181
|
+
return runv2.createService(projectId, region, serviceId, {
|
|
182
|
+
name: `projects/${projectId}/locations/${region}/services/${serviceId}`,
|
|
183
|
+
template,
|
|
184
|
+
client: "cli-firebase",
|
|
185
|
+
invokerIamDisabled: true,
|
|
186
|
+
ingress: "INGRESS_TRAFFIC_ALL",
|
|
187
|
+
}, { pollTimeoutMs: ROLLOUT_TIMEOUT_MS });
|
|
188
|
+
}
|
|
189
|
+
function deployRevision(service, template) {
|
|
190
|
+
const tags = (service.traffic || [])
|
|
191
|
+
.filter((t) => t.tag)
|
|
192
|
+
.map((t) => ({ type: t.type, revision: t.revision, tag: t.tag }));
|
|
193
|
+
return runv2.updateService({
|
|
194
|
+
name: service.name,
|
|
195
|
+
template,
|
|
196
|
+
traffic: [{ type: "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST", percent: 100 }, ...tags],
|
|
197
|
+
}, { updateMask: ["template", "traffic"], pollTimeoutMs: ROLLOUT_TIMEOUT_MS });
|
|
198
|
+
}
|
|
199
|
+
function toAppHostingConfig(config) {
|
|
200
|
+
return {
|
|
201
|
+
backendId: config.serviceId,
|
|
202
|
+
rootDir: config.rootDir || "",
|
|
203
|
+
ignore: config.ignore,
|
|
204
|
+
localBuild: config.localBuild,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function removeTempPath(tempPath) {
|
|
208
|
+
try {
|
|
209
|
+
fs.rmSync(tempPath, { recursive: true, force: true });
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
logger_1.logger.debug(`Failed to clean up ${tempPath}: ${(0, error_1.getErrMsg)(err)}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detailedHelp = exports.help = exports.release = exports.deploy = exports.prepare = void 0;
|
|
4
|
+
const prepare_1 = require("./prepare");
|
|
5
|
+
Object.defineProperty(exports, "prepare", { enumerable: true, get: function () { return prepare_1.prepare; } });
|
|
6
|
+
const deploy_1 = require("./deploy");
|
|
7
|
+
Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_1.deploy; } });
|
|
8
|
+
const release_1 = require("./release");
|
|
9
|
+
Object.defineProperty(exports, "release", { enumerable: true, get: function () { return release_1.release; } });
|
|
10
|
+
exports.help = "Builds and deploys web apps to Cloud Run services listed in firebase.json. Supports filtering:\n" +
|
|
11
|
+
" --only run:serviceId (in every region firebase.json lists it in)\n" +
|
|
12
|
+
" --only run:serviceId:region (in one region)";
|
|
13
|
+
exports.detailedHelp = "Deploys Cloud Run services from local source, or from a local build if localBuild is set.\n\n" +
|
|
14
|
+
"Configuration in firebase.json:\n" +
|
|
15
|
+
"{\n" +
|
|
16
|
+
' "run": {\n' +
|
|
17
|
+
' "serviceId": "my-service",\n' +
|
|
18
|
+
' "region": "us-central1",\n' +
|
|
19
|
+
' "rootDir": "/",\n' +
|
|
20
|
+
' "ignore": ["node_modules", ".git"]\n' +
|
|
21
|
+
" }\n" +
|
|
22
|
+
"}\n\n" +
|
|
23
|
+
"Base images are configured on the service with firebase run:services:update --base-image and are reused on every deploy.";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepare = prepare;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const buildEnv_1 = require("./buildEnv");
|
|
7
|
+
const prereqs_1 = require("./prereqs");
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
async function prepare(context, options, payload) {
|
|
10
|
+
const configs = (0, util_1.getServiceConfigs)(options);
|
|
11
|
+
if (!configs.length) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
await (0, prereqs_1.prereqs)(context.projectId);
|
|
15
|
+
payload.run = { services: [] };
|
|
16
|
+
for (const config of configs) {
|
|
17
|
+
payload.run.services.push(await prepareService(context, config));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function prepareService(context, config) {
|
|
21
|
+
const { serviceId, region } = config;
|
|
22
|
+
const existing = await (0, util_1.getExistingService)(context.projectId, region, serviceId);
|
|
23
|
+
let baseImage = (0, util_1.mainContainer)(existing?.template)?.baseImageUri;
|
|
24
|
+
if (context.baseImage !== undefined) {
|
|
25
|
+
baseImage = context.baseImage ?? undefined;
|
|
26
|
+
}
|
|
27
|
+
if (config.localBuild && !baseImage) {
|
|
28
|
+
const fix = existing
|
|
29
|
+
? `firebase run:services:update ${serviceId} --region ${region} --base-image <baseImage>`
|
|
30
|
+
: "firebase init run";
|
|
31
|
+
throw new error_1.FirebaseError(`Local builds require a base image. Set one for service ${serviceId} in ${region} with "${fix}".`);
|
|
32
|
+
}
|
|
33
|
+
const buildEnv = (0, buildEnv_1.getBuildEnv)(existing);
|
|
34
|
+
const secrets = (0, buildEnv_1.secretNames)(buildEnv);
|
|
35
|
+
if (secrets.length && !config.localBuild) {
|
|
36
|
+
throw new error_1.FirebaseError(`Service ${serviceId} in ${region} has build secrets (${secrets.join(", ")}), but only ` +
|
|
37
|
+
`local builds can use secrets: builds on Cloud Build only take plain values. To use ` +
|
|
38
|
+
`them, set "localBuild": true for this service in firebase.json.`);
|
|
39
|
+
}
|
|
40
|
+
const svc = { config, existing, baseImage };
|
|
41
|
+
if (Object.keys(buildEnv).length) {
|
|
42
|
+
(0, utils_1.logLabeledBullet)("run", `Using build environment variables for service ${serviceId} in ${region} from ` +
|
|
43
|
+
`${buildEnv_1.BUILD_ENV_ANNOTATION}: ${Object.keys(buildEnv).join(", ")}`);
|
|
44
|
+
svc.buildEnv = buildEnv;
|
|
45
|
+
}
|
|
46
|
+
return svc;
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RUN_PERMISSIONS = void 0;
|
|
4
|
+
exports.prereqs = prereqs;
|
|
5
|
+
const ensureApiEnabled_1 = require("../../ensureApiEnabled");
|
|
6
|
+
const artifactregistry = require("../../gcp/artifactregistry");
|
|
7
|
+
exports.RUN_PERMISSIONS = [
|
|
8
|
+
"run.services.get",
|
|
9
|
+
"run.services.create",
|
|
10
|
+
"run.services.update",
|
|
11
|
+
"run.services.setIamPolicy",
|
|
12
|
+
"run.operations.get",
|
|
13
|
+
"cloudbuild.builds.create",
|
|
14
|
+
"cloudbuild.builds.get",
|
|
15
|
+
"storage.buckets.get",
|
|
16
|
+
"storage.buckets.list",
|
|
17
|
+
"storage.buckets.create",
|
|
18
|
+
"storage.buckets.update",
|
|
19
|
+
"storage.objects.create",
|
|
20
|
+
"artifactregistry.repositories.get",
|
|
21
|
+
"artifactregistry.repositories.create",
|
|
22
|
+
"artifactregistry.repositories.downloadArtifacts",
|
|
23
|
+
"iam.serviceAccounts.actAs",
|
|
24
|
+
];
|
|
25
|
+
async function prereqs(projectId) {
|
|
26
|
+
await Promise.all([
|
|
27
|
+
(0, ensureApiEnabled_1.ensure)(projectId, "run.googleapis.com", "run", true),
|
|
28
|
+
(0, ensureApiEnabled_1.ensure)(projectId, "cloudbuild.googleapis.com", "cloudbuild", true),
|
|
29
|
+
(0, ensureApiEnabled_1.ensure)(projectId, "storage.googleapis.com", "storage", true),
|
|
30
|
+
artifactregistry.ensureApiEnabled(projectId),
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.release = release;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
async function release(_context, _options, payload) {
|
|
6
|
+
for (const { config, deployed } of payload.run?.services || []) {
|
|
7
|
+
(0, utils_1.logLabeledSuccess)("run", `Deployed service ${config.serviceId} in ${config.region}${deployed?.uri ? ` to ${deployed.uri}` : ""}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateService = updateService;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
async function updateService(serviceId, region, options) {
|
|
10
|
+
const settings = {
|
|
11
|
+
baseImage: readFlagPair(options.baseImage, options.clearBaseImage, "base-image"),
|
|
12
|
+
};
|
|
13
|
+
if (Object.values(settings).every((value) => value === undefined)) {
|
|
14
|
+
throw new error_1.FirebaseError("Specify a setting to update: --base-image <baseImage> or --clear-base-image.");
|
|
15
|
+
}
|
|
16
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
17
|
+
const config = findServiceToUpdate(serviceId, region, options);
|
|
18
|
+
if (settings.baseImage === null && config.localBuild) {
|
|
19
|
+
throw new error_1.FirebaseError(`Cannot clear the base image of ${config.serviceId}: local builds need one.`);
|
|
20
|
+
}
|
|
21
|
+
if (!(await (0, util_1.getExistingService)(projectId, config.region, config.serviceId))) {
|
|
22
|
+
const howToCreate = config.localBuild
|
|
23
|
+
? clc.bold("firebase init run")
|
|
24
|
+
: `${clc.bold("firebase init run")} or ` +
|
|
25
|
+
clc.bold(`firebase deploy --only run:${(0, util_1.fullServiceName)(config)}`);
|
|
26
|
+
throw new error_1.FirebaseError(`Cloud Run service ${config.serviceId} doesn't exist in ${config.region} yet. ` +
|
|
27
|
+
`Create it with ${howToCreate}, then update it.`);
|
|
28
|
+
}
|
|
29
|
+
await (0, __1.deploy)(["run"], { ...options, only: `run:${(0, util_1.fullServiceName)(config)}` }, settings);
|
|
30
|
+
}
|
|
31
|
+
function readFlagPair(value, clear, flag) {
|
|
32
|
+
if (value && clear) {
|
|
33
|
+
throw new error_1.FirebaseError(`Use either --${flag} or --clear-${flag}, not both.`);
|
|
34
|
+
}
|
|
35
|
+
return clear ? null : value;
|
|
36
|
+
}
|
|
37
|
+
function findServiceToUpdate(serviceId, region, options) {
|
|
38
|
+
const matches = (0, util_1.getAllServiceConfigs)(options).filter((c) => c.serviceId === serviceId && (!region || c.region === region));
|
|
39
|
+
if (!matches.length) {
|
|
40
|
+
const service = region ? `${serviceId} in ${region}` : serviceId;
|
|
41
|
+
throw new error_1.FirebaseError(`Cloud Run service ${service} not detected in firebase.json.`);
|
|
42
|
+
}
|
|
43
|
+
if (matches.length > 1) {
|
|
44
|
+
const regions = matches.map((c) => c.region);
|
|
45
|
+
const example = `firebase run:services:update ${serviceId} --region ${regions[0]}`;
|
|
46
|
+
throw new error_1.FirebaseError(`firebase.json lists ${serviceId} in ${regions.length} regions: ${regions.join(", ")}. ` +
|
|
47
|
+
`Pick one with --region, e.g. ${example}`);
|
|
48
|
+
}
|
|
49
|
+
return matches[0];
|
|
50
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllServiceConfigs = getAllServiceConfigs;
|
|
4
|
+
exports.getServiceConfigs = getServiceConfigs;
|
|
5
|
+
exports.findServices = findServices;
|
|
6
|
+
exports.fullServiceName = fullServiceName;
|
|
7
|
+
exports.getExistingService = getExistingService;
|
|
8
|
+
exports.mainContainer = mainContainer;
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
const runv2 = require("../../gcp/runv2");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
function getAllServiceConfigs(options) {
|
|
13
|
+
const configs = [options.config?.src?.run ?? []].flat();
|
|
14
|
+
const names = new Set();
|
|
15
|
+
for (const config of configs) {
|
|
16
|
+
if (!config.region) {
|
|
17
|
+
throw new error_1.FirebaseError(`Cloud Run service ${config.serviceId} is missing a region in firebase.json.`);
|
|
18
|
+
}
|
|
19
|
+
const name = fullServiceName(config);
|
|
20
|
+
if (names.has(name)) {
|
|
21
|
+
throw new error_1.FirebaseError(`Cloud Run service ${name} is listed more than once in firebase.json.`);
|
|
22
|
+
}
|
|
23
|
+
names.add(name);
|
|
24
|
+
}
|
|
25
|
+
return configs;
|
|
26
|
+
}
|
|
27
|
+
function getServiceConfigs(options) {
|
|
28
|
+
const configs = getAllServiceConfigs(options);
|
|
29
|
+
const filters = options.only ? options.only.split(",") : ["run"];
|
|
30
|
+
if (filters.includes("run")) {
|
|
31
|
+
return configs;
|
|
32
|
+
}
|
|
33
|
+
const selected = filters
|
|
34
|
+
.filter((f) => f.startsWith("run:"))
|
|
35
|
+
.flatMap((filter) => {
|
|
36
|
+
const name = filter.slice("run:".length);
|
|
37
|
+
const matches = findServices(configs, name);
|
|
38
|
+
if (!matches.length) {
|
|
39
|
+
throw new error_1.FirebaseError(`Cloud Run service ${name} not detected in firebase.json.`);
|
|
40
|
+
}
|
|
41
|
+
if (matches.length > 1) {
|
|
42
|
+
(0, utils_1.logLabeledBullet)("run", `${filter} matches ${matches.length} services in firebase.json: ` +
|
|
43
|
+
`${matches.map(fullServiceName).join(", ")}. Deploying all of them. ` +
|
|
44
|
+
`To deploy just one, use --only ${filter}:<region>.`);
|
|
45
|
+
}
|
|
46
|
+
return matches;
|
|
47
|
+
});
|
|
48
|
+
return configs.filter((c) => selected.includes(c));
|
|
49
|
+
}
|
|
50
|
+
function findServices(configs, name) {
|
|
51
|
+
const [serviceId, region, ...rest] = name.split(":");
|
|
52
|
+
if (!serviceId || region === "" || rest.length) {
|
|
53
|
+
throw new error_1.FirebaseError(`Invalid Cloud Run service "${name}". Use <serviceId> or <serviceId>:<region>.`);
|
|
54
|
+
}
|
|
55
|
+
return configs.filter((c) => c.serviceId === serviceId && (!region || c.region === region));
|
|
56
|
+
}
|
|
57
|
+
function fullServiceName(config) {
|
|
58
|
+
return `${config.serviceId}:${config.region}`;
|
|
59
|
+
}
|
|
60
|
+
async function getExistingService(projectId, region, serviceId) {
|
|
61
|
+
try {
|
|
62
|
+
return await runv2.getService(projectId, region, serviceId);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if ((0, error_1.getErrStatus)(err) === 404) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function mainContainer(template) {
|
|
72
|
+
return template?.containers?.[0];
|
|
73
|
+
}
|
|
@@ -107,7 +107,7 @@ async function tripFirebasePostinstall(rootDirectory, env) {
|
|
|
107
107
|
for (const dependency of dependenciesToSearch) {
|
|
108
108
|
if (dependency.name === "@firebase/util" &&
|
|
109
109
|
(0, semver_1.gte)(dependency.version, "1.11.0") &&
|
|
110
|
-
firebaseUtilPaths.
|
|
110
|
+
!firebaseUtilPaths.includes(dependency.path)) {
|
|
111
111
|
firebaseUtilPaths.push(dependency.path);
|
|
112
112
|
}
|
|
113
113
|
if (dependency.dependencies) {
|
|
@@ -19,7 +19,7 @@ function isValidEmailAddress(email) {
|
|
|
19
19
|
return /^[^@]+@[^@]+$/.test(email);
|
|
20
20
|
}
|
|
21
21
|
function isValidPhoneNumber(phoneNumber) {
|
|
22
|
-
return
|
|
22
|
+
return phoneNumber.startsWith("+");
|
|
23
23
|
}
|
|
24
24
|
function canonicalizeEmailAddress(email) {
|
|
25
25
|
return email.toLowerCase();
|
|
@@ -214,7 +214,7 @@ function processKillSignal(signal, res, rej, options) {
|
|
|
214
214
|
}
|
|
215
215
|
catch (e) {
|
|
216
216
|
logger_1.logger.debug(e);
|
|
217
|
-
rej();
|
|
217
|
+
rej((0, error_2.getError)(e));
|
|
218
218
|
}
|
|
219
219
|
};
|
|
220
220
|
}
|
|
@@ -251,13 +251,17 @@ async function runScript(script, extraEnv) {
|
|
|
251
251
|
return new Promise((resolve, reject) => {
|
|
252
252
|
proc.on("error", (err) => {
|
|
253
253
|
utils.logWarning(`There was an error running the script: ${JSON.stringify(err)}`);
|
|
254
|
-
reject(
|
|
254
|
+
reject(new error_1.FirebaseError("There was an error running the script.", {
|
|
255
|
+
original: err instanceof Error ? err : undefined,
|
|
256
|
+
}));
|
|
255
257
|
});
|
|
256
258
|
const exitDelayMs = 500;
|
|
257
259
|
proc.once("exit", (code, signal) => {
|
|
258
260
|
if (signal) {
|
|
259
261
|
utils.logWarning(`Script exited with signal: ${signal}`);
|
|
260
|
-
setTimeout(
|
|
262
|
+
setTimeout(() => {
|
|
263
|
+
reject(new error_1.FirebaseError(`Script exited with signal: ${signal}`));
|
|
264
|
+
}, exitDelayMs);
|
|
261
265
|
return;
|
|
262
266
|
}
|
|
263
267
|
const exitCode = code || 0;
|
|
@@ -165,7 +165,7 @@ class PostgresServer {
|
|
|
165
165
|
return db;
|
|
166
166
|
}
|
|
167
167
|
catch (err) {
|
|
168
|
-
if (pg17Dir && (0, error_1.hasMessage)(err) &&
|
|
168
|
+
if (pg17Dir && (0, error_1.hasMessage)(err) && err.message.includes("Database already exists")) {
|
|
169
169
|
fs.rmSync(pg17Dir, { force: true, recursive: true });
|
|
170
170
|
const db = new pglite_1.PGlite({ ...baseArgs, dataDir: pg17Dir });
|
|
171
171
|
await db.waitReady;
|
|
@@ -105,7 +105,7 @@ class DataConnectEmulator {
|
|
|
105
105
|
const emuInfo = await this.emulatorClient.getInfo();
|
|
106
106
|
if (!emuInfo) {
|
|
107
107
|
this.logger.logLabeled("ERROR", "dataconnect", "Could not connect to SQL Connect emulator. Check dataconnect-debug.log for more details.");
|
|
108
|
-
return Promise.reject();
|
|
108
|
+
return Promise.reject(new error_1.FirebaseError("Could not connect to SQL Connect emulator. Check dataconnect-debug.log for more details."));
|
|
109
109
|
}
|
|
110
110
|
return Promise.resolve();
|
|
111
111
|
}
|
package/lib/emulator/download.js
CHANGED
|
@@ -71,7 +71,7 @@ function removeOldFiles(name, emulator, removeAllVersions = false) {
|
|
|
71
71
|
const files = fs.readdirSync(emulator.opts.cacheDir);
|
|
72
72
|
for (const file of files) {
|
|
73
73
|
const fullFilePath = path.join(emulator.opts.cacheDir, file);
|
|
74
|
-
if (file.
|
|
74
|
+
if (!file.includes(emulator.opts.namePrefix)) {
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
77
|
if ((fullFilePath !== currentLocalPath && fullFilePath !== currentUnzipPath) ||
|
|
@@ -44,46 +44,46 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"pubsub": {
|
|
47
|
-
"version": "0.8.
|
|
48
|
-
"expectedSize":
|
|
49
|
-
"expectedChecksum": "
|
|
50
|
-
"expectedChecksumSHA256": "
|
|
51
|
-
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.
|
|
52
|
-
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
53
|
-
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
47
|
+
"version": "0.8.37",
|
|
48
|
+
"expectedSize": 53029797,
|
|
49
|
+
"expectedChecksum": "62cc150027ebea586c2c53c48c2cbb25",
|
|
50
|
+
"expectedChecksumSHA256": "c83383e0c71633e58abad6fdc9c0312c7d0f6a5a34236c42e3f92eb24ded1c26",
|
|
51
|
+
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.37.zip",
|
|
52
|
+
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.37.zip",
|
|
53
|
+
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.37/pubsub-emulator/bin/cloud-pubsub-emulator"
|
|
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.23",
|
|
58
|
+
"expectedSize": 33978064,
|
|
59
|
+
"expectedChecksum": "98d206c1a991b9a92609659d0533c9fd",
|
|
60
|
+
"expectedChecksumSHA256": "b88f852a34fbaad55c565d09aa758b7614ffba2da73a15218df5f078d8673d61",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.23",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.23"
|
|
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.23",
|
|
66
|
+
"expectedSize": 31927234,
|
|
67
|
+
"expectedChecksum": "c232606e8a5d8fbe2be2f090afea32ad",
|
|
68
|
+
"expectedChecksumSHA256": "a58ded5bcaf5a6cfb3156add51c08c3a126a3f921b10c7426c9e9fb31aa2d0e5",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.23",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.23"
|
|
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.23",
|
|
74
|
+
"expectedSize": 33988608,
|
|
75
|
+
"expectedChecksum": "962fbd2e1ba814f68df68971c44554d8",
|
|
76
|
+
"expectedChecksumSHA256": "ecccb3bb3df107b5792975e7cdf281476630042483b5fe3c334606fcc3770156",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.23",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.23.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.23",
|
|
82
|
+
"expectedSize": 33058978,
|
|
83
|
+
"expectedChecksum": "b1e424fbcf1e6a17bb9220e15fd8fee2",
|
|
84
|
+
"expectedChecksumSHA256": "337ec8a195d6198e83bdeb070b12a64cecbf7aa1ba2c190b6611f78cd128a21a",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.23",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.23"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -459,9 +459,7 @@ async function start(targetName, args, extraEnv = {}) {
|
|
|
459
459
|
return _runBinary(emulator, command, extraEnv);
|
|
460
460
|
}
|
|
461
461
|
function isIncomaptibleArchError(err) {
|
|
462
|
-
return ((0, error_1.hasMessage)(err) &&
|
|
463
|
-
/Unknown system error/.test(err.message ?? "") &&
|
|
464
|
-
process.platform === "darwin");
|
|
462
|
+
return ((0, error_1.hasMessage)(err) && err.message.includes("Unknown system error") && process.platform === "darwin");
|
|
465
463
|
}
|
|
466
464
|
function emulatorVersionOverride(emulator) {
|
|
467
465
|
return process.env[`${emulator.toUpperCase()}_EMULATOR_VERSION`];
|
|
@@ -125,7 +125,7 @@ class EventarcEmulator {
|
|
|
125
125
|
async triggerEventFunction(channel, event) {
|
|
126
126
|
if (!registry_1.EmulatorRegistry.isRunning(types_1.Emulators.FUNCTIONS)) {
|
|
127
127
|
this.logger.log("INFO", "Functions emulator not found. This should not happen.");
|
|
128
|
-
return Promise.reject();
|
|
128
|
+
return Promise.reject(new error_1.FirebaseError("Functions emulator not found. This should not happen."));
|
|
129
129
|
}
|
|
130
130
|
const key = `${event.type}-${channel}`;
|
|
131
131
|
const triggers = this.events[key] || [];
|