carlin 0.21.7 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/cli.js +12 -30
  2. package/dist/deploy/baseStack/deployBaseStack.js +4 -6
  3. package/dist/deploy/baseStack/getLambdaImageBuilder.template.js +2 -4
  4. package/dist/deploy/cicd/cicd.template.js +4 -6
  5. package/dist/deploy/cicd/command.js +5 -13
  6. package/dist/deploy/cicd/command.options.js +2 -5
  7. package/dist/deploy/cicd/deployCicd.js +13 -34
  8. package/dist/deploy/cicd/ecsTaskReportCommand.js +3 -5
  9. package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +1 -3
  10. package/dist/deploy/cicd/lambdas/executeTasks.js +1 -1
  11. package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +5 -15
  12. package/dist/deploy/cicd/lambdas/pipelines.handler.js +4 -25
  13. package/dist/deploy/cicd/pipelines.js +1 -1
  14. package/dist/deploy/cicd/readSSHKey.js +10 -0
  15. package/dist/deploy/cloudFormation.core.js +5 -26
  16. package/dist/deploy/cloudFormation.js +6 -8
  17. package/dist/deploy/command.js +6 -40
  18. package/dist/deploy/lambda/buildLambdaSingleFile.js +34 -0
  19. package/dist/deploy/lambda/deployLambdaCode.js +39 -0
  20. package/dist/deploy/lambda/deployLambdaLayers.js +34 -0
  21. package/dist/deploy/lambda/uploadCodeToECR.js +53 -0
  22. package/dist/deploy/lambda/uploadCodeToS3.js +31 -0
  23. package/dist/deploy/lambdaLayer/command.js +2 -4
  24. package/dist/deploy/lambdaLayer/deployLambdaLayer.js +9 -11
  25. package/dist/deploy/readDockerfile.js +18 -0
  26. package/dist/deploy/s3.js +6 -8
  27. package/dist/deploy/staticApp/command.js +6 -7
  28. package/dist/deploy/staticApp/deployStaticApp.js +64 -0
  29. package/dist/deploy/staticApp/findDefaultBuildFolder.js +27 -0
  30. package/dist/deploy/staticApp/getStaticAppBucket.js +19 -0
  31. package/dist/deploy/staticApp/invalidateCloudFront.js +42 -0
  32. package/dist/deploy/staticApp/removeOldVersions.js +43 -0
  33. package/dist/deploy/staticApp/staticApp.template.js +0 -1
  34. package/dist/deploy/staticApp/uploadBuiltAppToS3.js +33 -0
  35. package/dist/deploy/utils.js +2 -4
  36. package/dist/generateEnv/generateEnv.js +46 -0
  37. package/dist/generateEnv/generateEnvCommand.js +9 -0
  38. package/dist/index.js +2 -4
  39. package/dist/utils/cloudFormationTemplate.js +2 -4
  40. package/dist/utils/codeBuild.js +2 -4
  41. package/dist/utils/exec.js +3 -5
  42. package/dist/utils/formatCode.js +3 -21
  43. package/dist/utils/getCurrentBranch.js +2 -4
  44. package/dist/utils/getProjectName.js +1 -1
  45. package/dist/utils/index.js +15 -24
  46. package/dist/utils/packageJson.js +4 -6
  47. package/dist/utils/readCloudFormationTemplate.js +6 -8
  48. package/dist/utils/readObjectFile.js +3 -5
  49. package/package.json +22 -26
  50. package/dist/deploy/lambda.js +0 -177
  51. package/dist/deploy/staticApp/staticApp.js +0 -202
package/dist/cli.js CHANGED
@@ -1,40 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
3
  exports.options = void 0;
4
+ const tslib_1 = require("tslib");
26
5
  /* eslint-disable no-param-reassign */
27
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
28
- const change_case_1 = require("change-case");
29
- const deep_equal_1 = __importDefault(require("deep-equal"));
30
- const deepmerge_1 = __importDefault(require("deepmerge"));
31
- const find_up_1 = __importDefault(require("find-up"));
32
- const path_1 = __importDefault(require("path"));
33
- const yargs = __importStar(require("yargs"));
6
+ const yargs = tslib_1.__importStar(require("yargs"));
34
7
  const config_1 = require("./config");
