No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.printTriggerUrls = exports.release = void 0;
  4. const clc = require("colorette");
  5. const logger_1 = require("../../../logger");
  6. const functional_1 = require("../../../functional");
  7. const backend = require("../backend");
  8. const containerCleaner = require("../containerCleaner");
  9. const planner = require("./planner");
  10. const fabricator = require("./fabricator");
  11. const reporter = require("./reporter");
  12. const executor = require("./executor");
  13. const prompts = require("../prompts");
  14. const functionsConfig_1 = require("../../../functionsConfig");
  15. const functionsDeployHelper_1 = require("../functionsDeployHelper");
  16. const error_1 = require("../../../error");
  17. const getProjectNumber_1 = require("../../../getProjectNumber");
  18. async function release(context, options, payload) {
  19. if (!context.config) {
  20. return;
  21. }
  22. if (!payload.functions) {
  23. return;
  24. }
  25. if (!context.sources) {
  26. return;
  27. }
  28. let plan = {};
  29. for (const [codebase, { wantBackend, haveBackend }] of Object.entries(payload.functions)) {
  30. plan = Object.assign(Object.assign({}, plan), planner.createDeploymentPlan({
  31. codebase,
  32. wantBackend,
  33. haveBackend,
  34. filters: context.filters,
  35. }));
  36. }
  37. const fnsToDelete = Object.values(plan)
  38. .map((regionalChanges) => regionalChanges.endpointsToDelete)
  39. .reduce(functional_1.reduceFlat, []);
  40. const shouldDelete = await prompts.promptForFunctionDeletion(fnsToDelete, options.force, options.nonInteractive);
  41. if (!shouldDelete) {
  42. for (const change of Object.values(plan)) {
  43. change.endpointsToDelete = [];
  44. }
  45. }
  46. const functionExecutor = new executor.QueueExecutor({
  47. retries: 30,
  48. backoff: 20000,
  49. concurrency: 40,
  50. maxBackoff: 40000,
  51. });
  52. const fab = new fabricator.Fabricator({
  53. functionExecutor,
  54. executor: new executor.QueueExecutor({}),
  55. sources: context.sources,
  56. appEngineLocation: (0, functionsConfig_1.getAppEngineLocation)(context.firebaseConfig),
  57. projectNumber: options.projectNumber || (await (0, getProjectNumber_1.getProjectNumber)(context.projectId)),
  58. });
  59. const summary = await fab.applyPlan(plan);
  60. await reporter.logAndTrackDeployStats(summary);
  61. reporter.printErrors(summary);
  62. const wantBackend = backend.merge(...Object.values(payload.functions).map((p) => p.wantBackend));
  63. printTriggerUrls(wantBackend);
  64. const haveEndpoints = backend.allEndpoints(wantBackend);
  65. const deletedEndpoints = Object.values(plan)
  66. .map((r) => r.endpointsToDelete)
  67. .reduce(functional_1.reduceFlat, []);
  68. await containerCleaner.cleanupBuildImages(haveEndpoints, deletedEndpoints);
  69. const allErrors = summary.results.filter((r) => r.error).map((r) => r.error);
  70. if (allErrors.length) {
  71. const opts = allErrors.length === 1 ? { original: allErrors[0] } : { children: allErrors };
  72. logger_1.logger.debug("Functions deploy failed.");
  73. for (const error of allErrors) {
  74. logger_1.logger.debug(JSON.stringify(error, null, 2));
  75. }
  76. throw new error_1.FirebaseError("There was an error deploying functions", Object.assign(Object.assign({}, opts), { exit: 2 }));
  77. }
  78. }
  79. exports.release = release;
  80. function printTriggerUrls(results) {
  81. const httpsFunctions = backend.allEndpoints(results).filter(backend.isHttpsTriggered);
  82. if (httpsFunctions.length === 0) {
  83. return;
  84. }
  85. for (const httpsFunc of httpsFunctions) {
  86. if (!httpsFunc.uri) {
  87. logger_1.logger.debug("Not printing URL for HTTPS function. Typically this means it didn't match a filter or we failed deployment");
  88. continue;
  89. }
  90. logger_1.logger.info(clc.bold("Function URL"), `(${(0, functionsDeployHelper_1.getFunctionLabel)(httpsFunc)}):`, httpsFunc.uri);
  91. }
  92. }
  93. exports.printTriggerUrls = printTriggerUrls;