carlin 1.31.11 → 1.31.13
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/dist/index.js +4477 -4
- package/package.json +10 -10
- package/dist/cli.js +0 -246
- package/dist/config.js +0 -11
- package/dist/deploy/addDefaults.cloudformation.js +0 -151
- package/dist/deploy/baseStack/command.js +0 -9
- package/dist/deploy/baseStack/config.js +0 -30
- package/dist/deploy/baseStack/deployBaseStack.js +0 -62
- package/dist/deploy/baseStack/getBaseStackResource.js +0 -27
- package/dist/deploy/baseStack/getBucketTemplate.js +0 -46
- package/dist/deploy/baseStack/getLambdaImageBuilderTemplate.js +0 -188
- package/dist/deploy/baseStack/getLambdaLayerBuilderTemplate.js +0 -142
- package/dist/deploy/baseStack/getVpcTemplate.js +0 -169
- package/dist/deploy/cicd/cicd.template.js +0 -938
- package/dist/deploy/cicd/command.js +0 -31
- package/dist/deploy/cicd/command.options.js +0 -79
- package/dist/deploy/cicd/config.js +0 -8
- package/dist/deploy/cicd/deployCicd.js +0 -121
- package/dist/deploy/cicd/ecsTaskReportCommand.js +0 -55
- package/dist/deploy/cicd/getCicdStackName.js +0 -11
- package/dist/deploy/cicd/getTriggerPipelineObjectKey.js +0 -11
- package/dist/deploy/cicd/lambdas/cicdApiV1.handler.js +0 -124
- package/dist/deploy/cicd/lambdas/ecsTaskReport.handler.js +0 -126
- package/dist/deploy/cicd/lambdas/executeTasks.js +0 -67
- package/dist/deploy/cicd/lambdas/getProcessEnvVariable.js +0 -10
- package/dist/deploy/cicd/lambdas/githubWebhooksApiV1.handler.js +0 -148
- package/dist/deploy/cicd/lambdas/imageUpdaterSchedule.handler.js +0 -44
- package/dist/deploy/cicd/lambdas/index.js +0 -13
- package/dist/deploy/cicd/lambdas/pipelines.handler.js +0 -160
- package/dist/deploy/cicd/lambdas/putApprovalResultManualTask.js +0 -51
- package/dist/deploy/cicd/lambdas/shConditionalCommands.js +0 -30
- package/dist/deploy/cicd/pipelines.js +0 -86
- package/dist/deploy/cicd/readSSHKey.js +0 -34
- package/dist/deploy/cloudformation.core.js +0 -379
- package/dist/deploy/cloudformation.js +0 -189
- package/dist/deploy/command.js +0 -205
- package/dist/deploy/lambda/buildLambdaSingleFile.js +0 -67
- package/dist/deploy/lambda/deployLambdaCode.js +0 -43
- package/dist/deploy/lambda/deployLambdaLayers.js +0 -36
- package/dist/deploy/lambda/uploadCodeToECR.js +0 -53
- package/dist/deploy/lambda/uploadCodeToS3.js +0 -33
- package/dist/deploy/lambdaLayer/command.js +0 -50
- package/dist/deploy/lambdaLayer/deployLambdaLayer.js +0 -139
- package/dist/deploy/lambdaLayer/getPackageLambdaLayerStackName.js +0 -21
- package/dist/deploy/readDockerfile.js +0 -40
- package/dist/deploy/s3.js +0 -210
- package/dist/deploy/stackName.js +0 -85
- package/dist/deploy/staticApp/command.js +0 -86
- package/dist/deploy/staticApp/deployStaticApp.js +0 -65
- package/dist/deploy/staticApp/findDefaultBuildFolder.js +0 -44
- package/dist/deploy/staticApp/getStaticAppBucket.js +0 -19
- package/dist/deploy/staticApp/invalidateCloudFront.js +0 -44
- package/dist/deploy/staticApp/removeOldVersions.js +0 -56
- package/dist/deploy/staticApp/staticApp.template.js +0 -371
- package/dist/deploy/staticApp/uploadBuiltAppToS3.js +0 -28
- package/dist/deploy/utils.js +0 -31
- package/dist/deploy/vercel/command.js +0 -31
- package/dist/deploy/vercel/deployVercel.js +0 -59
- package/dist/generateEnv/generateEnv.js +0 -64
- package/dist/generateEnv/generateEnvCommand.js +0 -29
- package/dist/utils/addGroupToOptions.js +0 -11
- package/dist/utils/cloudFormationTemplate.js +0 -142
- package/dist/utils/codeBuild.js +0 -52
- package/dist/utils/environmentVariables.js +0 -16
- package/dist/utils/exec.js +0 -26
- package/dist/utils/formatCode.js +0 -34
- package/dist/utils/getAwsAccountId.js +0 -10
- package/dist/utils/getCurrentBranch.js +0 -35
- package/dist/utils/getEnvironment.js +0 -8
- package/dist/utils/getIamPath.js +0 -6
- package/dist/utils/getProjectName.js +0 -35
- package/dist/utils/index.js +0 -31
- package/dist/utils/packageJson.js +0 -32
- package/dist/utils/spawn.js +0 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carlin",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"author": "Pedro Arantes <arantespp@gmail.com> (https://twitter.com/arantespp)",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/ttoss/ttoss/issues"
|
|
15
15
|
},
|
|
16
|
-
"main": "dist/index.js",
|
|
17
16
|
"bin": {
|
|
18
17
|
"carlin": "./bin/carlin"
|
|
19
18
|
},
|
|
@@ -32,20 +31,19 @@
|
|
|
32
31
|
"deep-equal": "^2.2.3",
|
|
33
32
|
"deepmerge": "^4.3.1",
|
|
34
33
|
"dotenv": "^16.3.1",
|
|
35
|
-
"esbuild": "^0.
|
|
34
|
+
"esbuild": "^0.20.1",
|
|
36
35
|
"findup-sync": "^5.0.0",
|
|
37
36
|
"glob": "^10.3.10",
|
|
38
37
|
"js-yaml": "^4.1.0",
|
|
39
38
|
"mime-types": "^2.1.35",
|
|
40
39
|
"npmlog": "^7.0.1",
|
|
41
|
-
"prettier": "^3.2.
|
|
40
|
+
"prettier": "^3.2.5",
|
|
42
41
|
"semver": "^7.5.4",
|
|
43
42
|
"simple-git": "^3.21.0",
|
|
44
43
|
"ts-node": "^10.9.2",
|
|
45
44
|
"uglify-js": "^3.17.4",
|
|
46
45
|
"vercel": "^32.7.0",
|
|
47
|
-
"yargs": "^17.7.2"
|
|
48
|
-
"@ttoss/cloudformation": "^0.9.0"
|
|
46
|
+
"yargs": "^17.7.2"
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
49
|
"@types/adm-zip": "^0.5.5",
|
|
@@ -53,17 +51,19 @@
|
|
|
53
51
|
"@types/deep-equal": "^1.0.4",
|
|
54
52
|
"@types/findup-sync": "^4.0.4",
|
|
55
53
|
"@types/glob": "^8.1.0",
|
|
56
|
-
"@types/jest": "^29.5.
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
57
55
|
"@types/js-yaml": "^4.0.9",
|
|
58
56
|
"@types/mime-types": "^2.1.4",
|
|
59
|
-
"@types/node": "^20.
|
|
57
|
+
"@types/node": "^20.11.20",
|
|
60
58
|
"@types/npmlog": "^7.0.0",
|
|
61
59
|
"@types/semver": "^7.5.6",
|
|
62
60
|
"@types/uglify-js": "^3.17.4",
|
|
63
61
|
"@types/yargs": "^17.0.32",
|
|
64
62
|
"jest": "^29.7.0",
|
|
63
|
+
"tsup": "^8.0.2",
|
|
65
64
|
"typescript": "~5.2.2",
|
|
66
|
-
"@ttoss/
|
|
65
|
+
"@ttoss/cloudformation": "^0.9.1",
|
|
66
|
+
"@ttoss/test-utils": "^2.1.1"
|
|
67
67
|
},
|
|
68
68
|
"keywords": [],
|
|
69
69
|
"publishConfig": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"provenance": true
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
|
-
"build": "
|
|
74
|
+
"build": "tsup --splitting",
|
|
75
75
|
"test": "jest"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/dist/cli.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
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.cli = exports.options = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
/* eslint-disable no-param-reassign */
|
|
9
|
-
const config_1 = require("./config");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const change_case_1 = require("change-case");
|
|
12
|
-
const command_1 = require("./deploy/command");
|
|
13
|
-
const ecsTaskReportCommand_1 = require("./deploy/cicd/ecsTaskReportCommand");
|
|
14
|
-
const generateEnvCommand_1 = require("./generateEnv/generateEnvCommand");
|
|
15
|
-
const helpers_1 = require("yargs/helpers");
|
|
16
|
-
const cloudformation_1 = require("@ttoss/cloudformation");
|
|
17
|
-
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
18
|
-
const deep_equal_1 = __importDefault(require("deep-equal"));
|
|
19
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
20
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
22
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
23
|
-
const coerceSetEnvVar = (env) => {
|
|
24
|
-
return (value) => {
|
|
25
|
-
(0, utils_1.setEnvVar)(env, value);
|
|
26
|
-
return value;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
exports.options = {
|
|
30
|
-
branch: {
|
|
31
|
-
coerce: coerceSetEnvVar('BRANCH'),
|
|
32
|
-
require: false,
|
|
33
|
-
type: 'string',
|
|
34
|
-
},
|
|
35
|
-
config: {
|
|
36
|
-
alias: 'c',
|
|
37
|
-
describe: 'Path to config file. You can create a config file and set all options there. Valid extensions: .js, .json, .ts, .yml, or .yaml.',
|
|
38
|
-
require: false,
|
|
39
|
-
type: 'string',
|
|
40
|
-
},
|
|
41
|
-
environment: {
|
|
42
|
-
alias: ['e', 'env'],
|
|
43
|
-
coerce: coerceSetEnvVar('ENVIRONMENT'),
|
|
44
|
-
type: 'string',
|
|
45
|
-
},
|
|
46
|
-
environments: {},
|
|
47
|
-
project: {
|
|
48
|
-
coerce: coerceSetEnvVar('PROJECT'),
|
|
49
|
-
require: false,
|
|
50
|
-
type: 'string',
|
|
51
|
-
},
|
|
52
|
-
region: {
|
|
53
|
-
alias: 'r',
|
|
54
|
-
// coerce: coerceSetEnvVar('REGION'),
|
|
55
|
-
default: config_1.AWS_DEFAULT_REGION,
|
|
56
|
-
describe: 'AWS region.',
|
|
57
|
-
type: 'string',
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* You can also provide the options creating a property name `carlin`
|
|
62
|
-
* inside your `package.json`. [See Yargs reference](https://yargs.js.org/docs/#api-reference-pkgconfkey-cwd).
|
|
63
|
-
*/
|
|
64
|
-
const getPkgConfig = () => {
|
|
65
|
-
return config_1.NAME;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* All options can be passed as environment variables matching the prefix
|
|
69
|
-
* `CARLIN`. See [Yargs reference](https://yargs.js.org/docs/#api-reference-envprefix).
|
|
70
|
-
* Example, we may use `carlin deploy --stack-name StackName` or
|
|
71
|
-
* `CARLIN_STACK_NAME=StackName carlin deploy`.
|
|
72
|
-
*/
|
|
73
|
-
const getEnv = () => {
|
|
74
|
-
return (0, change_case_1.constantCase)(config_1.NAME);
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Transformed to method because finalConfig was failing the tests.
|
|
78
|
-
*/
|
|
79
|
-
const cli = () => {
|
|
80
|
-
/**
|
|
81
|
-
* All config files merged.
|
|
82
|
-
*/
|
|
83
|
-
let finalConfig;
|
|
84
|
-
/**
|
|
85
|
-
* If `--config` isn't provided, the algorithm will search for any of these
|
|
86
|
-
* files and use it to retrieve the options:
|
|
87
|
-
*
|
|
88
|
-
* - `carlin.js`
|
|
89
|
-
* - `carlin.ts`
|
|
90
|
-
* - `carlin.yaml`
|
|
91
|
-
* - `carlin.yml`
|
|
92
|
-
* - `carlin.json`
|
|
93
|
-
*
|
|
94
|
-
* The algorithm also make a find up path to search for other config files
|
|
95
|
-
* that may exist in parent directories. If find more than one file, they'll
|
|
96
|
-
* be merged, in such a way that the files nearest from `process.cwd()` will
|
|
97
|
-
* take the precedence at the merging.
|
|
98
|
-
*
|
|
99
|
-
* This is useful if you have a monorepo and have shared and specific
|
|
100
|
-
* configuration. For instance, you may have a config inside `packages/app/`
|
|
101
|
-
* folder with the config below:
|
|
102
|
-
*
|
|
103
|
-
* ```yaml
|
|
104
|
-
* stackName: MyMonorepoApp
|
|
105
|
-
* region: us-east-2
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* And on the root of your monorepo:
|
|
109
|
-
*
|
|
110
|
-
* ```yaml
|
|
111
|
-
* awsAccountId: 123456789012
|
|
112
|
-
* region: us-east-1
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* The result options that will be passed to the commands executed on
|
|
116
|
-
* `packages/app/` will be:
|
|
117
|
-
*
|
|
118
|
-
* ```yaml
|
|
119
|
-
* awsAccountId: 123456789012
|
|
120
|
-
* stackName: MyMonorepoApp
|
|
121
|
-
* region: us-east-2
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
const getConfig = () => {
|
|
125
|
-
const names = ['js', 'yml', 'yaml', 'json', 'ts'].map((ext) => {
|
|
126
|
-
return `${config_1.NAME}.${ext}`;
|
|
127
|
-
});
|
|
128
|
-
const paths = [];
|
|
129
|
-
let currentPath = process.cwd();
|
|
130
|
-
let findUpPath;
|
|
131
|
-
do {
|
|
132
|
-
findUpPath = (0, findup_sync_1.default)(names, { cwd: currentPath });
|
|
133
|
-
if (findUpPath) {
|
|
134
|
-
currentPath = path_1.default.resolve(findUpPath, '../..');
|
|
135
|
-
paths.push(findUpPath);
|
|
136
|
-
}
|
|
137
|
-
} while (findUpPath);
|
|
138
|
-
const configs = paths.map((p) => {
|
|
139
|
-
return (0, cloudformation_1.unstable_readObjectFile)({ path: p }) || {};
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* Using configs.reverser() to get the most far config first. This way the
|
|
143
|
-
* nearest configs will replace others.
|
|
144
|
-
*/
|
|
145
|
-
finalConfig = deepmerge_1.default.all(configs.reverse());
|
|
146
|
-
return finalConfig;
|
|
147
|
-
};
|
|
148
|
-
return ((0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
149
|
-
/**
|
|
150
|
-
* It can't be full strict because options may overlap among carlin config
|
|
151
|
-
* files.
|
|
152
|
-
*/
|
|
153
|
-
.strictCommands()
|
|
154
|
-
.scriptName(config_1.NAME)
|
|
155
|
-
.env(getEnv())
|
|
156
|
-
.options((0, utils_1.addGroupToOptions)(exports.options, 'Common Options'))
|
|
157
|
-
.middleware(((argv, { parsed }) => {
|
|
158
|
-
const { environment, environments } = argv;
|
|
159
|
-
/**
|
|
160
|
-
* Create final options with environment and environments.
|
|
161
|
-
*/
|
|
162
|
-
if (environment &&
|
|
163
|
-
environments &&
|
|
164
|
-
environments[environment]) {
|
|
165
|
-
Object.entries(environments[environment]).forEach(([key, value]) => {
|
|
166
|
-
/**
|
|
167
|
-
* The case where argv[key] must not have the environment value is
|
|
168
|
-
* when such value is passed as option via CLI. For instance,
|
|
169
|
-
*
|
|
170
|
-
* $ carlin deploy --stack-name SomeName
|
|
171
|
-
*
|
|
172
|
-
* SomeName must be used as stack name independently of the
|
|
173
|
-
* environment values https://github.com/ttoss/carlin/issues/13.
|
|
174
|
-
*
|
|
175
|
-
* Three cases set argv:
|
|
176
|
-
*
|
|
177
|
-
* 1. Default.
|
|
178
|
-
* 2. Config file.
|
|
179
|
-
* 3. CLI
|
|
180
|
-
*
|
|
181
|
-
* - Case 1 we determine if the parsed.defaulted is true.
|
|
182
|
-
* - Case 2 we determine if `argv[key] === finalConfig[key]`.
|
|
183
|
-
* - Case 3 if the two above are falsy.
|
|
184
|
-
*/
|
|
185
|
-
const isKeyFromCli = (() => {
|
|
186
|
-
const paramCaseKey = (0, change_case_1.paramCase)(key);
|
|
187
|
-
/**
|
|
188
|
-
* Case 1.
|
|
189
|
-
* Fixes #16 https://github.com/ttoss/carlin/issues/16
|
|
190
|
-
*/
|
|
191
|
-
if (parsed?.defaulted?.[paramCaseKey]) {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Case 2.
|
|
196
|
-
*
|
|
197
|
-
* Fixes #13 https://github.com/ttoss/carlin/issues/13
|
|
198
|
-
*
|
|
199
|
-
* Deep equal because arg can be an array or object.
|
|
200
|
-
*/
|
|
201
|
-
if ((0, deep_equal_1.default)(argv[key], finalConfig[key])) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
return true;
|
|
205
|
-
})();
|
|
206
|
-
if (!isKeyFromCli) {
|
|
207
|
-
argv[key] = value;
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}))
|
|
212
|
-
/**
|
|
213
|
-
* Sometimes "environments" can be written as "environment" on config file.
|
|
214
|
-
*/
|
|
215
|
-
.middleware(({ environment }) => {
|
|
216
|
-
if (!['string', 'undefined'].includes(typeof environment)) {
|
|
217
|
-
throw new Error(`environment type is invalid. The value: ${JSON.stringify(environment)}`);
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
/**
|
|
221
|
-
* Set AWS region.
|
|
222
|
-
*/
|
|
223
|
-
.middleware(({ region }) => {
|
|
224
|
-
aws_sdk_1.default.config.region = region;
|
|
225
|
-
(0, utils_1.setEnvVar)('REGION', region);
|
|
226
|
-
})
|
|
227
|
-
.pkgConf(getPkgConfig())
|
|
228
|
-
.config(getConfig())
|
|
229
|
-
.config('config', (configPath) => {
|
|
230
|
-
return (0, cloudformation_1.unstable_readObjectFile)({ path: configPath });
|
|
231
|
-
})
|
|
232
|
-
.command({
|
|
233
|
-
command: 'print-args',
|
|
234
|
-
describe: false,
|
|
235
|
-
handler: (argv) => {
|
|
236
|
-
// eslint-disable-next-line no-console
|
|
237
|
-
return console.log(JSON.stringify(argv, null, 2));
|
|
238
|
-
},
|
|
239
|
-
})
|
|
240
|
-
.command(command_1.deployCommand)
|
|
241
|
-
.command(ecsTaskReportCommand_1.ecsTaskReportCommand)
|
|
242
|
-
.command(generateEnvCommand_1.generateEnvCommand)
|
|
243
|
-
.epilogue('For more information, read our docs at https://ttoss.dev/docs/carlin/')
|
|
244
|
-
.help());
|
|
245
|
-
};
|
|
246
|
-
exports.cli = cli;
|
package/dist/config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NODE_RUNTIME = exports.CLOUDFRONT_REGION = exports.AWS_DEFAULT_REGION = exports.NAME = void 0;
|
|
4
|
-
exports.NAME = 'carlin';
|
|
5
|
-
exports.AWS_DEFAULT_REGION = 'us-east-1';
|
|
6
|
-
/**
|
|
7
|
-
* CloudFront triggers can be only in US East (N. Virginia) Region.
|
|
8
|
-
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html#lambda-requirements-cloudfront-triggers
|
|
9
|
-
*/
|
|
10
|
-
exports.CLOUDFRONT_REGION = 'us-east-1';
|
|
11
|
-
exports.NODE_RUNTIME = 'nodejs20.x';
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addDefaults = exports.CRITICAL_RESOURCES_TYPES = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const config_1 = require("../config");
|
|
6
|
-
const addDefaultsParametersAndTagsToParams = async (params) => {
|
|
7
|
-
const branchName = await (0, utils_1.getCurrentBranch)();
|
|
8
|
-
const environment = await (0, utils_1.getEnvironment)();
|
|
9
|
-
const packageName = await (0, utils_1.getPackageName)();
|
|
10
|
-
const packageVersion = await (0, utils_1.getPackageVersion)();
|
|
11
|
-
const projectName = await (0, utils_1.getProjectName)();
|
|
12
|
-
return {
|
|
13
|
-
...params,
|
|
14
|
-
Parameters: [
|
|
15
|
-
...(params.Parameters || []),
|
|
16
|
-
...(environment
|
|
17
|
-
? [{ ParameterKey: 'Environment', ParameterValue: environment }]
|
|
18
|
-
: []),
|
|
19
|
-
{ ParameterKey: 'Project', ParameterValue: projectName },
|
|
20
|
-
],
|
|
21
|
-
Tags: [
|
|
22
|
-
...(params.Tags || []),
|
|
23
|
-
{ Key: 'Branch', Value: branchName },
|
|
24
|
-
...(environment ? [{ Key: 'Environment', Value: environment }] : []),
|
|
25
|
-
{ Key: 'Package', Value: packageName },
|
|
26
|
-
{ Key: 'Project', Value: projectName },
|
|
27
|
-
{ Key: 'Version', Value: packageVersion },
|
|
28
|
-
].filter(({ Value }) => {
|
|
29
|
-
return !!Value;
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const addDefaultParametersToTemplate = async (template) => {
|
|
34
|
-
const [environment, projectName] = await Promise.all([
|
|
35
|
-
(0, utils_1.getEnvironment)(),
|
|
36
|
-
(0, utils_1.getProjectName)(),
|
|
37
|
-
]);
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
const newParameters = {
|
|
40
|
-
Project: { Default: projectName, Type: 'String' },
|
|
41
|
-
};
|
|
42
|
-
if (environment) {
|
|
43
|
-
newParameters.Environment = { Default: environment, Type: 'String' };
|
|
44
|
-
}
|
|
45
|
-
template.Parameters = { ...newParameters, ...template.Parameters };
|
|
46
|
-
};
|
|
47
|
-
const addLogGroupToResources = (template) => {
|
|
48
|
-
const { Resources } = template;
|
|
49
|
-
const resourcesEntries = Object.entries(Resources);
|
|
50
|
-
resourcesEntries.forEach(([key, resource]) => {
|
|
51
|
-
if (['AWS::Lambda::Function', 'AWS::Serverless::Function'].includes(resource.Type)) {
|
|
52
|
-
/**
|
|
53
|
-
* Check if exist a resource on template whose LogGroupName
|
|
54
|
-
* Properties includes the Lambda logical id.
|
|
55
|
-
*/
|
|
56
|
-
const logGroup = resourcesEntries.find(([, resource2]) => {
|
|
57
|
-
const logGroupNameStr = JSON.stringify(resource2.Properties?.LogGroupName?.['Fn::Join'] || '');
|
|
58
|
-
return logGroupNameStr.includes(key);
|
|
59
|
-
});
|
|
60
|
-
if (!logGroup) {
|
|
61
|
-
Resources[`${key}LogsLogGroup`] = {
|
|
62
|
-
Type: 'AWS::Logs::LogGroup',
|
|
63
|
-
DeletionPolicy: 'Delete',
|
|
64
|
-
Properties: {
|
|
65
|
-
LogGroupName: { 'Fn::Join': ['/', ['/aws/lambda', { Ref: key }]] },
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const addEnvironmentsToLambdaResources = async (template) => {
|
|
73
|
-
const environment = (0, utils_1.getEnvironment)();
|
|
74
|
-
const { Resources } = template;
|
|
75
|
-
const resourcesEntries = Object.entries(Resources);
|
|
76
|
-
resourcesEntries.forEach(([, resource]) => {
|
|
77
|
-
if (resource.Type === 'AWS::Lambda::Function') {
|
|
78
|
-
const { Properties } = resource;
|
|
79
|
-
/**
|
|
80
|
-
* Lambda@Edege does not support environment variables.
|
|
81
|
-
* https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-requirements-limits.html#lambda-requirements-lambda-function-configuration
|
|
82
|
-
* Then every function that has "Lambda@Edge" in its description will not
|
|
83
|
-
* have the variables passed to Environment.Variables.
|
|
84
|
-
*/
|
|
85
|
-
if ((Properties.Description || '').includes('Lambda@Edge')) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!environment) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (!Properties.Environment) {
|
|
92
|
-
Properties.Environment = {};
|
|
93
|
-
}
|
|
94
|
-
if (!Properties.Environment.Variables) {
|
|
95
|
-
Properties.Environment.Variables = {};
|
|
96
|
-
}
|
|
97
|
-
Properties.Environment.Variables.ENVIRONMENT = environment;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
exports.CRITICAL_RESOURCES_TYPES = [
|
|
102
|
-
'AWS::Cognito::UserPool',
|
|
103
|
-
'AWS::DynamoDB::Table',
|
|
104
|
-
];
|
|
105
|
-
/**
|
|
106
|
-
* Generally, critical resources are those that contain user data, such as
|
|
107
|
-
* Amazon Cognito user pools or DynamoDB tables. If you delete these resources,
|
|
108
|
-
* you might lose user data that cannot be recovered.
|
|
109
|
-
*/
|
|
110
|
-
const addRetainToCriticalResources = async (template) => {
|
|
111
|
-
const environment = (0, utils_1.getEnvironment)();
|
|
112
|
-
Object.entries(template.Resources).forEach(([, resource]) => {
|
|
113
|
-
if (exports.CRITICAL_RESOURCES_TYPES.includes(resource.Type)) {
|
|
114
|
-
if (!resource.DeletionPolicy && environment) {
|
|
115
|
-
resource.DeletionPolicy = 'Retain';
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
const addAppSyncApiOutputs = async (template) => {
|
|
121
|
-
Object.entries(template.Resources).forEach(([key, resource]) => {
|
|
122
|
-
if (resource.Type === 'AWS::AppSync::GraphQLApi') {
|
|
123
|
-
template.Outputs = {
|
|
124
|
-
[key]: {
|
|
125
|
-
Description: `Automatically added by ${config_1.NAME}`,
|
|
126
|
-
Value: { 'Fn::GetAtt': [key, 'GraphQLUrl'] },
|
|
127
|
-
Export: {
|
|
128
|
-
Name: {
|
|
129
|
-
'Fn::Join': [':', [{ Ref: 'AWS::StackName' }, 'GraphQLApiUrl']],
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
...template.Outputs,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
const addDefaults = async ({ params, template, }) => {
|
|
139
|
-
const newTemplate = JSON.parse(JSON.stringify(template));
|
|
140
|
-
await addDefaultParametersToTemplate(newTemplate);
|
|
141
|
-
await addLogGroupToResources(newTemplate);
|
|
142
|
-
await addEnvironmentsToLambdaResources(newTemplate);
|
|
143
|
-
await addAppSyncApiOutputs(newTemplate);
|
|
144
|
-
await addRetainToCriticalResources(newTemplate);
|
|
145
|
-
const response = {
|
|
146
|
-
params: await addDefaultsParametersAndTagsToParams(params),
|
|
147
|
-
template: newTemplate,
|
|
148
|
-
};
|
|
149
|
-
return response;
|
|
150
|
-
};
|
|
151
|
-
exports.addDefaults = addDefaults;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deployBaseStackCommand = void 0;
|
|
4
|
-
const deployBaseStack_1 = require("./deployBaseStack");
|
|
5
|
-
exports.deployBaseStackCommand = {
|
|
6
|
-
command: 'base-stack',
|
|
7
|
-
describe: 'Create base resources.',
|
|
8
|
-
handler: deployBaseStack_1.deployBaseStack,
|
|
9
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME = exports.BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME = exports.BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME = exports.BASE_STACK_VPC_DEFAULT_SECURITY_GROUP_EXPORTED_NAME = exports.BASE_STACK_VPC_ID_EXPORTED_NAME = exports.BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME = exports.BASE_STACK_LAMBDA_IMAGE_BUILDER_EXPORTED_NAME = exports.BASE_STACK_LAMBDA_IMAGE_BUILDER_LOGICAL_NAME = exports.BASE_STACK_BUCKET_NAME_EXPORTED_NAME = exports.BASE_STACK_BUCKET_LOGICAL_NAME = exports.BASE_STACK_BUCKET_TEMPLATES_FOLDER = exports.BASE_STACK_NAME = void 0;
|
|
4
|
-
const config_1 = require("../../config");
|
|
5
|
-
const change_case_1 = require("change-case");
|
|
6
|
-
const pascalCaseName = (0, change_case_1.pascalCase)(config_1.NAME);
|
|
7
|
-
exports.BASE_STACK_NAME = `${pascalCaseName}BaseStack`;
|
|
8
|
-
exports.BASE_STACK_BUCKET_TEMPLATES_FOLDER = 'cloudformation-templates';
|
|
9
|
-
/**
|
|
10
|
-
* S3 Bucket.
|
|
11
|
-
*/
|
|
12
|
-
exports.BASE_STACK_BUCKET_LOGICAL_NAME = `${pascalCaseName}Bucket`;
|
|
13
|
-
exports.BASE_STACK_BUCKET_NAME_EXPORTED_NAME = `${pascalCaseName}BucketNameExportedName`;
|
|
14
|
-
/**
|
|
15
|
-
* Lambda image builder.
|
|
16
|
-
*/
|
|
17
|
-
exports.BASE_STACK_LAMBDA_IMAGE_BUILDER_LOGICAL_NAME = `${pascalCaseName}LambdaImageBuilder`;
|
|
18
|
-
exports.BASE_STACK_LAMBDA_IMAGE_BUILDER_EXPORTED_NAME = `${pascalCaseName}LambdaImageBuilderExportedName`;
|
|
19
|
-
/**
|
|
20
|
-
* Lambda layer builder.
|
|
21
|
-
*/
|
|
22
|
-
exports.BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME = `${pascalCaseName}LambdaLayerBuilder`;
|
|
23
|
-
/**
|
|
24
|
-
* VPC
|
|
25
|
-
*/
|
|
26
|
-
exports.BASE_STACK_VPC_ID_EXPORTED_NAME = `${pascalCaseName}VPCIDExportedName`;
|
|
27
|
-
exports.BASE_STACK_VPC_DEFAULT_SECURITY_GROUP_EXPORTED_NAME = `${pascalCaseName}DefaultSecurityGroupExportedName`;
|
|
28
|
-
exports.BASE_STACK_VPC_PUBLIC_SUBNET_0_EXPORTED_NAME = `${pascalCaseName}VPCPublicSubnet0ExportedName`;
|
|
29
|
-
exports.BASE_STACK_VPC_PUBLIC_SUBNET_1_EXPORTED_NAME = `${pascalCaseName}VPCPublicSubnet1ExportedName`;
|
|
30
|
-
exports.BASE_STACK_VPC_PUBLIC_SUBNET_2_EXPORTED_NAME = `${pascalCaseName}VPCPublicSubnet2ExportedName`;
|
|
@@ -1,62 +0,0 @@
|
|
|
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.deployBaseStack = exports.baseStackTemplate = void 0;
|
|
7
|
-
const config_1 = require("./config");
|
|
8
|
-
const cloudformation_core_1 = require("../cloudformation.core");
|
|
9
|
-
const getBucketTemplate_1 = require("./getBucketTemplate");
|
|
10
|
-
const getLambdaImageBuilderTemplate_1 = require("./getLambdaImageBuilderTemplate");
|
|
11
|
-
const getLambdaLayerBuilderTemplate_1 = require("./getLambdaLayerBuilderTemplate");
|
|
12
|
-
const getVpcTemplate_1 = require("./getVpcTemplate");
|
|
13
|
-
const utils_1 = require("../utils");
|
|
14
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
15
|
-
const logPrefix = 'base-stack';
|
|
16
|
-
exports.baseStackTemplate = deepmerge_1.default.all([
|
|
17
|
-
(0, getBucketTemplate_1.getBucketTemplate)(),
|
|
18
|
-
(0, getLambdaImageBuilderTemplate_1.getLambdaImageBuilderTemplate)(),
|
|
19
|
-
(0, getLambdaLayerBuilderTemplate_1.getLambdaLayerBuilderTemplate)(),
|
|
20
|
-
(0, getVpcTemplate_1.getVpcTemplate)(),
|
|
21
|
-
]);
|
|
22
|
-
/**
|
|
23
|
-
* Base Stack is a set of auxiliary resources that will be used to help at the
|
|
24
|
-
* deployment time. The resources that will be created are listed below.
|
|
25
|
-
*
|
|
26
|
-
* - **S3 bucket**. Deployment may need an auxiliary bucket to succeed. For
|
|
27
|
-
* instance, to deploy resources that contain a
|
|
28
|
-
* [Lambda](https://carlin.ttoss.dev/docs/commands/deploy#lambda), we need a S3
|
|
29
|
-
* bucket to upload the zipped code. Or if the CloudFormation template has a
|
|
30
|
-
* size greater than [the limit](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html),
|
|
31
|
-
* we need to upload the template to a S3 bucket in order to create/update the
|
|
32
|
-
* stack.
|
|
33
|
-
*
|
|
34
|
-
* - **Lambda Layer builder**. This resource is a CodeBuild project that is
|
|
35
|
-
* used to create Lambda Layers when [--lambda-externals](/docs/api-reference/deploy#lambda-externals)
|
|
36
|
-
* has values.
|
|
37
|
-
*
|
|
38
|
-
* - **Lambda Image builder**. This resource is a CodeBuild project that builds
|
|
39
|
-
* Docker Images if Lambda is going to use them.
|
|
40
|
-
*
|
|
41
|
-
* - **VPC**. This resource is used when some network infrastructure is
|
|
42
|
-
* required. For example, CICD needs a VPC to execute the [Fargate](https://aws.amazon.com/fargate/)
|
|
43
|
-
* operations.
|
|
44
|
-
*/
|
|
45
|
-
const deployBaseStack = async () => {
|
|
46
|
-
try {
|
|
47
|
-
const { stackName } = await (0, utils_1.handleDeployInitialization)({
|
|
48
|
-
logPrefix,
|
|
49
|
-
stackName: config_1.BASE_STACK_NAME,
|
|
50
|
-
});
|
|
51
|
-
await (0, cloudformation_core_1.deploy)({
|
|
52
|
-
template: exports.baseStackTemplate,
|
|
53
|
-
params: { StackName: stackName },
|
|
54
|
-
terminationProtection: true,
|
|
55
|
-
});
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
(0, utils_1.handleDeployError)({ error, logPrefix });
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.deployBaseStack = deployBaseStack;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBaseStackResource = exports.getBaseStackOutput = void 0;
|
|
4
|
-
const config_1 = require("./config");
|
|
5
|
-
const cloudformation_core_1 = require("../cloudformation.core");
|
|
6
|
-
const getBaseStackOutput = async (outputKey) => {
|
|
7
|
-
const output = await (0, cloudformation_core_1.getStackOutput)({
|
|
8
|
-
stackName: config_1.BASE_STACK_NAME,
|
|
9
|
-
outputKey,
|
|
10
|
-
});
|
|
11
|
-
return output.OutputValue;
|
|
12
|
-
};
|
|
13
|
-
exports.getBaseStackOutput = getBaseStackOutput;
|
|
14
|
-
const resourcesKeys = {
|
|
15
|
-
BASE_STACK_BUCKET_LOGICAL_NAME: config_1.BASE_STACK_BUCKET_LOGICAL_NAME,
|
|
16
|
-
BASE_STACK_LAMBDA_IMAGE_BUILDER_LOGICAL_NAME: config_1.BASE_STACK_LAMBDA_IMAGE_BUILDER_LOGICAL_NAME,
|
|
17
|
-
BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME: config_1.BASE_STACK_LAMBDA_LAYER_BUILDER_LOGICAL_NAME,
|
|
18
|
-
};
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
const resources = {};
|
|
21
|
-
const getBaseStackResource = async (resource) => {
|
|
22
|
-
if (!resources[resource]) {
|
|
23
|
-
resources[resource] = await (0, exports.getBaseStackOutput)(resourcesKeys[resource]);
|
|
24
|
-
}
|
|
25
|
-
return resources[resource];
|
|
26
|
-
};
|
|
27
|
-
exports.getBaseStackResource = getBaseStackResource;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBucketTemplate = void 0;
|
|
4
|
-
const config_1 = require("./config");
|
|
5
|
-
const getBucketTemplate = () => {
|
|
6
|
-
return {
|
|
7
|
-
AWSTemplateFormatVersion: '2010-09-09',
|
|
8
|
-
Resources: {
|
|
9
|
-
[config_1.BASE_STACK_BUCKET_LOGICAL_NAME]: {
|
|
10
|
-
Type: 'AWS::S3::Bucket',
|
|
11
|
-
DeletionPolicy: 'Retain',
|
|
12
|
-
Properties: {
|
|
13
|
-
LifecycleConfiguration: {
|
|
14
|
-
Rules: [
|
|
15
|
-
{
|
|
16
|
-
ExpirationInDays: 1,
|
|
17
|
-
Prefix: config_1.BASE_STACK_BUCKET_TEMPLATES_FOLDER,
|
|
18
|
-
Status: 'Enabled',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
NoncurrentVersionExpirationInDays: 3,
|
|
22
|
-
Status: 'Enabled',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
/**
|
|
27
|
-
* This is necessary because if we update Lambda code without change
|
|
28
|
-
* CloudFormation template, the Lambda will not be updated.
|
|
29
|
-
*/
|
|
30
|
-
VersioningConfiguration: {
|
|
31
|
-
Status: 'Enabled',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
Outputs: {
|
|
37
|
-
[config_1.BASE_STACK_BUCKET_LOGICAL_NAME]: {
|
|
38
|
-
Value: { Ref: config_1.BASE_STACK_BUCKET_LOGICAL_NAME },
|
|
39
|
-
Export: {
|
|
40
|
-
Name: config_1.BASE_STACK_BUCKET_NAME_EXPORTED_NAME,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
exports.getBucketTemplate = getBucketTemplate;
|