8
+ const utils_1 = require("./utils");
9
+ const change_case_1 = require("change-case");
35
10
  const command_1 = require("./deploy/command");
36
11
  const ecsTaskReportCommand_1 = require("./deploy/cicd/ecsTaskReportCommand");
37
- const utils_1 = require("./utils");
12
+ const generateEnvCommand_1 = require("./generateEnv/generateEnvCommand");
13
+ const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk"));
14
+ const deep_equal_1 = tslib_1.__importDefault(require("deep-equal"));
15
+ const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
16
+ const find_up_1 = tslib_1.__importDefault(require("find-up"));
17
+ const path_1 = tslib_1.__importDefault(require("path"));
38
18
  const coerceSetEnvVar = (env) => (value) => {
39
19
  if (value) {
40
20
  (0, utils_1.setEnvVar)(env, value);
@@ -240,10 +220,12 @@ const cli = () => {
240
220
  .command({
241
221
  command: 'print-args',
242
222
  describe: false,
223
+ // eslint-disable-next-line no-console
243
224
  handler: (argv) => console.log(JSON.stringify(argv, null, 2)),
244
225
  })
245
226
  .command(command_1.deployCommand)
246
227
  .command(ecsTaskReportCommand_1.ecsTaskReportCommand)
228
+ .command(generateEnvCommand_1.generateEnvCommand)
247
229
  .epilogue('For more information, find our manual at https://carlin.ttoss.dev')
248
230
  .help());
249
231
  };
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.deployBaseStack = exports.baseStackTemplate = void 0;
7
- const deepmerge_1 = __importDefault(require("deepmerge"));
8
- const cloudFormation_core_1 = require("../cloudFormation.core");
9
- const utils_1 = require("../utils");
4
+ const tslib_1 = require("tslib");
10
5
  const config_1 = require("./config");
6
+ const cloudFormation_core_1 = require("../cloudFormation.core");
11
7
  const getBucket_template_1 = require("./getBucket.template");
12
8
  const getLambdaImageBuilder_template_1 = require("./getLambdaImageBuilder.template");
13
9
  const getLambdaLayerBuilder_template_1 = require("./getLambdaLayerBuilder.template");
14
10
  const getVpc_template_1 = require("./getVpc.template");
11
+ const utils_1 = require("../utils");
12
+ const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
15
13
  const logPrefix = 'base-stack';
16
14
  exports.baseStackTemplate = deepmerge_1.default.all([
17
15
  (0, getBucket_template_1.getBucketTemplate)(),
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getLambdaImageBuilderTemplate = void 0;
7
- const js_yaml_1 = __importDefault(require("js-yaml"));
4
+ const tslib_1 = require("tslib");
5
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
8
6
  const utils_1 = require("../../utils");
9
7
  const config_1 = require("./config");
10
8
  const getLambdaImageBuilderTemplate = () => {
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getCicdTemplate = exports.getRepositoryImageBuilder = exports.IMAGE_UPDATER_SCHEDULE_SERVERLESS_FUNCTION_LOGICAL_ID = exports.PIPELINES_HANDLER_LAMBDA_FUNCTION_LOGICAL_ID = exports.PIPELINES_TAG_LOGICAL_ID = exports.PIPELINES_MAIN_LOGICAL_ID = exports.PIPELINES_ROLE_LOGICAL_ID = exports.PIPELINES_ARTIFACT_STORE_S3_BUCKET_LOGICAL_ID = exports.REPOSITORY_TASKS_ECS_TASK_DEFINITION_TASK_ROLE_LOGICAL_ID = exports.REPOSITORY_TASKS_ECS_TASK_DEFINITION_EXECUTION_ROLE_LOGICAL_ID = exports.REPOSITORY_TASKS_ECS_CLUSTER_LOGS_LOG_GROUP_LOGICAL_ID = exports.REPOSITORY_TASKS_ECS_CLUSTER_LOGICAL_ID = exports.REPOSITORY_IMAGE_CODE_BUILD_PROJECT_LOGICAL_ID = exports.REPOSITORY_ECS_TASK_DEFINITION_LOGICAL_ID = exports.REPOSITORY_ECS_TASK_CONTAINER_NAME = exports.PROCESS_ENV_REPOSITORY_IMAGE_CODE_BUILD_PROJECT_NAME = exports.ECS_TASK_REPORT_HANDLER_LAMBDA_FUNCTION_LOGICAL_ID = exports.FUNCTION_IAM_ROLE_LOGICAL_ID = exports.ECR_REPOSITORY_LOGICAL_ID = exports.CODE_BUILD_PROJECT_SERVICE_ROLE_LOGICAL_ID = exports.CODE_BUILD_PROJECT_LOGS_LOGICAL_ID = exports.API_LOGICAL_ID = void 0;
7
- const change_case_1 = require("change-case");
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- const utils_1 = require("../../utils");
4
+ const tslib_1 = require("tslib");
10
5
  const config_1 = require("../baseStack/config");
11
6
  const command_options_1 = require("./command.options");
7
+ const utils_1 = require("../../utils");
12
8
  const config_2 = require("./config");
9
+ const change_case_1 = require("change-case");
10
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
13
11
  const getTriggerPipelineObjectKey_1 = require("./getTriggerPipelineObjectKey");
14
12
  exports.API_LOGICAL_ID = 'ApiV1ServerlessApi';
15
13
  exports.CODE_BUILD_PROJECT_LOGS_LOGICAL_ID = 'RepositoryImageCodeBuildProjectLogsLogGroup';
@@ -1,22 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deployCicdCommand = exports.readSSHKey = void 0;
7
- /* eslint-disable no-param-reassign */
8
- const fs_1 = __importDefault(require("fs"));
9
- const npmlog_1 = __importDefault(require("npmlog"));
3
+ exports.deployCicdCommand = void 0;
4
+ const tslib_1 = require("tslib");
10
5
  const config_1 = require("../../config");
11
6
  const utils_1 = require("../../utils");
12
7
  const deployCicd_1 = require("./deployCicd");
13
8
  const command_options_1 = require("./command.options");
9
+ const readSSHKey_1 = require("./readSSHKey");
10
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
14
11
  const logPrefix = 'deploy-cicd';
15
- /**
16
- * Created to allow mocking.
17
- */
18
- const readSSHKey = (dir) => fs_1.default.readFileSync(dir, 'utf-8');
19
- exports.readSSHKey = readSSHKey;
20
12
  exports.deployCicdCommand = {
21
13
  command: 'cicd',
22
14
  describe: 'Deploy CICD.',
@@ -28,7 +20,7 @@ exports.deployCicdCommand = {
28
20
  else {
29
21
  (0, deployCicd_1.deployCicd)({
30
22
  ...rest,
31
- sshKey: (0, exports.readSSHKey)(rest['ssh-key']),
23
+ sshKey: (0, readSSHKey_1.readSSHKey)(rest['ssh-key']),
32
24
  });
33
25
  }
34
26
  },
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getCicdConfig = exports.options = void 0;
7
- /* eslint-disable no-param-reassign */
4
+ const tslib_1 = require("tslib");
8
5
  const change_case_1 = require("change-case");
9
- const yargs_1 = __importDefault(require("yargs"));
10
6
  const pipelines_1 = require("./pipelines");
7
+ const yargs_1 = tslib_1.__importDefault(require("yargs"));
11
8
  exports.options = {
12
9
  cpu: {
13
10
  type: 'string',
@@ -1,37 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
3
  exports.deployCicd = exports.getLambdaInput = void 0;
26
- const fs = __importStar(require("fs"));
27
- const npmlog_1 = __importDefault(require("npmlog"));
28
- const path = __importStar(require("path"));
29
- const utils_1 = require("../../utils");
30
- const cloudFormation_core_1 = require("../cloudFormation.core");
31
- const utils_2 = require("../utils");
32
- const lambda_1 = require("../lambda");
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
33
7
  const cicd_template_1 = require("./cicd.template");
8
+ const cloudFormation_core_1 = require("../cloudFormation.core");
9
+ const deployLambdaCode_1 = require("../lambda/deployLambdaCode");
34
10
  const getCicdStackName_1 = require("./getCicdStackName");
11
+ const utils_1 = require("../utils");
12
+ const utils_2 = require("../../utils");
13
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
35
14
  const logPrefix = 'cicd';
36
15
  const getLambdaInput = (extension) => path.resolve(__dirname, `lambdas/index.${extension}`);
37
16
  exports.getLambdaInput = getLambdaInput;
@@ -52,7 +31,7 @@ const deployCicdLambdas = async ({ stackName }) => {
52
31
  }
53
32
  throw new Error('Cannot read CICD lambdas file.');
54
33
  })();
55
- const s3 = await (0, lambda_1.deployLambdaCode)({
34
+ const s3 = await (0, deployLambdaCode_1.deployLambdaCode)({
56
35
  lambdaInput,
57
36
  lambdaExternals: [],
58
37
  /**
@@ -74,14 +53,14 @@ const waitRepositoryImageUpdate = async ({ stackName, }) => {
74
53
  if (!projectName) {
75
54
  throw new Error(`Cannot retrieve repository image CodeBuild project name.`);
76
55
  }
77
- const build = await (0, utils_1.startCodeBuildBuild)({ projectName });
56
+ const build = await (0, utils_2.startCodeBuildBuild)({ projectName });
78
57
  if (build.id) {
79
- await (0, utils_1.waitCodeBuildFinish)({ buildId: build.id, name: stackName });
58
+ await (0, utils_2.waitCodeBuildFinish)({ buildId: build.id, name: stackName });
80
59
  }
81
60
  };
82
61
  const deployCicd = async ({ cpu, memory, pipelines, updateRepository, slackWebhookUrl, sshKey, sshUrl, taskEnvironment, }) => {
83
62
  try {
84
- const { stackName } = await (0, utils_2.handleDeployInitialization)({
63
+ const { stackName } = await (0, utils_1.handleDeployInitialization)({
85
64
  logPrefix,
86
65
  stackName: (0, getCicdStackName_1.getCicdStackName)(),
87
66
  });
@@ -108,7 +87,7 @@ const deployCicd = async ({ cpu, memory, pipelines, updateRepository, slackWebho
108
87
  }
109
88
  }
110
89
  catch (error) {
111
- (0, utils_2.handleDeployError)({ error, logPrefix });
90
+ (0, utils_1.handleDeployError)({ error, logPrefix });
112
91
  }
113
92
  };
114
93
  exports.deployCicd = deployCicd;
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ecsTaskReportCommand = void 0;
7
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
8
- const npmlog_1 = __importDefault(require("npmlog"));
4
+ const tslib_1 = require("tslib");
5
+ const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk"));
6
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
9
7
  const logPrefix = 'cicd-ecs-task-report';
10
8
  /**
11
9
  * This method create the payload to send to Lambda ECS task report handler.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ecsTaskReportHandler = exports.getEcsTaskTags = exports.getEcsTaskLogsUrl = void 0;
4
- const webhook_1 = require("@slack/webhook");
5
4
  const aws_sdk_1 = require("aws-sdk");
5
+ const webhook_1 = require("@slack/webhook");
6
6
  const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
7
7
  const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13' });
8
8
  const getEcsTaskId = ({ ecsTaskArn }) => {
@@ -53,14 +53,12 @@ const getEcsTaskTags = async ({ ecsTaskArn, }) => {
53
53
  .describeTasks({ cluster, include: ['TAGS'], tasks: [ecsTaskArn] })
54
54
  .promise();
55
55
  const task = tasks === null || tasks === void 0 ? void 0 : tasks[0];
56
- console.log({ tasks, cluster, ecsTaskArn });
57
56
  if (!task) {
58
57
  return undefined;
59
58
  }
60
59
  return task.tags;
61
60
  }
62
61
  catch (error) {
63
- console.error(error);
64
62
  return undefined;
65
63
  }
66
64
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeTasks = exports.shConditionalCommands = void 0;
4
4
  const aws_sdk_1 = require("aws-sdk");
5
5
  const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
6
- const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13' });
6
+ const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13', maxRetries: 3 });
7
7
  const compileCommands = (commands) => {
8
8
  return commands.map((c) => c.replace(/;$/, '')).join(' && ');
9
9
  };
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.githubWebhooksApiV1Handler = exports.webhooks = void 0;
7
- const webhooks_1 = require("@octokit/webhooks");
8
- const adm_zip_1 = __importDefault(require("adm-zip"));
9
- const aws_sdk_1 = require("aws-sdk");
10
- const getTriggerPipelineObjectKey_1 = require("../getTriggerPipelineObjectKey");
4
+ const tslib_1 = require("tslib");
11
5
  const pipelines_1 = require("../pipelines");
6
+ const aws_sdk_1 = require("aws-sdk");
7
+ const webhooks_1 = require("@octokit/webhooks");
12
8
  const executeTasks_1 = require("./executeTasks");
13
9
  const getProcessEnvVariable_1 = require("./getProcessEnvVariable");
10
+ const getTriggerPipelineObjectKey_1 = require("../getTriggerPipelineObjectKey");
11
+ const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
14
12
  const s3 = new aws_sdk_1.S3();
15
13
  /**
16
14
  * When this file is saved on S3, a CodePipeline pipeline is started.
@@ -59,13 +57,6 @@ exports.webhooks.on(['pull_request.opened', 'pull_request.reopened', 'pull_reque
59
57
  if (payload.pull_request.draft) {
60
58
  return;
61
59
  }
62
- console.log([
63
- { key: 'Pipeline', value: 'pr' },
64
- { key: 'PullRequest', value: payload.number.toString() },
65
- { key: 'PullRequestUrl', value: payload.pull_request.url },
66
- { key: 'Action', value: payload.action },
67
- { key: 'Branch', value: payload.pull_request.head.ref },
68
- ]);
69
60
  await (0, executeTasks_1.executeTasks)({
70
61
  commands: [
71
62
  (0, executeTasks_1.shConditionalCommands)({
@@ -148,7 +139,6 @@ const githubWebhooksApiV1Handler = async (event, context) => {
148
139
  return { statusCode: 200, body: JSON.stringify({ ok: true }) };
149
140
  }
150
141
  catch (error) {
151
- console.error(error);
152
142
  return { statusCode: error.status || 500, body: error.message };
153
143
  }
154
144
  };
@@ -1,31 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
3
  exports.pipelinesHandler = exports.getJobDetails = exports.getJobDetailsFilename = void 0;
26
- const adm_zip_1 = __importDefault(require("adm-zip"));
4
+ const tslib_1 = require("tslib");
5
+ const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
27
6
  const aws_sdk_1 = require("aws-sdk");
28
- const fs = __importStar(require("fs"));
7
+ const fs = tslib_1.__importStar(require("fs"));
29
8
  const pipelines_1 = require("../pipelines");
30
9
  const executeTasks_1 = require("./executeTasks");
31
10
  const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
@@ -55,7 +34,7 @@ const getJobDetails = async (event) => {
55
34
  try {
56
35
  return JSON.parse(file);
57
36
  }
58
- catch (_a) {
37
+ catch {
59
38
  throw new Error(`Job details is not a valid json. ${file}`);
60
39
  }
61
40
  };
@@ -12,7 +12,7 @@ const getPrCommands = ({ branch }) => [
12
12
  * Update to the most recent main branch to Lerna performs the diff properly.
13
13
  */
14
14
  'git pull origin main',
15
- `git checkout ${branch}`,
15
+ `git checkout ${branch} || echo 'branch not found, probably deleted'; exit 0`,
16
16
  `git pull origin ${branch}`,
17
17
  'git rev-parse HEAD',
18
18
  'git status',
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readSSHKey = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ /**
7
+ * Created to allow mocking.
8
+ */
9
+ const readSSHKey = (dir) => fs.readFileSync(dir, 'utf-8');
10
+ exports.readSSHKey = readSSHKey;
@@ -1,33 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
3
  exports.destroy = exports.canDestroyStack = exports.deploy = exports.defaultTemplatePaths = exports.enableTerminationProtection = exports.updateStack = exports.createStack = exports.deleteStack = exports.printStackOutputsAfterDeploy = exports.getStackOutput = exports.describeStack = exports.describeStackEvents = exports.doesStackExist = exports.describeStackResource = exports.describeStacks = exports.cloudFormationV2 = exports.cloudFormation = void 0;
4
+ const tslib_1 = require("tslib");
26
5
  const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
27
- const aws_sdk_1 = __importDefault(require("aws-sdk"));
28
- const fs = __importStar(require("fs"));
29
- const npmlog_1 = __importDefault(require("npmlog"));
30
- const path = __importStar(require("path"));
6
+ const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk"));
7
+ const fs = tslib_1.__importStar(require("fs"));
8
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
9
+ const path = tslib_1.__importStar(require("path"));
31
10
  const utils_1 = require("../utils");
32
11
  const addDefaults_cloudFormation_1 = require("./addDefaults.cloudFormation");
33
12
  const s3_1 = require("./s3");
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.destroyCloudFormation = exports.deployCloudFormation = exports.defaultTemplatePaths = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const npmlog_1 = __importDefault(require("npmlog"));
9
- const path_1 = __importDefault(require("path"));
4
+ const tslib_1 = require("tslib");
10
5
  const utils_1 = require("../utils");
11
6
  const cloudFormation_core_1 = require("./cloudFormation.core");
12
- const lambda_1 = require("./lambda");
7
+ const deployLambdaCode_1 = require("./lambda/deployLambdaCode");
13
8
  const s3_1 = require("./s3");
14
9
  const stackName_1 = require("./stackName");
15
10
  const utils_2 = require("./utils");
11
+ const fs_1 = tslib_1.__importDefault(require("fs"));
12
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
13
+ const path_1 = tslib_1.__importDefault(require("path"));
16
14
  const logPrefix = 'cloudformation';
17
15
  npmlog_1.default.addLevel('event', 10000, { fg: 'yellow' });
18
16
  npmlog_1.default.addLevel('output', 10000, { fg: 'blue' });
@@ -75,7 +73,7 @@ const deployCloudFormation = async ({ lambdaDockerfile, lambdaInput, lambdaImage
75
73
  * image URI will be passed to CloudFormation as parameter.
76
74
  */
77
75
  const deployCloudFormationDeployLambdaCode = async () => {
78
- const response = await (0, lambda_1.deployLambdaCode)({
76
+ const response = await (0, deployLambdaCode_1.deployLambdaCode)({
79
77
  lambdaDockerfile,
80
78
  lambdaExternals,
81
79
  lambdaInput,
@@ -1,39 +1,17 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.deployCommand = exports.examples = exports.options = exports.readDockerfile = void 0;
26
- const fs = __importStar(require("fs"));
27
- const npmlog_1 = __importDefault(require("npmlog"));
28
- const path = __importStar(require("path"));
3
+ exports.deployCommand = exports.examples = exports.options = void 0;
4
+ const tslib_1 = require("tslib");
29
5
  const utils_1 = require("../utils");
30
6
  const command_1 = require("./baseStack/command");
31
7
  const command_2 = require("./cicd/command");
32
8
  const cloudFormation_1 = require("./cloudFormation");
33
- const cloudFormation_core_1 = require("./cloudFormation.core");
34
9
  const command_3 = require("./lambdaLayer/command");
35
10
  const command_4 = require("./staticApp/command");
36
11
  const stackName_1 = require("./stackName");
12
+ const cloudFormation_core_1 = require("./cloudFormation.core");
13
+ const readDockerfile_1 = require("./readDockerfile");
14
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
37
15
  const logPrefix = 'deploy';
38
16
  const checkAwsAccountId = async (awsAccountId) => {
39
17
  try {
@@ -60,18 +38,6 @@ const describeDeployCommand = {
60
38
  }
61
39
  },
62
40
  };
63
- /**
64
- * This method was created because fs.readFileSync cannot be mocked.
65
- */
66
- const readDockerfile = (dockerfilePath) => {
67
- try {
68
- return fs.readFileSync(path.join(process.cwd(), dockerfilePath), 'utf8');
69
- }
70
- catch (_a) {
71
- return '';
72
- }
73
- };
74
- exports.readDockerfile = readDockerfile;
75
41
  exports.options = {
76
42
  'aws-account-id': {
77
43
  description: 'AWS account id associated with the deployment.',
@@ -83,7 +49,7 @@ exports.options = {
83
49
  type: 'boolean',
84
50
  },
85
51
  'lambda-dockerfile': {
86
- coerce: (arg) => (0, exports.readDockerfile)(arg),
52
+ coerce: (arg) => (0, readDockerfile_1.readDockerfile)(arg),
87
53
  default: 'Dockerfile',
88
54
  describe: 'Instructions to create the Lambda image.',
89
55
  type: 'string',
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildLambdaSingleFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const esbuild = tslib_1.__importStar(require("esbuild"));
6
+ const builtin_modules_1 = tslib_1.__importDefault(require("builtin-modules"));
7
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const logPrefix = 'lambda';
10
+ const outFolder = 'dist';
11
+ const outFile = 'index.js';
12
+ /**
13
+ * Using Webpack because of issue #8.
14
+ * {@link https://github.com/ttoss/carlin/issues/8}
15
+ */
16
+ const buildLambdaSingleFile = async ({ lambdaExternals, lambdaInput, }) => {
17
+ npmlog_1.default.info(logPrefix, 'Building Lambda single file...');
18
+ const { errors } = esbuild.buildSync({
19
+ banner: {
20
+ js: '// Powered by carlin (https://carlin.ttoss.dev)',
21
+ },
22
+ bundle: true,
23
+ entryPoints: [path_1.default.resolve(process.cwd(), lambdaInput)],
24
+ external: ['aws-sdk', ...builtin_modules_1.default, ...lambdaExternals],
25
+ platform: 'node',
26
+ outfile: path_1.default.join(process.cwd(), outFolder, outFile),
27
+ target: 'node12',
28
+ treeShaking: true,
29
+ });
30
+ if (errors.length > 0) {
31
+ throw errors;
32
+ }
33
+ };
34
+ exports.buildLambdaSingleFile = buildLambdaSingleFile;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deployLambdaCode = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const buildLambdaSingleFile_1 = require("./buildLambdaSingleFile");
6
+ const deployLambdaLayers_1 = require("./deployLambdaLayers");
7
+ const uploadCodeToECR_1 = require("./uploadCodeToECR");
8
+ const uploadCodeToS3_1 = require("./uploadCodeToS3");
9
+ const fs_1 = tslib_1.__importDefault(require("fs"));
10
+ const npmlog_1 = tslib_1.__importDefault(require("npmlog"));
11
+ const logPrefix = 'lambda';
12
+ /**
13
+ * 1. Build Lambda code using Webpack. The build process create a single file.
14
+ * 1. If packages is passed to `lambda-externals` option, Webpack will ignore
15
+ * them.
16
+ * 1. Zip the output file.
17
+ * 1. Upload the zipped code to base stack bucket.
18
+ */
19
+ const deployLambdaCode = async ({ lambdaDockerfile, lambdaExternals, lambdaImage, lambdaInput, stackName, }) => {
20
+ if (!fs_1.default.existsSync(lambdaInput)) {
21
+ return undefined;
22
+ }
23
+ npmlog_1.default.info(logPrefix, 'Deploying Lambda code...');
24
+ await (0, buildLambdaSingleFile_1.buildLambdaSingleFile)({ lambdaExternals, lambdaInput });
25
+ const { bucket, key, versionId } = await (0, uploadCodeToS3_1.uploadCodeToS3)({ stackName });
26
+ if (!lambdaImage) {
27
+ await (0, deployLambdaLayers_1.deployLambdaLayers)({ lambdaExternals });
28
+ return { bucket, key, versionId };
29
+ }
30
+ const { imageUri } = await (0, uploadCodeToECR_1.uploadCodeToECR)({
31
+ bucket,
32
+ key,
33
+ versionId,
34
+ lambdaDockerfile,
35
+ lambdaExternals,
36
+ });
37
+ return { imageUri };
38
+ };
39
+ exports.deployLambdaCode = deployLambdaCode;