[go: nahoru, domu]

Skip to content

Commit

Permalink
Match GCFv1 source upload region to the function deploy region. (#3950)
Browse files Browse the repository at this point in the history
* Upload gcfv1 sources to deploy region, unless overriden by FIREBASE_FUNCTIONS_UPLOAD_REGION environment variable.

* Use source url corresponding to the region.

* Fix small bug.

* Fix bug, let's not support multi-region uploads.

* Simplify a bit.

* Add comment for clarity

* Add changelog.
  • Loading branch information
taeold committed Dec 16, 2021
1 parent 3757c0f commit 37d7b24
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- **BREAKING** Drops support for running the CLI on Node 10.
- **BREAKING** Replaces all usages of `-y`, `--yes`, or `--confirm` with `-f` and `--force`.
- **BREAKING** Function deploys upload source to the deployed region instead of us-central1.
- Requires firebase-functions >= 3.13.1 in Functions emulator to include bug fixes (#3851).
1 change: 0 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ var api = {
"https://cloudfunctions.googleapis.com"
),
runOrigin: utils.envOverride("CLOUD_RUN_URL", "https://run.googleapis.com"),
functionsUploadRegion: utils.envOverride("FIREBASE_FUNCTIONS_UPLOAD_REGION", "us-central1"),
functionsDefaultRegion: utils.envOverride("FIREBASE_FUNCTIONS_DEFAULT_REGION", "us-central1"),
cloudschedulerOrigin: utils.envOverride(
"FIREBASE_CLOUDSCHEDULER_URL",
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/functions/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Context {
firebaseConfig?: FirebaseConfig;

// Filled in the "deploy" phase.
uploadUrl?: string;
sourceUrl?: string;
storage?: Record<string, gcfV2.StorageSource>;
}

Expand Down
16 changes: 8 additions & 8 deletions src/deploy/functions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as clc from "cli-color";
import * as fs from "fs";

import { checkHttpIam } from "./checkIam";
import { functionsUploadRegion } from "../../api";
import { logSuccess, logWarning } from "../../utils";
import { Options } from "../../options";
import * as args from "./args";
Expand All @@ -13,13 +12,11 @@ import * as gcfv2 from "../../gcp/cloudfunctionsv2";
import * as utils from "../../utils";
import * as backend from "./backend";

const GCP_REGION = functionsUploadRegion;

setGracefulCleanup();

async function uploadSourceV1(context: args.Context): Promise<void> {
const uploadUrl = await gcf.generateUploadUrl(context.projectId, GCP_REGION);
context.uploadUrl = uploadUrl;
async function uploadSourceV1(context: args.Context, region: string): Promise<void> {
const uploadUrl = await gcf.generateUploadUrl(context.projectId, region);
context.sourceUrl = uploadUrl;
const uploadOpts = {
file: context.functionsSourceV1!,
stream: fs.createReadStream(context.functionsSourceV1!),
Expand Down Expand Up @@ -63,8 +60,11 @@ export async function deploy(
try {
const want = payload.functions!.backend;
const uploads: Promise<void>[] = [];
if (backend.allEndpoints(want).some((endpoint) => endpoint.platform === "gcfv1")) {
uploads.push(uploadSourceV1(context));

const v1Endpoints = backend.allEndpoints(want).filter((e) => e.platform === "gcfv1");
if (v1Endpoints.length > 0) {
// Choose one of the function region for source upload.
uploads.push(uploadSourceV1(context, v1Endpoints[0].region));
}

for (const region of Object.keys(want.endpoints)) {
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/functions/release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function release(
const fab = new fabricator.Fabricator({
functionExecutor,
executor: new executor.QueueExecutor({}),
sourceUrl: context.uploadUrl!,
sourceUrl: context.sourceUrl!,
storage: context.storage!,
appEngineLocation: getAppEngineLocation(context.firebaseConfig),
});
Expand Down

0 comments on commit 37d7b24

Please sign in to comment.