carlin 0.20.5 → 0.21.2

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,22 @@
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.21.2](https://github.com/ttoss/carlin/compare/v0.21.1...v0.21.2) (2022-03-10)
7
+
8
+ **Note:** Version bump only for package carlin
9
+
10
+ ## [0.21.1](https://github.com/ttoss/carlin/compare/v0.21.0...v0.21.1) (2022-03-10)
11
+
12
+ ### Bug Fixes
13
+
14
+ - closed-pr pipeline commands ([#47](https://github.com/ttoss/carlin/issues/47)) ([3eec7f1](https://github.com/ttoss/carlin/commit/3eec7f1ef81e5972c551f793cc4d5ab0b399b200))
15
+
16
+ # [0.21.0](https://github.com/ttoss/carlin/compare/v0.20.5...v0.21.0) (2022-03-09)
17
+
18
+ ### Features
19
+
20
+ - add repository image updater ([#45](https://github.com/ttoss/carlin/issues/45)) ([cbcbdea](https://github.com/ttoss/carlin/commit/cbcbdea7f08885dcfe833c637612472236d93b38))
21
+
6
22
  ## [0.20.5](https://github.com/ttoss/carlin/compare/v0.20.4...v0.20.5) (2022-02-24)
7
23
 
8
24
  ### Bug Fixes
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getCicdTemplate = exports.getRepositoryImageBuilder = 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;
6
+ 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
7
  const change_case_1 = require("change-case");
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
9
  const utils_1 = require("../../utils");
10
10
  const config_1 = require("../baseStack/config");
11
+ const command_options_1 = require("./command.options");
11
12
  const config_2 = require("./config");
12
13
  const getTriggerPipelineObjectKey_1 = require("./getTriggerPipelineObjectKey");
13
14
  exports.API_LOGICAL_ID = 'ApiV1ServerlessApi';
@@ -29,6 +30,7 @@ exports.PIPELINES_ROLE_LOGICAL_ID = 'PipelinesMainIAMRole';
29
30
  exports.PIPELINES_MAIN_LOGICAL_ID = 'PipelinesMainCodePipeline';
30
31
  exports.PIPELINES_TAG_LOGICAL_ID = 'PipelinesTagCodePipeline';
31
32
  exports.PIPELINES_HANDLER_LAMBDA_FUNCTION_LOGICAL_ID = 'PipelinesHandlerLambdaFunction';
33
+ exports.IMAGE_UPDATER_SCHEDULE_SERVERLESS_FUNCTION_LOGICAL_ID = 'ImageUpdaterScheduleServerlessFunction';
32
34
  /**
33
35
  * An [AWS CodeBuild](https://aws.amazon.com/codebuild/) project is created
34
36
  * to build (create and update) repository images. It uses a
@@ -251,6 +253,18 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
251
253
  },
252
254
  });
253
255
  resources[exports.ECR_REPOSITORY_LOGICAL_ID] = getEcrRepositoryResource();
256
+ const commonFunctionProperties = {
257
+ CodeUri: {
258
+ Bucket: s3.bucket,
259
+ Key: s3.key,
260
+ Version: s3.versionId,
261
+ },
262
+ Role: {
263
+ 'Fn::GetAtt': [exports.FUNCTION_IAM_ROLE_LOGICAL_ID, 'Arn'],
264
+ },
265
+ Runtime: 'nodejs14.x',
266
+ Timeout: 60,
267
+ };
254
268
  /**
255
269
  * CodeBuild
256
270
  */
@@ -313,6 +327,35 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
313
327
  };
314
328
  resources[exports.REPOSITORY_IMAGE_CODE_BUILD_PROJECT_LOGICAL_ID] =
315
329
  (0, exports.getRepositoryImageBuilder)();
330
+ const cicdConfig = {
331
+ ...(0, command_options_1.getCicdConfig)(),
332
+ 'ssh-key': '/root/.ssh/id_rsa',
333
+ environment: (0, utils_1.getEnvironment)(),
334
+ };
335
+ resources[exports.IMAGE_UPDATER_SCHEDULE_SERVERLESS_FUNCTION_LOGICAL_ID] = {
336
+ Type: 'AWS::Serverless::Function',
337
+ Properties: {
338
+ ...commonFunctionProperties,
339
+ Events: {
340
+ Schedule: {
341
+ Type: 'Schedule',
342
+ Properties: {
343
+ Schedule: 'rate(7 days)',
344
+ },
345
+ },
346
+ },
347
+ Environment: {
348
+ Variables: {
349
+ [exports.PROCESS_ENV_REPOSITORY_IMAGE_CODE_BUILD_PROJECT_NAME]: {
350
+ Ref: exports.REPOSITORY_IMAGE_CODE_BUILD_PROJECT_LOGICAL_ID,
351
+ },
352
+ CICD_CONFIG: JSON.stringify(cicdConfig),
353
+ ...executeEcsTaskVariables,
354
+ },
355
+ },
356
+ Handler: 'index.imageUpdaterScheduleHandler',
357
+ },
358
+ };
316
359
  })();
317
360
  const createApiResources = () => {
318
361
  resources[exports.API_LOGICAL_ID] = {
@@ -422,18 +465,6 @@ const getCicdTemplate = ({ pipelines = [], cpu = config_2.ECS_TASK_DEFAULT_CPU,
422
465
  ],
423
466
  },
424
467
  };
425
- const commonFunctionProperties = {
426
- CodeUri: {
427
- Bucket: s3.bucket,
428
- Key: s3.key,
429
- Version: s3.versionId,
430
- },
431
- Role: {
432
- 'Fn::GetAtt': [exports.FUNCTION_IAM_ROLE_LOGICAL_ID, 'Arn'],
433
- },
434
- Runtime: 'nodejs14.x',
435
- Timeout: 60,
436
- };
437
468
  /**
438
469
  * Called after ECS task execution success or failure.
439
470
  */
@@ -3,73 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.deployCicdCommand = exports.options = exports.readSSHKey = void 0;
6
+ exports.deployCicdCommand = exports.readSSHKey = void 0;
7
7
  /* eslint-disable no-param-reassign */
8
- const change_case_1 = require("change-case");
9
8
  const fs_1 = __importDefault(require("fs"));
10
9
  const npmlog_1 = __importDefault(require("npmlog"));
11
10
  const config_1 = require("../../config");
12
11
  const utils_1 = require("../../utils");
13
- const pipelines_1 = require("./pipelines");
14
12
  const deployCicd_1 = require("./deployCicd");
13
+ const command_options_1 = require("./command.options");
15
14
  const logPrefix = 'deploy-cicd';
16
15
  /**
17
16
  * Created to allow mocking.
18
17
  */
19
18
  const readSSHKey = (dir) => fs_1.default.readFileSync(dir, 'utf-8');
20
19
  exports.readSSHKey = readSSHKey;
21
- exports.options = {
22
- cpu: {
23
- type: 'string',
24
- },
25
- memory: {
26
- type: 'string',
27
- },
28
- pipelines: {
29
- choices: pipelines_1.pipelines,
30
- coerce: (values) => values.map((value) => (0, change_case_1.camelCase)(value)),
31
- default: [],
32
- description: 'Pipelines that will be implemented with the CICD stack.',
33
- type: 'array',
34
- },
35
- 'update-repository': {
36
- alias: ['ur'],
37
- description: 'Determine if the repository image will be updated.',
38
- default: true,
39
- type: 'boolean',
40
- },
41
- 'ssh-key': {
42
- demandOption: true,
43
- type: 'string',
44
- },
45
- 'ssh-url': {
46
- demandOption: true,
47
- type: 'string',
48
- },
49
- 'slack-webhook-url': {
50
- type: 'string',
51
- },
52
- /**
53
- * This option has the format:
54
- *
55
- * ```ts
56
- * Array<{
57
- * name: string,
58
- * value: string,
59
- * }>
60
- * ```
61
- */
62
- 'task-environment': {
63
- alias: ['te'],
64
- default: [],
65
- describe: 'A list of environment variables that will be passed to the ECS container task.',
66
- type: 'array',
67
- },
68
- };
69
20
  exports.deployCicdCommand = {
70
21
  command: 'cicd',
71
22
  describe: 'Deploy CICD.',
72
- builder: (yargs) => yargs.options((0, utils_1.addGroupToOptions)(exports.options, 'Deploy CICD Options')),
23
+ builder: (yargs) => yargs.options((0, utils_1.addGroupToOptions)(command_options_1.options, 'Deploy CICD Options')),
73
24
  handler: ({ destroy, ...rest }) => {
74
25
  if (destroy) {
75
26
  npmlog_1.default.info(logPrefix, `${config_1.NAME} doesn't destroy CICD stack.`);
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCicdConfig = exports.options = void 0;
7
+ /* eslint-disable no-param-reassign */
8
+ const change_case_1 = require("change-case");
9
+ const yargs_1 = __importDefault(require("yargs"));
10
+ const pipelines_1 = require("./pipelines");
11
+ exports.options = {
12
+ cpu: {
13
+ type: 'string',
14
+ },
15
+ memory: {
16
+ type: 'string',
17
+ },
18
+ pipelines: {
19
+ choices: pipelines_1.pipelines,
20
+ coerce: (values) => values.map((value) => (0, change_case_1.camelCase)(value)),
21
+ default: [],
22
+ description: 'Pipelines that will be implemented with the CICD stack.',
23
+ type: 'array',
24
+ },
25
+ 'update-repository': {
26
+ alias: ['ur'],
27
+ description: 'Determine if the repository image will be updated.',
28
+ default: true,
29
+ type: 'boolean',
30
+ },
31
+ 'ssh-key': {
32
+ demandOption: true,
33
+ type: 'string',
34
+ },
35
+ 'ssh-url': {
36
+ demandOption: true,
37
+ type: 'string',
38
+ },
39
+ 'slack-webhook-url': {
40
+ type: 'string',
41
+ },
42
+ /**
43
+ * This option has the format:
44
+ *
45
+ * ```ts
46
+ * Array<{
47
+ * name: string,
48
+ * value: string,
49
+ * }>
50
+ * ```
51
+ */
52
+ 'task-environment': {
53
+ alias: ['te'],
54
+ default: [],
55
+ describe: 'A list of environment variables that will be passed to the ECS container task.',
56
+ type: 'array',
57
+ },
58
+ };
59
+ const getCicdConfig = () => {
60
+ const { parsed } = yargs_1.default.config();
61
+ if (!parsed) {
62
+ return false;
63
+ }
64
+ const { argv } = parsed;
65
+ const config = Object.keys(exports.options).reduce((acc, key) => {
66
+ const value = argv[key];
67
+ if (value) {
68
+ acc[key] = value;
69
+ }
70
+ return acc;
71
+ }, {});
72
+ return config;
73
+ };
74
+ exports.getCicdConfig = getCicdConfig;
@@ -91,8 +91,8 @@ exports.webhooks.on(['pull_request.closed'], async ({ payload }) => {
91
91
  * https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
92
92
  */
93
93
  await (0, executeTasks_1.executeTasks)({
94
- cpu: '256',
95
- memory: '512',
94
+ cpu: '512',
95
+ memory: '2048',
96
96
  commands: [
97
97
  (0, executeTasks_1.shConditionalCommands)({
98
98
  conditionalCommands: (0, pipelines_1.getClosedPrCommands)({
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageUpdaterScheduleHandler = void 0;
4
+ const executeTasks_1 = require("./executeTasks");
5
+ const imageUpdaterScheduleHandler = async () => {
6
+ const cicdConfig = process.env.CICD_CONFIG;
7
+ if (!cicdConfig) {
8
+ console.log('No CICD config found.');
9
+ return;
10
+ }
11
+ const commands = [
12
+ 'set -e',
13
+ 'git status',
14
+ 'git fetch',
15
+ 'git pull origin main',
16
+ 'git rev-parse HEAD',
17
+ 'yarn global add carlin',
18
+ 'cd cicd',
19
+ 'echo $CICD_CONFIG > carlin.json',
20
+ 'cat carlin.json',
21
+ `carlin deploy cicd -c carlin.json`,
22
+ ];
23
+ const response = await (0, executeTasks_1.executeTasks)({
24
+ commands,
25
+ cpu: '512',
26
+ memory: '2048',
27
+ taskEnvironment: [
28
+ {
29
+ name: 'CICD_CONFIG',
30
+ value: cicdConfig,
31
+ },
32
+ ],
33
+ });
34
+ console.log(JSON.stringify(response, null, 2));
35
+ };
36
+ exports.imageUpdaterScheduleHandler = imageUpdaterScheduleHandler;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipelinesHandler = exports.githubWebhooksApiV1Handler = exports.ecsTaskReportHandler = exports.cicdApiV1Handler = void 0;
3
+ exports.pipelinesHandler = exports.imageUpdaterScheduleHandler = exports.githubWebhooksApiV1Handler = exports.ecsTaskReportHandler = exports.cicdApiV1Handler = void 0;
4
4
  var cicdApiV1_handler_1 = require("./cicdApiV1.handler");
5
5
  Object.defineProperty(exports, "cicdApiV1Handler", { enumerable: true, get: function () { return cicdApiV1_handler_1.cicdApiV1Handler; } });
6
6
  var ecsTaskReport_handler_1 = require("./ecsTaskReport.handler");
7
7
  Object.defineProperty(exports, "ecsTaskReportHandler", { enumerable: true, get: function () { return ecsTaskReport_handler_1.ecsTaskReportHandler; } });
8
8
  var githubWebhooksApiV1_handler_1 = require("./githubWebhooksApiV1.handler");
9
9
  Object.defineProperty(exports, "githubWebhooksApiV1Handler", { enumerable: true, get: function () { return githubWebhooksApiV1_handler_1.githubWebhooksApiV1Handler; } });
10
+ var imageUpdaterSchedule_handler_1 = require("./imageUpdaterSchedule.handler");
11
+ Object.defineProperty(exports, "imageUpdaterScheduleHandler", { enumerable: true, get: function () { return imageUpdaterSchedule_handler_1.imageUpdaterScheduleHandler; } });
10
12
  var pipelines_handler_1 = require("./pipelines.handler");
11
13
  Object.defineProperty(exports, "pipelinesHandler", { enumerable: true, get: function () { return pipelines_handler_1.pipelinesHandler; } });
@@ -29,7 +29,7 @@ const getClosedPrCommands = ({ branch }) => [
29
29
  'git pull origin main',
30
30
  'git rev-parse HEAD',
31
31
  `export CARLIN_BRANCH=${branch}`,
32
- `sh ${(0, exports.getCommandFileDir)('closed-pr')} || true`,
32
+ `[ -f "${(0, exports.getCommandFileDir)('closed-pr')}" ] && sh ${(0, exports.getCommandFileDir)('closed-pr')}`,
33
33
  ];
34
34
  exports.getClosedPrCommands = getClosedPrCommands;
35
35
  const getMainCommands = () => [
@@ -104,7 +104,7 @@ const getBaseTemplate = ({ cloudfront, spa, }) => {
104
104
  },
105
105
  };
106
106
  };
107
- const getCloudFrontTemplate = ({ acm, aliases, cloudfront, spa, hostedZoneName, region, }) => {
107
+ const getCloudFrontTemplate = ({ acm, aliases = [], cloudfront, spa, hostedZoneName, region, }) => {
108
108
  const template = { ...getBaseTemplate({ cloudfront, spa }) };
109
109
  const cloudFrontResources = {
110
110
  [CLOUDFRONT_DISTRIBUTION_ORIGIN_ACCESS_IDENTITY_LOGICAL_ID]: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlin",
3
- "version": "0.20.5",
3
+ "version": "0.21.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {