Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
06b62a1
Adding onPoll option to operation-poller (#3046)
joehan Jan 19, 2021
6258dd5
Typescriptify functionsDeployHelper (#3059)
joehan Jan 20, 2021
ec7d079
Typescriptifying gcp.cloudfunctions (#3060)
joehan Jan 20, 2021
f583ef6
Typescriptifying functionsConfig (#3063)
joehan Jan 21, 2021
08b9d56
Typescriptifying deploymentTool (#3061)
joehan Jan 21, 2021
b4944a4
Refactoring prepare stage of functions deploy (#3067)
joehan Jan 21, 2021
3be0dca
refactoring release step of functions deploy to use typescript
joehan Jan 21, 2021
e0e703e
Adding logic to build regional deployments
joehan Jan 24, 2021
046c7d7
Implementing createDeploymentPlan
joehan Jan 26, 2021
b876523
First round of PR feedback, removing most usages of lodash
joehan Jan 28, 2021
9e0e6e9
moving function prompts into their own file
joehan Jan 28, 2021
2a3b547
seperating out a bunch of code from functionsDeployHelper
joehan Jan 28, 2021
51f2395
Resolves merge conflicts
joehan Jan 28, 2021
30cc0e9
refactoring release step of functions deploy to use typescript (#3071)
joehan Feb 1, 2021
6916000
Implements core logic of running function deploys
joehan Feb 1, 2021
3c8d4a0
Typescriptifying prepareFunctionsUpload (#3064)
joehan Feb 1, 2021
11956fa
Implementing createDeploymentPlan (#3081)
joehan Feb 1, 2021
85d0afe
adding timing and logs for deployments
joehan Feb 2, 2021
00b1989
cleaning up unused code
joehan Feb 2, 2021
397d7c4
Fixing some things that were broken while merging
joehan Feb 3, 2021
21f4906
Fixing up the order of wait and close to ensure that queue promsies a…
joehan Feb 4, 2021
3b3edbd
Format and clean up typos
joehan Feb 4, 2021
e428bcb
refactoring error handling to be cleaner
joehan Feb 5, 2021
4c8e2fb
cleaning up extera newlines
joehan Feb 8, 2021
7f48130
first round of pr fixes
joehan Feb 9, 2021
39a7e86
Readding some changes that I accidenttally wiped out during a merge
joehan Feb 9, 2021
1366955
Switching name to id where appropriate
joehan Feb 9, 2021
7513229
fixing another bug caused by functionName vs Id
joehan Feb 9, 2021
8d3d82d
Merge pull request #3107 from firebase/jh-execute-deployment-plans
joehan Feb 9, 2021
6d2260e
Refactor functions-delete (#3110)
joehan Feb 9, 2021
42e6c15
Cleaning up error reporting
joehan Feb 10, 2021
e4ce126
Merge remote-tracking branch 'public/master' into jh-functions-refactor
joehan Feb 10, 2021
12a48ea
Merge remote-tracking branch 'public/master' into jh-functions-refactor
joehan Feb 11, 2021
7cfe9d9
Implement validation for changing trigger types, and fixes from bug b…
joehan Feb 12, 2021
5eb08bd
Merge branch 'master' into jh-functions-refactor
joehan Feb 12, 2021
5ca6bbf
Merge branch 'master' into jh-functions-refactor
joehan Feb 16, 2021
344b674
fixes package.json
joehan Feb 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
},
"dependencies": {
"@google-cloud/pubsub": "^2.7.0",
"@types/archiver": "^5.1.0",
"@types/filesize": "^5.0.0",
"JSONStream": "^1.2.1",
"abort-controller": "^3.0.0",
"archiver": "^3.0.0",
Expand All @@ -98,7 +100,7 @@
"exegesis-express": "^2.0.0",
"exit-code": "^1.0.2",
"express": "^4.16.4",
"filesize": "^3.1.3",
"filesize": "^6.1.0",
"fs-extra": "^0.23.1",
"glob": "^7.1.2",
"google-auth-library": "^6.1.3",
Expand Down
70 changes: 0 additions & 70 deletions src/deploy/functions/createOrUpdateSchedulesAndTopics.ts

This file was deleted.

84 changes: 43 additions & 41 deletions src/deploy/functions/deploymentPlanner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as deploymentTool from "../../deploymentTool";
import { functionMatchesAnyGroup, getTopicName } from "../../functionsDeployHelper";

// TODO: Better name for this?
// It's really a CloudFuntion, not just a trigger,
// but CloudFunction is a different exported type from firebase-functions
export interface CloudFunctionTrigger {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joehan how about CloudFunctionConfig?

name: string;
sourceUploadUrl?: string;
Expand Down Expand Up @@ -31,10 +34,9 @@ export interface RegionMap {
export interface RegionalDeployment {
region: string;
sourceToken?: string;
firstFunctionDeployment?: () => any;
functionsToCreate: CloudFunctionTrigger[];
functionsToUpdate: CloudFunctionTrigger[];
schedulesToCreateOrUpdate: CloudFunctionTrigger[];
schedulesToUpsert: CloudFunctionTrigger[];
}

export interface DeploymentPlan {
Expand All @@ -47,14 +49,14 @@ export interface DeploymentPlan {
* Creates a map of regions to all the CloudFunctions being deployed
* to that region.
* @param projectId The project in use.
* @param parsedTriggers A list of all CloudFunctions in the deployment.
* @param localFunctions A list of all CloudFunctions in the deployment.
*/
export function createFunctionsByRegionMap(
export function functionsByRegion(
projectId: string,
parsedTriggers: CloudFunctionTrigger[]
localFunctions: CloudFunctionTrigger[]
): RegionMap {
const regionMap: RegionMap = {};
for (const trigger of parsedTriggers) {
for (const trigger of localFunctions) {
if (!trigger.regions) {
trigger.regions = ["us-central1"];
}
Expand Down Expand Up @@ -84,7 +86,7 @@ export function createFunctionsByRegionMap(
* Helper method to turn a RegionMap into a flat list of all functions in a deployment.
* @param regionMap A RegionMap for the deployment.
*/
export function flattenRegionMap(regionMap: RegionMap): CloudFunctionTrigger[] {
export function allFunctions(regionMap: RegionMap): CloudFunctionTrigger[] {
const triggers: CloudFunctionTrigger[] = [];
for (const [k, v] of Object.entries(regionMap)) {
triggers.push(...v);
Expand All @@ -95,59 +97,59 @@ export function flattenRegionMap(regionMap: RegionMap): CloudFunctionTrigger[] {
/**
* Create a plan for deploying all functions in one region.
* @param region The region of this deployment
* @param functionsInSourceByRegion The functions present in the code currently being deployed.
* @param loclFunctionsByRegion The functions present in the code currently being deployed.
* @param existingFunctionNames The names of all functions that already exist.
* @param existingScheduledFunctionNames The names of all schedules functions that already exist.
* @param filters The filters, passed in by the user via `--only functions:`
*/
export function createDeploymentPlan(
functionsInSourceByRegion: RegionMap,
localFunctionsByRegion: RegionMap,
existingFunctions: CloudFunctionTrigger[],
filters: string[][]
): DeploymentPlan {
let existingFnsCopy: CloudFunctionTrigger[] = [...existingFunctions];
const deployment: DeploymentPlan = {
regionalDeployments: [],
functionsToDelete: [],
schedulesToDelete: [],
};
// eslint-disable-next-line guard-for-in
for (const region in functionsInSourceByRegion) {
for (const region in localFunctionsByRegion) {
const regionalDeployment: RegionalDeployment = {
region,
functionsToCreate: [],
functionsToUpdate: [],
schedulesToCreateOrUpdate: [],
schedulesToUpsert: [],
};
const localFunctionsInRegion = functionsInSourceByRegion[region];
const localFunctionsInRegion = localFunctionsByRegion[region];
for (const fn of localFunctionsInRegion) {
// Check if this function matches the --only filters
if (functionMatchesAnyGroup(fn.name, filters)) {
// Check if this local function has the same name as an exisiting one.
const matchingExistingFunction = existingFunctions.find((exFn) => {
return exFn.name === fn.name;
});
// Check if the matching exisitng function is scheduled
const isMatchingExisitingFnScheduled =
matchingExistingFunction?.labels?.["deployment-scheduled"] === "true";
// Check if the local function is a scheduled function
if (fn.schedule) {
// If the local function is scheduled, set its trigger to the correct pubsub topic
fn.eventTrigger.resource = getTopicName(fn.name);
// and create or update a schedule.
regionalDeployment.schedulesToCreateOrUpdate.push(fn);
} else if (isMatchingExisitingFnScheduled) {
// If the local function isn't scheduled but the existing one is, delete the schedule.
deployment.schedulesToDelete.push(matchingExistingFunction!.name);
}
if (!functionMatchesAnyGroup(fn.name, filters)) {
continue;
}
// Check if this local function has the same name as an exisiting one.
const matchingExistingFunction = existingFnsCopy.find((exFn) => exFn.name === fn.name);
// Check if the matching exisitng function is scheduled
const isMatchingExisitingFnScheduled =
matchingExistingFunction?.labels?.["deployment-scheduled"] === "true";
// Check if the local function is a scheduled function
if (fn.schedule) {
// If the local function is scheduled, set its trigger to the correct pubsub topic
fn.eventTrigger.resource = getTopicName(fn.name);
// and create or update a schedule.
regionalDeployment.schedulesToUpsert.push(fn);
} else if (isMatchingExisitingFnScheduled) {
// If the local function isn't scheduled but the existing one is, delete the schedule.
deployment.schedulesToDelete.push(matchingExistingFunction!.name);
}

if (!matchingExistingFunction) {
regionalDeployment.functionsToCreate.push(fn);
} else {
regionalDeployment.functionsToUpdate.push(fn);
existingFunctions = existingFunctions.filter((exFn: CloudFunctionTrigger) => {
return exFn.name !== fn.name;
});
}
if (matchingExistingFunction) {
regionalDeployment.functionsToUpdate.push(fn);
existingFnsCopy = existingFnsCopy.filter((exFn: CloudFunctionTrigger) => {
return exFn.name !== fn.name;
});
} else {
regionalDeployment.functionsToCreate.push(fn);
}
}
deployment.regionalDeployments.push(regionalDeployment);
Expand All @@ -156,12 +158,12 @@ export function createDeploymentPlan(
// Delete any remaining existing functions that:
// 1 - Have the deployment-tool: 'firebase-cli' label and
// 2 - Match the --only filters, if any are provided.
const functionsToDelete = existingFunctions
const functionsToDelete = existingFnsCopy
.filter((fn) => {
return deploymentTool.check(fn.labels);
return deploymentTool.isFirebaseManaged(fn.labels);
})
.filter((fn) => {
return filters.length ? functionMatchesAnyGroup(fn.name, filters) : true;
return functionMatchesAnyGroup(fn.name, filters);
});
deployment.functionsToDelete = functionsToDelete.map((fn) => {
return fn.name;
Expand Down
Loading