Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactor of functions deploy #3132

Merged
merged 37 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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.
Jump to
Jump to file
Failed to load files.
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",
"abort-controller": "^3.0.0",
"archiver": "^5.0.0",
"body-parser": "^1.19.0",
Expand All @@ -97,7 +99,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
92 changes: 0 additions & 92 deletions src/commands/functions-delete.js

This file was deleted.

84 changes: 84 additions & 0 deletions src/commands/functions-delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Command } from "../command";
import * as clc from "cli-color";
import * as cloudfunctions from "../gcp/cloudfunctions";
import * as functionsConfig from "../functionsConfig";
import { deleteFunctions } from "../functionsDelete";
import * as getProjectId from "../getProjectId";
import * as helper from "../functionsDeployHelper";
import { prompt } from "../prompt";
import { requirePermissions } from "../requirePermissions";
import * as utils from "../utils";

export default new Command("functions:delete [filters...]")
.description("delete one or more Cloud Functions by name or group name.")
.option(
"--region <region>",
"Specify region of the function to be deleted. " +
"If omitted, functions from all regions whose names match the filters will be deleted. "
)
.option("-f, --force", "No confirmation. Otherwise, a confirmation prompt will appear.")
.before(requirePermissions, ["cloudfunctions.functions.list", "cloudfunctions.functions.delete"])
.action(async (filters, options) => {
if (!filters.length) {
return utils.reject("Must supply at least function or group name.");
}

const projectId = getProjectId(options);

// Dot notation can be used to indicate function inside of a group
const filterChunks = filters.map((filter: string) => {
return filter.split(".");
});
const config = await functionsConfig.getFirebaseConfig(options);
const appEngineLocation = functionsConfig.getAppEngineLocation(config);
const existingFns = await cloudfunctions.listAllFunctions(projectId);
const functionsToDelete = existingFns.filter((fn) => {
const regionMatches = options.region ? helper.getRegion(fn.name) === options.region : true;
const nameMatches = helper.functionMatchesAnyGroup(fn.name, filterChunks);
return regionMatches && nameMatches;
});
if (functionsToDelete.length === 0) {
return utils.reject(
`The specified filters do not match any existing functions in project ${clc.bold(
projectId
)}.`,
{ exit: 1 }
);
}

const scheduledFnNamesToDelete = functionsToDelete
.filter((fn) => {
return fn.labels?.["deployment-scheduled"] === "true";
})
.map((fn) => fn.name);
const fnNamesToDelete = functionsToDelete.map((fn) => fn.name);

let confirmDeletion = false;
if (!options.force) {
const deleteList = fnNamesToDelete
.map((func) => {
return "\t" + helper.getFunctionLabel(func);
})
.join("\n");
confirmDeletion = await prompt(options, [
{
type: "confirm",
name: "confirm",
default: false,
message:
"You are about to delete the following Cloud Functions:\n" +
deleteList +
"\n Are you sure?",
},
]);
}
if (!confirmDeletion && !options.force) {
return utils.reject("Command aborted.", { exit: 1 });
}
return await deleteFunctions(
fnNamesToDelete,
scheduledFnNamesToDelete,
projectId,
appEngineLocation
);
});
18 changes: 7 additions & 11 deletions src/deploy/functions/checkIam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { bold } from "cli-color";

import { debug } from "../../logger";
import * as track from "../../track";
import { getReleaseNames, getFunctionsInfo, getFilterGroups } from "../../functionsDeployHelper";
import { getReleaseNames, getFilterGroups } from "../../functionsDeployHelper";
import { CloudFunctionTrigger } from "./deploymentPlanner";
import { FirebaseError } from "../../error";
import { testIamPermissions, testResourceIamPermissions } from "../../gcp/iam";

Expand Down Expand Up @@ -50,18 +51,13 @@ export async function checkServiceAccountIam(projectId: string): Promise<void> {
* @param options The command-wide options object.
* @param payload The deploy payload.
*/
export async function checkHttpIam(
context: { projectId: string; existingFunctions: { name: string }[] },
options: unknown,
payload: { functions: { triggers: { name: string; httpsTrigger?: {} }[] } }
): Promise<void> {
const triggers = payload.functions.triggers;
const functionsInfo = getFunctionsInfo(triggers, context.projectId);
const filterGroups = getFilterGroups(options);
export async function checkHttpIam(context: any, options: any, payload: any): Promise<void> {
const functionsInfo = payload.functions.triggers;
const filterGroups = context.filters || getFilterGroups(options);

const httpFunctionNames: string[] = functionsInfo
.filter((f) => has(f, "httpsTrigger"))
.map((f) => f.name);
.filter((f: CloudFunctionTrigger) => has(f, "httpsTrigger"))
.map((f: CloudFunctionTrigger) => f.name);
const httpFunctionFullNames: string[] = getReleaseNames(httpFunctionNames, [], filterGroups);
const existingFunctionFullNames: string[] = context.existingFunctions.map(
(f: { name: string }) => f.name
Expand Down
70 changes: 0 additions & 70 deletions src/deploy/functions/createOrUpdateSchedulesAndTopics.ts

This file was deleted.