carlin 0.19.14 → 0.20.0

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,34 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.20.0](https://github.com/ttoss/carlin/compare/v0.19.17...v0.20.0) (2022-02-01)
7
+
8
+ ### Bug Fixes
9
+
10
+ - update cloudfront protocol ([13678cd](https://github.com/ttoss/carlin/commit/13678cd3551924aa47d72ec322ea3d8c0e0502bc))
11
+
12
+ ### Features
13
+
14
+ - add tags to ecs report ([d0bf69d](https://github.com/ttoss/carlin/commit/d0bf69d82a737053a539356d8ba7afba966dacc3))
15
+
16
+ ## [0.19.17](https://github.com/ttoss/carlin/compare/v0.19.16...v0.19.17) (2022-01-24)
17
+
18
+ ### Bug Fixes
19
+
20
+ - pipelines commands ([1c01d40](https://github.com/ttoss/carlin/commit/1c01d4077ae6fc9fc1ab6a565c0d08b50a575664))
21
+
22
+ ## [0.19.16](https://github.com/ttoss/carlin/compare/v0.19.15...v0.19.16) (2022-01-04)
23
+
24
+ ### Bug Fixes
25
+
26
+ - add set -e to cicd pipelines ([95ba9a7](https://github.com/ttoss/carlin/commit/95ba9a7317e02a8e60b579a6f50132ef7629c1f8))
27
+
28
+ ## [0.19.15](https://github.com/ttoss/carlin/compare/v0.19.14...v0.19.15) (2021-12-23)
29
+
30
+ ### Bug Fixes
31
+
32
+ - improve cicd docs ([3265dbc](https://github.com/ttoss/carlin/commit/3265dbc9a353cdd176aa6d79b2adb638db30931a))
33
+
6
34
  ## [0.19.14](https://github.com/ttoss/carlin/compare/v0.19.9...v0.19.14) (2021-12-09)
7
35
 
8
36
  ### Bug Fixes
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ecsTaskReportHandler = exports.getEcsTaskLogsUrl = void 0;
3
+ exports.ecsTaskReportHandler = exports.getEcsTaskTags = exports.getEcsTaskLogsUrl = void 0;
4
4
  const webhook_1 = require("@slack/webhook");
5
+ const aws_sdk_1 = require("aws-sdk");
5
6
  const putApprovalResultManualTask_1 = require("./putApprovalResultManualTask");
6
- const getEcsTaskLogsUrl = ({ ecsTaskArn }) => {
7
- if (!process.env.ECS_TASK_CONTAINER_NAME ||
8
- !process.env.ECS_TASK_LOGS_LOG_GROUP) {
9
- return undefined;
10
- }
7
+ const ecs = new aws_sdk_1.ECS({ apiVersion: '2014-11-13' });
8
+ const getEcsTaskId = ({ ecsTaskArn }) => {
11
9
  /**
12
10
  * Arn has the following format:
13
11
  * arn:aws:ecs:us-east-1:483684946879:task/CarlinCicdCarlinMonorepo-RepositoryTasksECSCluster-1J6saGT91hCr/6fcc78682de442ae89a0b7339ac7d981
@@ -15,6 +13,24 @@ const getEcsTaskLogsUrl = ({ ecsTaskArn }) => {
15
13
  * We want the "6fcc78682de442ae89a0b7339ac7d981" part.
16
14
  */
17
15
  const ecsTaskId = ecsTaskArn.split('/')[2];
16
+ return ecsTaskId;
17
+ };
18
+ const getEcsTaskCluster = ({ ecsTaskArn }) => {
19
+ /**
20
+ * Arn has the following format:
21
+ * arn:aws:ecs:us-east-1:483684946879:task/CarlinCicdCarlinMonorepo-RepositoryTasksECSCluster-1J6saGT91hCr/6fcc78682de442ae89a0b7339ac7d981
22
+ *
23
+ * We want the "CarlinCicdCarlinMonorepo-RepositoryTasksECSCluster-1J6saGT91hCr" part.
24
+ */
25
+ const ecsTaskCluster = ecsTaskArn.split('/')[1];
26
+ return ecsTaskCluster;
27
+ };
28
+ const getEcsTaskLogsUrl = ({ ecsTaskArn }) => {
29
+ if (!process.env.ECS_TASK_CONTAINER_NAME ||
30
+ !process.env.ECS_TASK_LOGS_LOG_GROUP) {
31
+ return undefined;
32
+ }
33
+ const ecsTaskId = getEcsTaskId({ ecsTaskArn });
18
34
  const ecsTaskLogsUrl = new URL([
19
35
  /**
20
36
  * https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
@@ -30,6 +46,19 @@ const getEcsTaskLogsUrl = ({ ecsTaskArn }) => {
30
46
  return ecsTaskLogsUrl.href;
31
47
  };
32
48
  exports.getEcsTaskLogsUrl = getEcsTaskLogsUrl;
49
+ const getEcsTaskTags = async ({ ecsTaskArn, }) => {
50
+ const cluster = getEcsTaskCluster({ ecsTaskArn });
51
+ const taskId = getEcsTaskId({ ecsTaskArn });
52
+ const { tasks } = await ecs
53
+ .describeTasks({ cluster, include: ['TAGS'], tasks: [taskId] })
54
+ .promise();
55
+ const task = tasks === null || tasks === void 0 ? void 0 : tasks[0];
56
+ if (!task) {
57
+ return undefined;
58
+ }
59
+ return task.tags;
60
+ };
61
+ exports.getEcsTaskTags = getEcsTaskTags;
33
62
  /**
34
63
  * This method is invoked when an ECS task is executed and the success or
35
64
  * failure commands calls `carlin cicd-ecs-task-report --status=<status>`.
@@ -47,6 +76,7 @@ const ecsTaskReportHandler = async ({ ecsTaskArn, status, pipelineName, }) => {
47
76
  });
48
77
  }
49
78
  };
79
+ const ecsTaskTags = ecsTaskArn && (await exports.getEcsTaskTags({ ecsTaskArn }));
50
80
  const handleStackNotification = async () => {
51
81
  /**
52
82
  * Do not send a notification if the task was main pipeline with tag.
@@ -79,6 +109,7 @@ const ecsTaskReportHandler = async ({ ecsTaskArn, status, pipelineName, }) => {
79
109
  text: `\`\`\`${JSON.stringify({
80
110
  status,
81
111
  pipelineName,
112
+ ecsTaskTags,
82
113
  }, null, 2)}\`\`\``,
83
114
  },
84
115
  },
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTagCommands = exports.getMainCommands = exports.getClosedPrCommands = exports.getPrCommands = exports.pipelines = void 0;
3
+ exports.getTagCommands = exports.getMainCommands = exports.getClosedPrCommands = exports.getPrCommands = exports.getCommandFileDir = exports.pipelines = void 0;
4
4
  exports.pipelines = ['pr', 'main', 'tag'];
5
- const executeCommandFile = (pipeline) => `chmod +x ./cicd/commands/${pipeline} && ./cicd/commands/${pipeline}`;
5
+ const getCommandFileDir = (pipeline) => `./cicd/commands/${pipeline}`;
6
+ exports.getCommandFileDir = getCommandFileDir;
6
7
  const getPrCommands = ({ branch }) => [
8
+ 'set -e',
7
9
  'git status',
8
10
  'git fetch',
9
11
  /**
@@ -15,7 +17,7 @@ const getPrCommands = ({ branch }) => [
15
17
  'git rev-parse HEAD',
16
18
  'git status',
17
19
  'yarn',
18
- executeCommandFile('pr'),
20
+ `sh -e ${exports.getCommandFileDir('pr')}`,
19
21
  ];
20
22
  exports.getPrCommands = getPrCommands;
21
23
  const getClosedPrCommands = ({ branch }) => [
@@ -27,10 +29,11 @@ const getClosedPrCommands = ({ branch }) => [
27
29
  'git pull origin main',
28
30
  'git rev-parse HEAD',
29
31
  `export CARLIN_BRANCH=${branch}`,
30
- executeCommandFile('closed-pr'),
32
+ `sh ${exports.getCommandFileDir('closed-pr')} || true`,
31
33
  ];
32
34
  exports.getClosedPrCommands = getClosedPrCommands;
33
35
  const getMainCommands = () => [
36
+ 'set -e',
34
37
  `export CARLIN_ENVIRONMENT=Staging`,
35
38
  'git status',
36
39
  'git fetch',
@@ -41,16 +44,17 @@ const getMainCommands = () => [
41
44
  */
42
45
  'if git describe --exact-match; then echo "Tag found" && carlin cicd-ecs-task-report --status=MainTagFound && exit 0; fi',
43
46
  'yarn',
44
- executeCommandFile('main'),
47
+ `sh -e ${exports.getCommandFileDir('main')}`,
45
48
  ];
46
49
  exports.getMainCommands = getMainCommands;
47
50
  const getTagCommands = ({ tag }) => [
51
+ 'set -e',
48
52
  `export CARLIN_ENVIRONMENT=Production`,
49
53
  'git status',
50
54
  'git fetch --tags',
51
55
  `git checkout tags/${tag} -b ${tag}-branch`,
52
56
  'git rev-parse HEAD',
53
57
  'yarn',
54
- executeCommandFile('tag'),
58
+ `sh -e ${exports.getCommandFileDir('tag')}`,
55
59
  ];
56
60
  exports.getTagCommands = getTagCommands;
@@ -42,8 +42,8 @@ const checkAwsAccountId = async (awsAccountId) => {
42
42
  throw new Error(`AWS account id does not match. Current is "${currentAwsAccountId}" but the defined in configuration files is "${awsAccountId}".`);
43
43
  }
44
44
  }
45
- catch (err) {
46
- npmlog_1.default.error(logPrefix, err.message);
45
+ catch (error) {
46
+ npmlog_1.default.error(logPrefix, error.message);
47
47
  process.exit();
48
48
  }
49
49
  };
@@ -55,8 +55,8 @@ const describeDeployCommand = {
55
55
  const newStackName = stackName || (await stackName_1.getStackName());
56
56
  await cloudFormation_core_1.printStackOutputsAfterDeploy({ stackName: newStackName });
57
57
  }
58
- catch (err) {
59
- npmlog_1.default.info(logPrefix, 'Cannot describe stack. Message: %s', err.message);
58
+ catch (error) {
59
+ npmlog_1.default.info(logPrefix, 'Cannot describe stack. Message: %s', error.message);
60
60
  }
61
61
  },
62
62
  };
@@ -192,12 +192,20 @@ exports.deployCommand = {
192
192
  npmlog_1.default.warn(logPrefix, "Skip deploy flag is true, then the deploy command wasn't executed.");
193
193
  process.exit(0);
194
194
  }
195
- })
196
- .command(command_3.deployLambdaLayerCommand)
197
- .command(describeDeployCommand)
198
- .command(command_1.deployBaseStackCommand)
199
- .command(command_4.deployStaticAppCommand)
200
- .command(command_2.deployCicdCommand);
195
+ });
196
+ const commands = [
197
+ command_3.deployLambdaLayerCommand,
198
+ describeDeployCommand,
199
+ command_1.deployBaseStackCommand,
200
+ command_4.deployStaticAppCommand,
201
+ command_2.deployCicdCommand,
202
+ ];
203
+ yargsBuilder.positional('deploy', {
204
+ choices: commands.map(({ command }) => command),
205
+ describe: 'Type of deployment.',
206
+ type: 'string',
207
+ });
208
+ commands.forEach((command) => yargsBuilder.command(command));
201
209
  return yargsBuilder;
202
210
  },
203
211
  handler: ({ destroy, ...rest }) => {
@@ -205,6 +213,7 @@ exports.deployCommand = {
205
213
  cloudFormation_1.destroyCloudFormation();
206
214
  }
207
215
  else {
216
+ console.log(rest);
208
217
  cloudFormation_1.deployCloudFormation(rest);
209
218
  }
210
219
  },
@@ -10,18 +10,18 @@ const config_1 = require("../../config");
10
10
  const utils_1 = require("../../utils");
11
11
  const deployLambdaLayer_1 = require("./deployLambdaLayer");
12
12
  const logPrefix = 'deploy-lambda-layer';
13
+ /**
14
+ * https://stackoverflow.com/a/64880672/8786986
15
+ */
16
+ const packageNameRegex = /@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/;
13
17
  exports.options = {
14
18
  packages: {
15
19
  array: true,
16
- describe: "NPM packages' names to be deployed as Lambda Layers. ",
20
+ describe: `NPM packages' names to be deployed as Lambda Layers. It must follow the format: ${packageNameRegex.toString()}.`,
17
21
  required: true,
18
22
  type: 'string',
19
23
  },
20
24
  };
21
- /**
22
- * https://stackoverflow.com/a/64880672/8786986
23
- */
24
- const packageNameRegex = /@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/;
25
25
  exports.deployLambdaLayerCommand = {
26
26
  command: 'lambda-layer',
27
27
  describe: 'Deploy Lambda Layer.',
@@ -34,7 +34,7 @@ exports.deployLambdaLayerCommand = {
34
34
  })
35
35
  .filter((packageName) => !!packageName);
36
36
  if (invalidPackages.length > 0) {
37
- throw new Error(`Some package names are invalid: ${invalidPackages.join(', ')}`);
37
+ throw new Error(`Some package names are invalid: ${invalidPackages.join(', ')}. The package must follow the pattern: ${packageNameRegex.toString()}.`);
38
38
  }
39
39
  else {
40
40
  return true;
@@ -777,6 +777,12 @@ const getCloudFrontTemplate = ({ acm, aliases, cloudfront, gtmId, csp, spa, host
777
777
  },
778
778
  };
779
779
  if (acm) {
780
+ const acmRegex = /^arn:aws:acm:[-a-z0-9]+:\d{12}:certificate\/[-a-z0-9]+$/;
781
+ const acmCertificateArn = acmRegex.test(acm)
782
+ ? acm
783
+ : {
784
+ 'Fn::ImportValue': acm,
785
+ };
780
786
  /**
781
787
  * Add ACM to CloudFront template.
782
788
  */
@@ -785,11 +791,11 @@ const getCloudFrontTemplate = ({ acm, aliases, cloudfront, gtmId, csp, spa, host
785
791
  .DistributionConfig,
786
792
  Aliases: aliases || { Ref: 'AWS::NoValue' },
787
793
  ViewerCertificate: {
788
- AcmCertificateArn: /^arn:aws:acm:[-a-z0-9]+:\d{12}:certificate\/[-a-z0-9]+$/.test(acm)
789
- ? acm
790
- : {
791
- 'Fn::ImportValue': acm,
792
- },
794
+ AcmCertificateArn: acmCertificateArn,
795
+ /**
796
+ * AWS CloudFront recommendation.
797
+ */
798
+ MinimumProtocolVersion: 'TLSv1.2_2021',
793
799
  SslSupportMethod: 'sni-only',
794
800
  },
795
801
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "0.19.14",
3
+ "version": "0.20.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {