@geek-fun/serverlessinsight 0.0.2 → 0.0.4
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/package.json +4 -1
- package/dist/src/commands/deploy.js +6 -9
- package/dist/src/commands/index.js +6 -1
- package/dist/src/commands/validate.js +5 -5
- package/dist/src/common/actionContext.js +3 -0
- package/dist/src/common/iacHelper.js +70 -0
- package/dist/src/common/index.d.ts +1 -1
- package/dist/src/common/index.js +1 -1
- package/dist/src/common/logger.js +4 -0
- package/dist/src/common/rosClient.js +13 -11
- package/dist/src/stack/deploy.js +8 -49
- package/dist/src/{iac → stack}/iacSchema.js +6 -2
- package/dist/src/stack/iacStack.js +140 -0
- package/dist/src/stack/index.d.ts +2 -0
- package/dist/src/stack/index.js +16 -0
- package/dist/src/{iac → stack}/parse.js +7 -1
- package/dist/src/types.js +5 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -1
- package/dist/src/common/printer.js +0 -12
- package/dist/src/iac/index.d.ts +0 -2
- package/dist/src/iac/index.js +0 -18
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -50,14 +50,17 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/openapi-client": "^0.4.11",
|
|
53
|
+
"@alicloud/ros-cdk-apigateway": "^1.2.0",
|
|
53
54
|
"@alicloud/ros-cdk-core": "^1.2.0",
|
|
54
55
|
"@alicloud/ros-cdk-fc": "^1.2.0",
|
|
56
|
+
"@alicloud/ros-cdk-ram": "^1.2.0",
|
|
55
57
|
"@alicloud/ros20190910": "^3.4.3",
|
|
56
58
|
"ajv": "^8.17.1",
|
|
57
59
|
"chalk": "^4.1.2",
|
|
58
60
|
"commander": "^11.1.0",
|
|
59
61
|
"i18n": "^0.15.1",
|
|
60
62
|
"pino": "^8.17.2",
|
|
63
|
+
"pino-pretty": "^11.2.2",
|
|
61
64
|
"yaml": "^2.5.1"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deploy = void 0;
|
|
4
4
|
const stack_1 = require("../stack");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
|
-
const iac_1 = require("../iac");
|
|
7
|
-
const actionContext_1 = require("../common/actionContext");
|
|
8
6
|
const deploy = async (stackName, options) => {
|
|
9
|
-
const context = (0,
|
|
10
|
-
common_1.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
common_1.
|
|
14
|
-
common_1.printer.info('Deploying stack...');
|
|
7
|
+
const context = (0, common_1.constructActionContext)({ ...options, stackName });
|
|
8
|
+
common_1.logger.info('Validating yaml...');
|
|
9
|
+
const iac = (0, stack_1.parseYaml)(context.iacLocation);
|
|
10
|
+
common_1.logger.info('Yaml is valid! 🎉');
|
|
11
|
+
common_1.logger.info('Deploying stack...');
|
|
15
12
|
await (0, stack_1.deployStack)(stackName, iac, context);
|
|
16
|
-
common_1.
|
|
13
|
+
common_1.logger.info('Stack deployed! 🎉');
|
|
17
14
|
};
|
|
18
15
|
exports.deploy = deploy;
|
|
@@ -31,8 +31,13 @@ program
|
|
|
31
31
|
.command('deploy <stackName>')
|
|
32
32
|
.description('deploy serverless Iac yaml')
|
|
33
33
|
.option('-f, --file <path>', 'specify the yaml file')
|
|
34
|
+
.option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
|
|
35
|
+
const [key, val] = value.split('=');
|
|
36
|
+
previous[key] = val;
|
|
37
|
+
return previous;
|
|
38
|
+
}, {})
|
|
34
39
|
.action(async (stackName, options) => {
|
|
35
40
|
common_1.logger.debug('log command info');
|
|
36
|
-
await (0, deploy_1.deploy)(stackName, { location: options.file });
|
|
41
|
+
await (0, deploy_1.deploy)(stackName, { location: options.file, parameters: options.parameter });
|
|
37
42
|
});
|
|
38
43
|
program.parse();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validate = void 0;
|
|
4
|
-
const iac_1 = require("../iac");
|
|
5
4
|
const common_1 = require("../common");
|
|
6
|
-
const
|
|
5
|
+
const stack_1 = require("../stack");
|
|
7
6
|
const validate = (location) => {
|
|
8
|
-
const context = (0,
|
|
9
|
-
(0,
|
|
10
|
-
common_1.
|
|
7
|
+
const context = (0, common_1.constructActionContext)({ location });
|
|
8
|
+
(0, stack_1.parseYaml)(context.iacLocation);
|
|
9
|
+
common_1.logger.info('Yaml is valid! 🎉');
|
|
10
|
+
common_1.logger.debug('Yaml is valid! debug🎉');
|
|
11
11
|
};
|
|
12
12
|
exports.validate = validate;
|
|
@@ -7,6 +7,8 @@ exports.constructActionContext = void 0;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const constructActionContext = (config) => {
|
|
9
9
|
return {
|
|
10
|
+
stage: config?.stage ?? 'default',
|
|
11
|
+
stackName: config?.stackName ?? '',
|
|
10
12
|
region: config?.region ?? process.env.ROS_REGION_ID ?? process.env.ALIYUN_REGION ?? 'cn-hangzhou',
|
|
11
13
|
accessKeyId: config?.accessKeyId ?? process.env.ALIYUN_ACCESS_KEY_ID,
|
|
12
14
|
accessKeySecret: config?.accessKeySecret ?? process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
@@ -17,6 +19,7 @@ const constructActionContext = (config) => {
|
|
|
17
19
|
? node_path_1.default.resolve(projectRoot, config?.location)
|
|
18
20
|
: node_path_1.default.resolve(projectRoot, 'serverless-insight.yml');
|
|
19
21
|
})(),
|
|
22
|
+
parameters: Object.entries(config?.parameters ?? {}).map(([key, value]) => ({ key, value })),
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
25
|
exports.constructActionContext = constructActionContext;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.replaceVars = exports.resolveCode = void 0;
|
|
30
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
31
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
32
|
+
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
33
|
+
const resolveCode = (location) => {
|
|
34
|
+
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
35
|
+
const fileContent = node_fs_1.default.readFileSync(filePath);
|
|
36
|
+
return fileContent.toString('base64');
|
|
37
|
+
};
|
|
38
|
+
exports.resolveCode = resolveCode;
|
|
39
|
+
const replaceVars = (value, stage) => {
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
const matchVar = value.match(/^\$\{vars\.(\w+)}$/);
|
|
42
|
+
const containsVar = value.match(/\$\{vars\.(\w+)}/);
|
|
43
|
+
const matchMap = value.match(/^\$\{stages\.(\w+)}$/);
|
|
44
|
+
const containsMap = value.match(/\$\{stages\.(\w+)}/);
|
|
45
|
+
if (matchVar?.length) {
|
|
46
|
+
return ros.Fn.ref(matchVar[1]);
|
|
47
|
+
}
|
|
48
|
+
if (matchMap?.length) {
|
|
49
|
+
return ros.Fn.findInMap('stages', '', matchMap[1]);
|
|
50
|
+
}
|
|
51
|
+
if (containsMap?.length && containsVar?.length) {
|
|
52
|
+
return ros.Fn.sub(value.replace(/\$\{stages\.(\w+)}/g, '${$1}').replace(/\$\{vars\.(\w+)}/g, '${$1}'));
|
|
53
|
+
}
|
|
54
|
+
if (containsVar?.length) {
|
|
55
|
+
return ros.Fn.sub(value.replace(/\$\{vars\.(\w+)}/g, '${$1}'));
|
|
56
|
+
}
|
|
57
|
+
if (containsMap?.length) {
|
|
58
|
+
return ros.Fn.sub(value.replace(/\$\{stages\.(\w+)}/g, '${$1}'));
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return value.map((item) => (0, exports.replaceVars)(item, stage));
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === 'object' && value !== null) {
|
|
66
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, (0, exports.replaceVars)(val, stage)]));
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
};
|
|
70
|
+
exports.replaceVars = replaceVars;
|
package/dist/src/common/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./printer"), exports);
|
|
18
17
|
__exportStar(require("./provider"), exports);
|
|
19
18
|
__exportStar(require("./logger"), exports);
|
|
20
19
|
__exportStar(require("./getVersion"), exports);
|
|
21
20
|
__exportStar(require("./rosClient"), exports);
|
|
22
21
|
__exportStar(require("./actionContext"), exports);
|
|
22
|
+
__exportStar(require("./iacHelper"), exports);
|
|
@@ -7,5 +7,9 @@ exports.logger = void 0;
|
|
|
7
7
|
const pino_1 = __importDefault(require("pino"));
|
|
8
8
|
const logger = (0, pino_1.default)({
|
|
9
9
|
name: 'ServerlessInsight',
|
|
10
|
+
level: ['ServerlessInsight', '*'].includes(process.env.DEBUG || '') ? 'debug' : 'info',
|
|
11
|
+
transport: {
|
|
12
|
+
target: 'pino-pretty',
|
|
13
|
+
},
|
|
10
14
|
});
|
|
11
15
|
exports.logger = logger;
|
|
@@ -30,7 +30,7 @@ exports.rosStackDeploy = void 0;
|
|
|
30
30
|
const tea_util_1 = __importDefault(require("@alicloud/tea-util"));
|
|
31
31
|
const ros20190910_1 = __importStar(require("@alicloud/ros20190910"));
|
|
32
32
|
const openapi_client_1 = require("@alicloud/openapi-client");
|
|
33
|
-
const
|
|
33
|
+
const logger_1 = require("./logger");
|
|
34
34
|
const client = new ros20190910_1.default(new openapi_client_1.Config({
|
|
35
35
|
accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
|
|
36
36
|
accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
@@ -54,15 +54,17 @@ const createStack = async (stackName, templateBody, context) => {
|
|
|
54
54
|
console.log(`创建中,资源栈ID:${response.body?.stackId}`);
|
|
55
55
|
return response.body?.stackId;
|
|
56
56
|
};
|
|
57
|
-
const updateStack = async (
|
|
58
|
-
const parameters = context.parameters?.map((parameter) => new ros20190910_1.
|
|
57
|
+
const updateStack = async (stackId, templateBody, context) => {
|
|
58
|
+
const parameters = context.parameters?.map((parameter) => new ros20190910_1.UpdateStackRequestParameters({
|
|
59
59
|
parameterKey: tea_util_1.default.assertAsString(parameter.key),
|
|
60
|
-
parameterValue: tea_util_1.default.assertAsString(parameter.
|
|
60
|
+
parameterValue: tea_util_1.default.assertAsString(parameter.key),
|
|
61
61
|
}));
|
|
62
|
-
const createStackRequest = new ros20190910_1.
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const createStackRequest = new ros20190910_1.UpdateStackRequest({
|
|
63
|
+
regionId: context.region,
|
|
64
|
+
stackId,
|
|
65
|
+
templateBody: JSON.stringify(templateBody),
|
|
65
66
|
parameters,
|
|
67
|
+
tags: context.tags?.map((tag) => new ros20190910_1.CreateStackRequestTags(tag)),
|
|
66
68
|
});
|
|
67
69
|
const response = await client.updateStack(createStackRequest);
|
|
68
70
|
console.log(`更新中,资源栈ID:${response.body?.stackId}`);
|
|
@@ -87,15 +89,15 @@ const rosStackDeploy = async (stackName, templateBody, context) => {
|
|
|
87
89
|
if (stackInfo) {
|
|
88
90
|
const { Status: stackStatus } = stackInfo;
|
|
89
91
|
if (stackStatus?.indexOf('IN_PROGRESS') >= 0) {
|
|
90
|
-
|
|
92
|
+
logger_1.logger.error(`fail to update stack, because stack status is ${stackStatus}`);
|
|
91
93
|
throw new Error(`fail to update stack, because stack status is ${stackStatus}`);
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
return await updateStack(
|
|
95
|
+
logger_1.logger.info(`Update stack: ${stackName} deploying... `);
|
|
96
|
+
return await updateStack(stackInfo.stackId, templateBody, context);
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
99
|
// create stack
|
|
98
|
-
|
|
100
|
+
logger_1.logger.info(`Create stack: ${stackName} deploying... `);
|
|
99
101
|
return await createStack(stackName, templateBody, context);
|
|
100
102
|
}
|
|
101
103
|
};
|
package/dist/src/stack/deploy.js
CHANGED
|
@@ -22,62 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.deployStack =
|
|
26
|
+
exports.deployStack = void 0;
|
|
30
27
|
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
31
|
-
const fc = __importStar(require("@alicloud/ros-cdk-fc"));
|
|
32
28
|
const common_1 = require("../common");
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const resolveCode = (location) => {
|
|
36
|
-
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
37
|
-
const fileContent = fs.readFileSync(filePath);
|
|
38
|
-
return fileContent.toString('base64');
|
|
39
|
-
};
|
|
40
|
-
class IacStack extends ros.Stack {
|
|
41
|
-
constructor(scope, iac, props) {
|
|
42
|
-
super(scope, iac.service, props);
|
|
43
|
-
new ros.RosInfo(this, ros.RosInfo.description, 'This is the simple ros cdk app example.');
|
|
44
|
-
const service = new fc.RosService(this, `${iac.service}-service`, {
|
|
45
|
-
serviceName: `${iac.service}-service`,
|
|
46
|
-
}, true);
|
|
47
|
-
iac.functions.forEach((fnc) => {
|
|
48
|
-
const func = new fc.RosFunction(this, fnc.key, {
|
|
49
|
-
functionName: fnc.name,
|
|
50
|
-
serviceName: service.serviceName,
|
|
51
|
-
handler: fnc.handler,
|
|
52
|
-
runtime: fnc.runtime,
|
|
53
|
-
memorySize: fnc.memory,
|
|
54
|
-
timeout: fnc.timeout,
|
|
55
|
-
environmentVariables: fnc.environment,
|
|
56
|
-
code: {
|
|
57
|
-
zipFile: resolveCode(fnc.code),
|
|
58
|
-
},
|
|
59
|
-
}, true);
|
|
60
|
-
func.addDependsOn(service);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.IacStack = IacStack;
|
|
65
|
-
const generateStackTemplate = (stackName, iac) => {
|
|
29
|
+
const iacStack_1 = require("./iacStack");
|
|
30
|
+
const generateStackTemplate = (stackName, iac, context) => {
|
|
66
31
|
const app = new ros.App();
|
|
67
|
-
new IacStack(app, iac);
|
|
32
|
+
new iacStack_1.IacStack(app, iac, context);
|
|
68
33
|
const assembly = app.synth();
|
|
69
34
|
const stackArtifact = assembly.getStackByName(stackName);
|
|
70
|
-
|
|
71
|
-
key,
|
|
72
|
-
value,
|
|
73
|
-
}));
|
|
74
|
-
return { template: stackArtifact.template, parameters };
|
|
35
|
+
return { template: stackArtifact.template };
|
|
75
36
|
};
|
|
76
37
|
const deployStack = async (stackName, iac, context) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await (0, common_1.rosStackDeploy)(stackName, template, { ...context, parameters });
|
|
81
|
-
common_1.printer.info(`Stack deployed! 🎉`);
|
|
38
|
+
const { template } = generateStackTemplate(stackName, iac, context);
|
|
39
|
+
await (0, common_1.rosStackDeploy)(stackName, template, context);
|
|
40
|
+
common_1.logger.info(`Stack deployed! 🎉`);
|
|
82
41
|
};
|
|
83
42
|
exports.deployStack = deployStack;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.validateYaml = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
const common_1 = require("../common");
|
|
8
9
|
const ajv = new ajv_1.default({ allowUnionTypes: true, strict: false, allErrors: true });
|
|
9
10
|
const schema = {
|
|
10
11
|
type: 'object',
|
|
@@ -82,6 +83,7 @@ const schema = {
|
|
|
82
83
|
'.*': {
|
|
83
84
|
type: 'object',
|
|
84
85
|
properties: {
|
|
86
|
+
name: { type: 'string' },
|
|
85
87
|
type: { type: 'string', enum: ['API_GATEWAY'] },
|
|
86
88
|
triggers: {
|
|
87
89
|
type: 'array',
|
|
@@ -93,7 +95,7 @@ const schema = {
|
|
|
93
95
|
},
|
|
94
96
|
},
|
|
95
97
|
},
|
|
96
|
-
required: ['type', 'triggers'],
|
|
98
|
+
required: ['name', 'type', 'triggers'],
|
|
97
99
|
},
|
|
98
100
|
},
|
|
99
101
|
},
|
|
@@ -119,8 +121,10 @@ class IacSchemaErrors extends Error {
|
|
|
119
121
|
const validateYaml = (iacJson) => {
|
|
120
122
|
const validate = ajv.compile(schema);
|
|
121
123
|
const valid = validate(iacJson);
|
|
122
|
-
if (!valid)
|
|
124
|
+
if (!valid) {
|
|
125
|
+
common_1.logger.debug(`Invalid yaml: ${JSON.stringify(validate.errors)}`);
|
|
123
126
|
throw new IacSchemaErrors(validate.errors);
|
|
127
|
+
}
|
|
124
128
|
return true;
|
|
125
129
|
};
|
|
126
130
|
exports.validateYaml = validateYaml;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.IacStack = void 0;
|
|
27
|
+
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
28
|
+
const ros_cdk_core_1 = require("@alicloud/ros-cdk-core");
|
|
29
|
+
const types_1 = require("../types");
|
|
30
|
+
const fc = __importStar(require("@alicloud/ros-cdk-fc"));
|
|
31
|
+
const ram = __importStar(require("@alicloud/ros-cdk-ram"));
|
|
32
|
+
const agw = __importStar(require("@alicloud/ros-cdk-apigateway"));
|
|
33
|
+
const common_1 = require("../common");
|
|
34
|
+
class IacStack extends ros.Stack {
|
|
35
|
+
constructor(scope, iac, context) {
|
|
36
|
+
super(scope, iac.service, {
|
|
37
|
+
stackName: context.stackName,
|
|
38
|
+
tags: iac.tags.reduce((acc, tag) => {
|
|
39
|
+
acc[tag.key] = (0, common_1.replaceVars)(tag.value, context.stage);
|
|
40
|
+
return acc;
|
|
41
|
+
}, {}),
|
|
42
|
+
});
|
|
43
|
+
// Define Parameters
|
|
44
|
+
Object.entries(iac.vars).map(([key, value]) => new ros.RosParameter(this, key, {
|
|
45
|
+
type: ros_cdk_core_1.RosParameterType.STRING,
|
|
46
|
+
defaultValue: value,
|
|
47
|
+
}));
|
|
48
|
+
// Define Mappings
|
|
49
|
+
new ros.RosMapping(this, 'stages', { mapping: (0, common_1.replaceVars)(iac.stages, context.stage) });
|
|
50
|
+
new ros.RosInfo(this, ros.RosInfo.description, (0, common_1.replaceVars)(`${iac.service} stack`, context.stage));
|
|
51
|
+
const service = new fc.RosService(this, (0, common_1.replaceVars)(`${iac.service}-service`, context.stage), {
|
|
52
|
+
serviceName: (0, common_1.replaceVars)(`${iac.service}-service`, context.stage),
|
|
53
|
+
tags: (0, common_1.replaceVars)(iac.tags, context.stage),
|
|
54
|
+
}, true);
|
|
55
|
+
iac.functions.forEach((fnc) => {
|
|
56
|
+
const func = new fc.RosFunction(this, fnc.key, {
|
|
57
|
+
functionName: (0, common_1.replaceVars)(fnc.name, context.stage),
|
|
58
|
+
serviceName: (0, common_1.replaceVars)(service.serviceName, context.stage),
|
|
59
|
+
handler: (0, common_1.replaceVars)(fnc.handler, context.stage),
|
|
60
|
+
runtime: (0, common_1.replaceVars)(fnc.runtime, context.stage),
|
|
61
|
+
memorySize: (0, common_1.replaceVars)(fnc.memory, context.stage),
|
|
62
|
+
timeout: (0, common_1.replaceVars)(fnc.timeout, context.stage),
|
|
63
|
+
environmentVariables: (0, common_1.replaceVars)(fnc.environment, context.stage),
|
|
64
|
+
code: {
|
|
65
|
+
zipFile: (0, common_1.resolveCode)(fnc.code),
|
|
66
|
+
},
|
|
67
|
+
}, true);
|
|
68
|
+
func.addDependsOn(service);
|
|
69
|
+
});
|
|
70
|
+
const apiGateway = iac.events?.filter((event) => event.type === types_1.EventTypes.API_GATEWAY);
|
|
71
|
+
if (apiGateway?.length) {
|
|
72
|
+
const gatewayAccessRole = new ram.RosRole(this, (0, common_1.replaceVars)(`${iac.service}_role`, context.stage), {
|
|
73
|
+
roleName: (0, common_1.replaceVars)(`${iac.service}-gateway-access-role`, context.stage),
|
|
74
|
+
description: (0, common_1.replaceVars)(`${iac.service} role`, context.stage),
|
|
75
|
+
assumeRolePolicyDocument: {
|
|
76
|
+
version: '1',
|
|
77
|
+
statement: [
|
|
78
|
+
{
|
|
79
|
+
action: 'sts:AssumeRole',
|
|
80
|
+
effect: 'Allow',
|
|
81
|
+
principal: {
|
|
82
|
+
service: ['apigateway.aliyuncs.com'],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
policies: [
|
|
88
|
+
{
|
|
89
|
+
policyName: (0, common_1.replaceVars)(`${iac.service}-policy`, context.stage),
|
|
90
|
+
policyDocument: {
|
|
91
|
+
version: '1',
|
|
92
|
+
statement: [
|
|
93
|
+
{
|
|
94
|
+
action: ['fc:InvokeFunction'],
|
|
95
|
+
effect: 'Allow',
|
|
96
|
+
// @TODO implement at least permission granting
|
|
97
|
+
resource: ['*'],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
}, true);
|
|
104
|
+
const apiGatewayGroup = new agw.RosGroup(this, (0, common_1.replaceVars)(`${iac.service}_apigroup`, context.stage), {
|
|
105
|
+
groupName: (0, common_1.replaceVars)(`${iac.service}_apigroup`, context.stage),
|
|
106
|
+
tags: (0, common_1.replaceVars)(iac.tags, context.stage),
|
|
107
|
+
}, true);
|
|
108
|
+
apiGateway.forEach((event) => {
|
|
109
|
+
event.triggers.forEach((trigger) => {
|
|
110
|
+
const key = `${trigger.method}_${trigger.path}`.toLowerCase().replace(/\//g, '_');
|
|
111
|
+
const api = new agw.RosApi(this, (0, common_1.replaceVars)(`${event.key}_api_${key}`, context.stage), {
|
|
112
|
+
apiName: (0, common_1.replaceVars)(`${event.name}_api_${key}`, context.stage),
|
|
113
|
+
groupId: apiGatewayGroup.attrGroupId,
|
|
114
|
+
visibility: 'PRIVATE',
|
|
115
|
+
requestConfig: {
|
|
116
|
+
requestProtocol: 'HTTP',
|
|
117
|
+
requestHttpMethod: (0, common_1.replaceVars)(trigger.method, context.stage),
|
|
118
|
+
requestPath: (0, common_1.replaceVars)(trigger.path, context.stage),
|
|
119
|
+
requestMode: 'PASSTHROUGH',
|
|
120
|
+
},
|
|
121
|
+
serviceConfig: {
|
|
122
|
+
serviceProtocol: 'FunctionCompute',
|
|
123
|
+
functionComputeConfig: {
|
|
124
|
+
fcRegionId: context.region,
|
|
125
|
+
serviceName: service.serviceName,
|
|
126
|
+
functionName: trigger.backend,
|
|
127
|
+
roleArn: gatewayAccessRole.attrArn,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
resultSample: 'ServerlessInsight resultSample',
|
|
131
|
+
resultType: 'JSON',
|
|
132
|
+
tags: (0, common_1.replaceVars)(iac.tags, context.stage),
|
|
133
|
+
}, true);
|
|
134
|
+
api.addDependsOn(apiGatewayGroup);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.IacStack = IacStack;
|
package/dist/src/stack/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.deployStack = void 0;
|
|
4
18
|
var deploy_1 = require("./deploy");
|
|
5
19
|
Object.defineProperty(exports, "deployStack", { enumerable: true, get: function () { return deploy_1.deployStack; } });
|
|
20
|
+
__exportStar(require("./parse"), exports);
|
|
21
|
+
__exportStar(require("./iacSchema"), exports);
|
|
@@ -7,6 +7,9 @@ const iacSchema_1 = require("./iacSchema");
|
|
|
7
7
|
const mapToArr = (obj) => {
|
|
8
8
|
return Object.entries(obj).map(([key, value]) => typeof value === 'string' ? { [key]: value } : { key, ...value });
|
|
9
9
|
};
|
|
10
|
+
const mapToKvArr = (obj) => {
|
|
11
|
+
return Object.entries(obj).map(([key, value]) => ({ key, value }));
|
|
12
|
+
};
|
|
10
13
|
const validateExistence = (path) => {
|
|
11
14
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
12
15
|
throw new Error(`File does not exist at path: ${path}`);
|
|
@@ -21,7 +24,10 @@ const transformYaml = (iacJson) => {
|
|
|
21
24
|
stages: iacJson.stages,
|
|
22
25
|
functions: mapToArr(iacJson.functions),
|
|
23
26
|
events: mapToArr(iacJson.events),
|
|
24
|
-
tags:
|
|
27
|
+
tags: [
|
|
28
|
+
{ key: 'iac-provider', value: 'ServerlessInsight' },
|
|
29
|
+
...mapToKvArr(iacJson.tags),
|
|
30
|
+
],
|
|
25
31
|
};
|
|
26
32
|
};
|
|
27
33
|
const parseYaml = (yamlPath) => {
|
package/dist/src/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/types.ts","../src/commands/deploy.ts","../src/commands/index.ts","../src/commands/validate.ts","../src/common/actionContext.ts","../src/common/getVersion.ts","../src/common/
|
|
1
|
+
{"root":["../src/index.ts","../src/types.ts","../src/commands/deploy.ts","../src/commands/index.ts","../src/commands/validate.ts","../src/common/actionContext.ts","../src/common/getVersion.ts","../src/common/iacHelper.ts","../src/common/index.ts","../src/common/logger.ts","../src/common/provider.ts","../src/common/rosClient.ts","../src/lang/index.ts","../src/stack/deploy.ts","../src/stack/iacSchema.ts","../src/stack/iacStack.ts","../src/stack/index.ts","../src/stack/parse.ts"],"version":"5.6.2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -50,14 +50,17 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/openapi-client": "^0.4.11",
|
|
53
|
+
"@alicloud/ros-cdk-apigateway": "^1.2.0",
|
|
53
54
|
"@alicloud/ros-cdk-core": "^1.2.0",
|
|
54
55
|
"@alicloud/ros-cdk-fc": "^1.2.0",
|
|
56
|
+
"@alicloud/ros-cdk-ram": "^1.2.0",
|
|
55
57
|
"@alicloud/ros20190910": "^3.4.3",
|
|
56
58
|
"ajv": "^8.17.1",
|
|
57
59
|
"chalk": "^4.1.2",
|
|
58
60
|
"commander": "^11.1.0",
|
|
59
61
|
"i18n": "^0.15.1",
|
|
60
62
|
"pino": "^8.17.2",
|
|
63
|
+
"pino-pretty": "^11.2.2",
|
|
61
64
|
"yaml": "^2.5.1"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
@@ -1,12 +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.printer = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
exports.printer = {
|
|
9
|
-
success: (message) => console.log(`${chalk_1.default.blue('ServerlessInsight')}: ${chalk_1.default.green(message)}`),
|
|
10
|
-
info: (message) => console.log(`${chalk_1.default.blue('ServerlessInsight')}: ${message}`),
|
|
11
|
-
error: (message) => console.log(`${chalk_1.default.bgRed(chalk_1.default.black('ServerlessInsight'))}: ${chalk_1.default.red(message)}`),
|
|
12
|
-
};
|
package/dist/src/iac/index.d.ts
DELETED
package/dist/src/iac/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./parse"), exports);
|
|
18
|
-
__exportStar(require("./iacSchema"), exports);
|