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 1 commit
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
Prev Previous commit
Next Next commit
Typescriptifying prepareFunctionsUpload (#3064)
* Typescriptifying prepareFunctionsUpload, and updating filesize package to get types

* fixing merge conflict
  • Loading branch information
joehan committed Feb 1, 2021
commit 3c8d4a017d3729a07b2ddc6e8a4642f33df5006f
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
2 changes: 1 addition & 1 deletion src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as getProjectId from "../../getProjectId";
import { logBullet } from "../../utils";
import { getRuntimeChoice } from "../../parseRuntimeAndValidateSDK";
import { getFunctionsInfo, promptForFailurePolicies } from "../../functionsDeployHelper";
import * as prepareFunctionsUpload from "../../prepareFunctionsUpload";
import { prepareFunctionsUpload } from "../../prepareFunctionsUpload";
import * as validate from "./validate";
import { checkRuntimeDependencies } from "./checkRuntimeDependencies";

Expand Down
134 changes: 0 additions & 134 deletions src/prepareFunctionsUpload.js

This file was deleted.

118 changes: 118 additions & 0 deletions src/prepareFunctionsUpload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import * as _ from "lodash";
import * as archiver from "archiver";
import * as clc from "cli-color";
import * as filesize from "filesize";
import * as fs from "fs";
import * as path from "path";
import * as tmp from "tmp";

import { FirebaseError } from "./error";
import * as functionsConfig from "./functionsConfig";
import * as getProjectId from "./getProjectId";
import * as logger from "./logger";
import * as utils from "./utils";
import * as parseTriggers from "./parseTriggers";
import * as fsAsync from "./fsAsync";

const CONFIG_DEST_FILE = ".runtimeconfig.json";

async function getFunctionsConfig(context: any): Promise<{ [key: string]: any }> {
let config = {};
if (context.runtimeConfigEnabled) {
try {
config = await functionsConfig.materializeAll(context.firebaseConfig.projectId);
} catch (err) {
logger.debug(err);
const errorCode = _.get(err, "context.response.statusCode");
if (errorCode === 500 || errorCode === 503) {
throw new FirebaseError(
"Cloud Runtime Config is currently experiencing issues, " +
"which is preventing your functions from being deployed. " +
"Please wait a few minutes and then try to deploy your functions again." +
"\nRun `firebase deploy --except functions` if you want to continue deploying the rest of your project."
);
}
config = {};
}
}

const firebaseConfig = _.get(context, "firebaseConfig");
_.set(config, "firebase", firebaseConfig);
return config;
}

async function pipeAsync(from: archiver.Archiver, to: fs.WriteStream) {
return new Promise((resolve, reject) => {
to.on("finish", resolve);
to.on("error", reject);
from.pipe(to);
});
}

async function packageSource(options: any, sourceDir: string, configValues: any) {
const tmpFile = tmp.fileSync({ prefix: "firebase-functions-", postfix: ".zip" }).name;
const fileStream = fs.createWriteStream(tmpFile, {
flags: "w",
encoding: "binary",
});
const archive = archiver("zip");

// We must ignore firebase-debug.log or weird things happen if
// you're in the public dir when you deploy.
// We ignore any CONFIG_DEST_FILE that already exists, and write another one
// with current config values into the archive in the "end" handler for reader
const ignore = options.config.get("functions.ignore", ["node_modules", ".git"]);
ignore.push(
"firebase-debug.log",
"firebase-debug.*.log",
CONFIG_DEST_FILE /* .runtimeconfig.json */
);
try {
const files = await fsAsync.readdirRecursive({ path: sourceDir, ignore: ignore });
_.forEach(files, (file) => {
archive.file(file.name, {
name: path.relative(sourceDir, file.name),
mode: file.mode,
});
});
archive.append(JSON.stringify(configValues, null, 2), {
name: CONFIG_DEST_FILE,
mode: 420 /* 0o644 */,
});
archive.finalize();
await pipeAsync(archive, fileStream);
} catch (err) {
throw new FirebaseError(
"Could not read source directory. Remove links and shortcuts and try again.",
{
original: err,
exit: 1,
}
);
}
utils.logBullet(
clc.cyan.bold("functions:") +
" packaged " +
clc.bold(options.config.get("functions.source")) +
" (" +
filesize(archive.pointer()) +
") for uploading"
);
return {
file: tmpFile,
stream: fs.createReadStream(tmpFile),
size: archive.pointer(),
};
}

export async function prepareFunctionsUpload(context: any, options: any) {
const sourceDir = options.config.path(options.config.get("functions.source"));
const configValues = await getFunctionsConfig(context);
const triggers = await parseTriggers(getProjectId(options), sourceDir, configValues);
options.config.set("functions.triggers", triggers);
if (triggers.length === 0) {
// No need to package if there are 0 functions to deploy.
return;
}
return packageSource(options, sourceDir, configValues);
}