@geek-fun/serverlessinsight 0.2.0 → 0.3.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/dist/package.json +18 -12
- package/dist/src/commands/deploy.js +2 -2
- package/dist/src/commands/destroy.js +5 -3
- package/dist/src/commands/index.js +32 -5
- package/dist/src/commands/validate.js +2 -2
- package/dist/src/common/actionContext.js +14 -9
- package/dist/src/common/base64.js +3 -1
- package/dist/src/common/domainHelper.js +10 -0
- package/dist/src/common/iacHelper.js +1 -1
- package/dist/src/common/index.d.ts +2 -0
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/rosAssets.js +152 -0
- package/dist/src/common/rosClient.js +1 -53
- package/dist/src/parser/bucketParser.js +35 -0
- package/dist/src/parser/eventParser.js +1 -0
- package/dist/src/parser/functionParser.js +12 -3
- package/dist/src/parser/index.js +2 -0
- package/dist/src/stack/rfsStack/function.js +3 -3
- package/dist/src/stack/rosStack/bucket.js +126 -0
- package/dist/src/stack/rosStack/event.js +58 -51
- package/dist/src/stack/rosStack/function.js +152 -21
- package/dist/src/stack/rosStack/index.js +3 -0
- package/dist/src/types/domains/bucket.js +9 -0
- package/dist/src/types/domains/function.js +19 -0
- package/dist/src/types/index.d.ts +6 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/validator/bucketSchema.js +76 -0
- package/dist/src/validator/eventSchema.js +3 -7
- package/dist/src/validator/functionSchema.js +94 -18
- package/dist/src/validator/iacSchema.js +2 -0
- package/dist/src/validator/rootSchema.js +3 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -12
- package/samples/{aliyun-poc-fc.yml → aliyun-poc-api.yml} +9 -20
- package/samples/aliyun-poc-bucket.yml +20 -0
- package/samples/aliyun-poc-domain.yml +23 -0
- package/samples/aliyun-poc-fc-gpu.yml +54 -0
- package/samples/huawei-poc-fc.yml +4 -3
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -51,25 +51,31 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/ims20190815": "^2.1.4",
|
|
53
53
|
"@alicloud/openapi-client": "^0.4.12",
|
|
54
|
-
"@alicloud/ros-cdk-apigateway": "^1.
|
|
55
|
-
"@alicloud/ros-cdk-core": "^1.
|
|
56
|
-
"@alicloud/ros-cdk-
|
|
57
|
-
"@alicloud/ros-cdk-
|
|
58
|
-
"@alicloud/ros-cdk-
|
|
59
|
-
"@alicloud/ros-cdk-
|
|
60
|
-
"@alicloud/ros-cdk-
|
|
61
|
-
"@alicloud/ros-cdk-
|
|
62
|
-
"@alicloud/ros-cdk-
|
|
54
|
+
"@alicloud/ros-cdk-apigateway": "^1.6.0",
|
|
55
|
+
"@alicloud/ros-cdk-core": "^1.6.0",
|
|
56
|
+
"@alicloud/ros-cdk-dns": "^1.6.0",
|
|
57
|
+
"@alicloud/ros-cdk-ecs": "^1.6.0",
|
|
58
|
+
"@alicloud/ros-cdk-elasticsearchserverless": "^1.6.0",
|
|
59
|
+
"@alicloud/ros-cdk-fc3": "^1.6.0",
|
|
60
|
+
"@alicloud/ros-cdk-nas": "^1.6.0",
|
|
61
|
+
"@alicloud/ros-cdk-oss": "^1.6.0",
|
|
62
|
+
"@alicloud/ros-cdk-ossdeployment": "^1.6.0",
|
|
63
|
+
"@alicloud/ros-cdk-ram": "^1.6.0",
|
|
64
|
+
"@alicloud/ros-cdk-rds": "^1.6.0",
|
|
65
|
+
"@alicloud/ros-cdk-sls": "^1.6.0",
|
|
63
66
|
"@alicloud/ros20190910": "^3.5.2",
|
|
64
67
|
"ajv": "^8.17.1",
|
|
65
68
|
"ali-oss": "^6.22.0",
|
|
66
|
-
"chalk": "^5.
|
|
69
|
+
"chalk": "^5.4.1",
|
|
67
70
|
"commander": "^12.1.0",
|
|
71
|
+
"i": "^0.3.7",
|
|
68
72
|
"i18n": "^0.15.1",
|
|
73
|
+
"jszip": "^3.10.1",
|
|
69
74
|
"lodash": "^4.17.21",
|
|
75
|
+
"npm": "^11.1.0",
|
|
70
76
|
"pino": "^9.5.0",
|
|
71
77
|
"pino-pretty": "^13.0.0",
|
|
72
|
-
"yaml": "^2.
|
|
78
|
+
"yaml": "^2.7.0"
|
|
73
79
|
},
|
|
74
80
|
"devDependencies": {
|
|
75
81
|
"@types/ali-oss": "^6.16.11",
|
|
@@ -5,10 +5,10 @@ const stack_1 = require("../stack");
|
|
|
5
5
|
const common_1 = require("../common");
|
|
6
6
|
const parser_1 = require("../parser");
|
|
7
7
|
const deploy = async (stackName, options) => {
|
|
8
|
-
const context = (0, common_1.constructActionContext)({ ...options, stackName });
|
|
9
8
|
common_1.logger.info('Validating yaml...');
|
|
10
|
-
const iac = (0, parser_1.parseYaml)(
|
|
9
|
+
const iac = (0, parser_1.parseYaml)((0, common_1.getIacLocation)(options.location));
|
|
11
10
|
common_1.logger.info('Yaml is valid! 🎉');
|
|
11
|
+
const context = (0, common_1.constructActionContext)({ ...options, stackName, iacProvider: iac.provider });
|
|
12
12
|
common_1.logger.info('Deploying stack...');
|
|
13
13
|
await (0, stack_1.deployStack)(stackName, iac, context);
|
|
14
14
|
common_1.logger.info('Stack deployed! 🎉');
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.destroyStack = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const parser_1 = require("../parser");
|
|
6
|
+
const destroyStack = async (stackName, options) => {
|
|
7
|
+
const iac = (0, parser_1.parseYaml)((0, common_1.getIacLocation)(options.location));
|
|
8
|
+
const context = (0, common_1.constructActionContext)({ stackName, ...options, iacProvider: iac.provider });
|
|
9
|
+
common_1.logger.info(`Destroying stack: ${stackName}, provider: ${context.provider}, region: ${context.region}...`);
|
|
8
10
|
await (0, common_1.rosStackDelete)(context);
|
|
9
11
|
};
|
|
10
12
|
exports.destroyStack = destroyStack;
|
|
@@ -25,20 +25,34 @@ program
|
|
|
25
25
|
.option('-s, --stage <stage>', 'specify the stage')
|
|
26
26
|
.action((stackName, { file, stage }) => {
|
|
27
27
|
common_1.logger.debug('log command info');
|
|
28
|
-
(0, validate_1.validate)(
|
|
28
|
+
(0, validate_1.validate)(stackName, { stage, location: file });
|
|
29
29
|
});
|
|
30
30
|
program
|
|
31
31
|
.command('deploy <stackName>')
|
|
32
32
|
.description('deploy serverless Iac yaml')
|
|
33
33
|
.option('-f, --file <path>', 'specify the yaml file')
|
|
34
34
|
.option('-s, --stage <stage>', 'specify the stage')
|
|
35
|
+
.option('-r, --region <region>', 'specify the region')
|
|
36
|
+
.option('-pr, --provider <provider>', 'specify the provider')
|
|
37
|
+
.option('-ak, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
|
|
38
|
+
.option('-as, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
|
|
39
|
+
.option('-at, --securityToken <securityToken>', 'specify the SecurityToken')
|
|
35
40
|
.option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
|
|
36
41
|
const [key, val] = value.split('=');
|
|
37
42
|
previous[key] = val;
|
|
38
43
|
return previous;
|
|
39
44
|
}, {})
|
|
40
|
-
.action(async (stackName, {
|
|
41
|
-
await (0, deploy_1.deploy)(stackName, {
|
|
45
|
+
.action(async (stackName, { stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
|
|
46
|
+
await (0, deploy_1.deploy)(stackName, {
|
|
47
|
+
stage,
|
|
48
|
+
parameters: parameter,
|
|
49
|
+
location: file,
|
|
50
|
+
region,
|
|
51
|
+
provider,
|
|
52
|
+
accessKeyId,
|
|
53
|
+
accessKeySecret,
|
|
54
|
+
securityToken,
|
|
55
|
+
});
|
|
42
56
|
});
|
|
43
57
|
program
|
|
44
58
|
.command('template <stackName>')
|
|
@@ -51,8 +65,21 @@ program
|
|
|
51
65
|
});
|
|
52
66
|
program
|
|
53
67
|
.command('destroy <stackName>')
|
|
68
|
+
.option('-f, --file <path>', 'specify the yaml file')
|
|
69
|
+
.option('-r, --region <region>', 'specify the region')
|
|
70
|
+
.option('-pr, --provider <provider>', 'specify the provider')
|
|
71
|
+
.option('-ak, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
|
|
72
|
+
.option('-as, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
|
|
73
|
+
.option('-at, --securityToken <securityToken>', 'specify the SecurityToken')
|
|
54
74
|
.description('destroy serverless stack')
|
|
55
|
-
.action(async (stackName) => {
|
|
56
|
-
await (0, destroy_1.destroyStack)(stackName
|
|
75
|
+
.action(async (stackName, { file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
|
|
76
|
+
await (0, destroy_1.destroyStack)(stackName, {
|
|
77
|
+
location: file,
|
|
78
|
+
region,
|
|
79
|
+
provider,
|
|
80
|
+
accessKeyId,
|
|
81
|
+
accessKeySecret,
|
|
82
|
+
securityToken,
|
|
83
|
+
});
|
|
57
84
|
});
|
|
58
85
|
program.parse();
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validate = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
5
|
const parser_1 = require("../parser");
|
|
6
|
-
const validate = (
|
|
7
|
-
const context = (0, common_1.constructActionContext)({
|
|
6
|
+
const validate = (stackName, options) => {
|
|
7
|
+
const context = (0, common_1.constructActionContext)({ stackName, ...options });
|
|
8
8
|
(0, parser_1.parseYaml)(context.iacLocation);
|
|
9
9
|
common_1.logger.info('Yaml is valid! 🎉');
|
|
10
10
|
};
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.constructActionContext = exports.getIacLocation = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const providerEnum_1 = require("./providerEnum");
|
|
8
9
|
const getIacLocation = (location) => {
|
|
9
10
|
const projectRoot = node_path_1.default.resolve(process.cwd());
|
|
10
11
|
return location
|
|
@@ -17,15 +18,19 @@ const getIacLocation = (location) => {
|
|
|
17
18
|
exports.getIacLocation = getIacLocation;
|
|
18
19
|
const constructActionContext = (config) => {
|
|
19
20
|
return {
|
|
20
|
-
stage: config
|
|
21
|
-
stackName: config
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
stage: config.stage ?? 'default',
|
|
22
|
+
stackName: config.stackName ?? '',
|
|
23
|
+
provider: (config.provider ?? config.iacProvider?.name ?? providerEnum_1.ProviderEnum.ALIYUN),
|
|
24
|
+
region: config.region ??
|
|
25
|
+
config.iacProvider?.region ??
|
|
26
|
+
process.env.ROS_REGION_ID ??
|
|
27
|
+
process.env.ALIYUN_REGION ??
|
|
28
|
+
'cn-hangzhou',
|
|
29
|
+
accessKeyId: config.accessKeyId ?? process.env.ALIYUN_ACCESS_KEY_ID,
|
|
30
|
+
accessKeySecret: config.accessKeySecret ?? process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
31
|
+
securityToken: config.securityToken ?? process.env.ALIYUN_SECURITY_TOKEN,
|
|
32
|
+
iacLocation: (0, exports.getIacLocation)(config.location),
|
|
33
|
+
parameters: Object.entries(config.parameters ?? {}).map(([key, value]) => ({ key, value })),
|
|
29
34
|
};
|
|
30
35
|
};
|
|
31
36
|
exports.constructActionContext = constructActionContext;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeBase64 = void 0;
|
|
3
|
+
exports.encodeBase64ForRosId = exports.encodeBase64 = void 0;
|
|
4
4
|
const encodeBase64 = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
5
5
|
exports.encodeBase64 = encodeBase64;
|
|
6
|
+
const encodeBase64ForRosId = (str) => (0, exports.encodeBase64)(str).replace(/=+$/, '');
|
|
7
|
+
exports.encodeBase64ForRosId = encodeBase64ForRosId;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitDomain = void 0;
|
|
4
|
+
const splitDomain = (domain) => {
|
|
5
|
+
const parts = domain.split('.');
|
|
6
|
+
const rr = parts.length > 2 ? parts[0] : '@';
|
|
7
|
+
const domainName = parts.length > 2 ? parts.slice(1).join('.') : domain;
|
|
8
|
+
return { rr, domainName };
|
|
9
|
+
};
|
|
10
|
+
exports.splitDomain = splitDomain;
|
|
@@ -61,7 +61,7 @@ const getFileSource = (fcName, location) => {
|
|
|
61
61
|
}
|
|
62
62
|
const hash = node_crypto_1.default.createHash('md5').update(node_fs_1.default.readFileSync(filePath)).digest('hex');
|
|
63
63
|
const objectKey = `${fcName}/${hash}-${filePath.split('/').pop()}`;
|
|
64
|
-
const source = ossDeployment.Source.asset(filePath, {}, `${fcName}/${hash}-`);
|
|
64
|
+
const source = ossDeployment.Source.asset(filePath, { deployTime: true }, `${fcName}/${hash}-`);
|
|
65
65
|
return { source, objectKey };
|
|
66
66
|
};
|
|
67
67
|
exports.getFileSource = getFileSource;
|
package/dist/src/common/index.js
CHANGED
|
@@ -23,3 +23,5 @@ __exportStar(require("./iacHelper"), exports);
|
|
|
23
23
|
__exportStar(require("./constants"), exports);
|
|
24
24
|
__exportStar(require("./imsClient"), exports);
|
|
25
25
|
__exportStar(require("./base64"), exports);
|
|
26
|
+
__exportStar(require("./rosAssets"), exports);
|
|
27
|
+
__exportStar(require("./domainHelper"), exports);
|
|
@@ -0,0 +1,152 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.publishAssets = exports.getAssets = void 0;
|
|
40
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
|
+
const ossDeployment = __importStar(require("@alicloud/ros-cdk-ossdeployment"));
|
|
42
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
44
|
+
const logger_1 = require("./logger");
|
|
45
|
+
const lodash_1 = require("lodash");
|
|
46
|
+
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
47
|
+
const buildAssets = (rootPath, relativePath) => {
|
|
48
|
+
const location = node_path_1.default.resolve(rootPath, relativePath);
|
|
49
|
+
if (!node_fs_1.default.existsSync(location)) {
|
|
50
|
+
throw new Error(`Location: ${location} is not exists!`);
|
|
51
|
+
}
|
|
52
|
+
if (node_fs_1.default.lstatSync(location).isFile()) {
|
|
53
|
+
return [
|
|
54
|
+
ossDeployment.Source.asset(location, {}, relativePath.substring(0, relativePath.lastIndexOf('/') + 1)),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
return node_fs_1.default
|
|
58
|
+
.readdirSync(location)
|
|
59
|
+
.map((file) => buildAssets(rootPath, `${relativePath}/${file}`.replace(/^\//, '')))
|
|
60
|
+
.flat();
|
|
61
|
+
};
|
|
62
|
+
const getAssets = (location) => {
|
|
63
|
+
return buildAssets(location, '');
|
|
64
|
+
};
|
|
65
|
+
exports.getAssets = getAssets;
|
|
66
|
+
const assembleFiles = (folder, zip) => {
|
|
67
|
+
const files = node_fs_1.default.readdirSync(folder);
|
|
68
|
+
files.forEach((file) => {
|
|
69
|
+
const filePath = node_path_1.default.join(folder, file);
|
|
70
|
+
if (node_fs_1.default.lstatSync(filePath).isFile()) {
|
|
71
|
+
const content = node_fs_1.default.readFileSync(filePath);
|
|
72
|
+
zip.file(file, content);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const subZip = zip.folder(file);
|
|
76
|
+
if (subZip) {
|
|
77
|
+
assembleFiles(filePath, subZip);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const zipAssets = async (assetsPath) => {
|
|
83
|
+
const zip = new jszip_1.default();
|
|
84
|
+
assembleFiles(assetsPath, zip);
|
|
85
|
+
const zipPath = `${assetsPath.replace(/\/$/, '').trim()}.zip`;
|
|
86
|
+
await zip
|
|
87
|
+
.generateAsync({ type: 'nodebuffer' })
|
|
88
|
+
.then((content) => {
|
|
89
|
+
node_fs_1.default.writeFileSync(zipPath, content);
|
|
90
|
+
logger_1.logger.info(`Folder compressed to: ${zipPath}`);
|
|
91
|
+
})
|
|
92
|
+
.catch((e) => {
|
|
93
|
+
logger_1.logger.error(`Failed to compress folder: ${e}`);
|
|
94
|
+
throw e;
|
|
95
|
+
});
|
|
96
|
+
return zipPath;
|
|
97
|
+
};
|
|
98
|
+
const constructAssets = async ({ files, rootPath }, region) => {
|
|
99
|
+
const assets = await Promise.all(Object.entries(files)
|
|
100
|
+
.filter(([, fileItem]) => !fileItem.source.path.endsWith('.template.json'))
|
|
101
|
+
.map(async ([, fileItem]) => {
|
|
102
|
+
let sourcePath = `${rootPath}/${fileItem.source.path}`;
|
|
103
|
+
if (fileItem.source.packaging === 'zip') {
|
|
104
|
+
sourcePath = await zipAssets(`${rootPath}/${fileItem.source.path}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
bucketName: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.bucketName', '').replace('${ALIYUN::Region}', region),
|
|
108
|
+
source: sourcePath,
|
|
109
|
+
objectKey: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.objectKey'),
|
|
110
|
+
};
|
|
111
|
+
}));
|
|
112
|
+
return !(0, lodash_1.isEmpty)(assets) ? assets : undefined;
|
|
113
|
+
};
|
|
114
|
+
const ensureBucketExits = async (bucketName, ossClient) => await ossClient.getBucketInfo(bucketName).catch((err) => {
|
|
115
|
+
if (err.code === 'NoSuchBucket') {
|
|
116
|
+
logger_1.logger.info(`Bucket: ${bucketName} not exists, creating...`);
|
|
117
|
+
return ossClient.putBucket(bucketName, {
|
|
118
|
+
storageClass: 'Standard',
|
|
119
|
+
acl: 'private',
|
|
120
|
+
dataRedundancyType: 'LRS',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const publishAssets = async (assets, context) => {
|
|
128
|
+
const constructedAssets = await constructAssets(assets, context.region);
|
|
129
|
+
if (!constructedAssets?.length) {
|
|
130
|
+
logger_1.logger.info('No assets to publish, skipped!');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const bucketName = constructedAssets[0].bucketName;
|
|
134
|
+
const client = new ali_oss_1.default({
|
|
135
|
+
region: `oss-${context.region}`,
|
|
136
|
+
accessKeyId: context.accessKeyId,
|
|
137
|
+
accessKeySecret: context.accessKeySecret,
|
|
138
|
+
bucket: bucketName,
|
|
139
|
+
});
|
|
140
|
+
await ensureBucketExits(bucketName, client);
|
|
141
|
+
const headers = {
|
|
142
|
+
'x-oss-storage-class': 'Standard',
|
|
143
|
+
'x-oss-object-acl': 'default',
|
|
144
|
+
'x-oss-forbid-overwrite': 'false',
|
|
145
|
+
};
|
|
146
|
+
await Promise.all(constructedAssets.map(async ({ source, objectKey }) => {
|
|
147
|
+
await client.put(objectKey, node_path_1.default.normalize(source), { headers });
|
|
148
|
+
logger_1.logger.info(`Upload file: ${source}) to bucket: ${bucketName} successfully!`);
|
|
149
|
+
}));
|
|
150
|
+
return bucketName;
|
|
151
|
+
};
|
|
152
|
+
exports.publishAssets = publishAssets;
|
|
@@ -36,15 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.rosStackDelete = exports.rosStackDeploy = void 0;
|
|
40
40
|
const tea_util_1 = __importDefault(require("@alicloud/tea-util"));
|
|
41
41
|
const ros20190910_1 = __importStar(require("@alicloud/ros20190910"));
|
|
42
42
|
const openapi_client_1 = require("@alicloud/openapi-client");
|
|
43
|
-
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
44
43
|
const logger_1 = require("./logger");
|
|
45
44
|
const lang_1 = require("../lang");
|
|
46
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
47
|
-
const lodash_1 = require("lodash");
|
|
48
45
|
const client = new ros20190910_1.default(new openapi_client_1.Config({
|
|
49
46
|
accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
|
|
50
47
|
accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
@@ -197,52 +194,3 @@ const rosStackDelete = async ({ stackName, region, }) => {
|
|
|
197
194
|
}
|
|
198
195
|
};
|
|
199
196
|
exports.rosStackDelete = rosStackDelete;
|
|
200
|
-
const ensureBucketExits = async (bucketName, ossClient) => await ossClient.getBucketInfo(bucketName).catch((err) => {
|
|
201
|
-
if (err.code === 'NoSuchBucket') {
|
|
202
|
-
logger_1.logger.info(`Bucket: ${bucketName} not exists, creating...`);
|
|
203
|
-
return ossClient.putBucket(bucketName, {
|
|
204
|
-
storageClass: 'Standard',
|
|
205
|
-
acl: 'private',
|
|
206
|
-
dataRedundancyType: 'LRS',
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
const getZipAssets = ({ files, rootPath }, region) => {
|
|
214
|
-
const zipAssets = Object.entries(files)
|
|
215
|
-
.filter(([, fileItem]) => fileItem.source.path.endsWith('zip'))
|
|
216
|
-
.map(([, fileItem]) => ({
|
|
217
|
-
bucketName: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.bucketName', '').replace('${ALIYUN::Region}', region),
|
|
218
|
-
source: `${rootPath}/${fileItem.source.path}`,
|
|
219
|
-
objectKey: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.objectKey'),
|
|
220
|
-
}));
|
|
221
|
-
return !(0, lodash_1.isEmpty)(zipAssets) ? zipAssets : undefined;
|
|
222
|
-
};
|
|
223
|
-
const publishAssets = async (assets, context) => {
|
|
224
|
-
const zipAssets = getZipAssets(assets, context.region);
|
|
225
|
-
if (!zipAssets) {
|
|
226
|
-
logger_1.logger.info('No assets to publish, skipped!');
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const bucketName = zipAssets[0].bucketName;
|
|
230
|
-
const client = new ali_oss_1.default({
|
|
231
|
-
region: `oss-${context.region}`,
|
|
232
|
-
accessKeyId: context.accessKeyId,
|
|
233
|
-
accessKeySecret: context.accessKeySecret,
|
|
234
|
-
bucket: bucketName,
|
|
235
|
-
});
|
|
236
|
-
await ensureBucketExits(bucketName, client);
|
|
237
|
-
const headers = {
|
|
238
|
-
'x-oss-storage-class': 'Standard',
|
|
239
|
-
'x-oss-object-acl': 'private',
|
|
240
|
-
'x-oss-forbid-overwrite': 'false',
|
|
241
|
-
};
|
|
242
|
-
await Promise.all(zipAssets.map(async ({ source, objectKey }) => {
|
|
243
|
-
await client.put(objectKey, node_path_1.default.normalize(source), { headers });
|
|
244
|
-
logger_1.logger.info(`Upload file: ${source}) to bucket: ${bucketName} successfully!`);
|
|
245
|
-
}));
|
|
246
|
-
return bucketName;
|
|
247
|
-
};
|
|
248
|
-
exports.publishAssets = publishAssets;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBucket = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const parseBucket = (buckets) => {
|
|
6
|
+
if (!buckets) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return Object.entries(buckets).map(([key, bucket]) => ({
|
|
10
|
+
key,
|
|
11
|
+
name: bucket.name,
|
|
12
|
+
storage: bucket.storage,
|
|
13
|
+
versioning: bucket.versioning,
|
|
14
|
+
security: bucket.security
|
|
15
|
+
? {
|
|
16
|
+
acl: bucket.security.acl
|
|
17
|
+
? bucket.security.acl
|
|
18
|
+
: types_1.BucketAccessEnum.PRIVATE,
|
|
19
|
+
force_delete: bucket.security.force_delete ?? false,
|
|
20
|
+
sse_algorithm: bucket.security.sse_algorithm,
|
|
21
|
+
sse_kms_master_key_id: bucket.security.sse_kms_master_key_id,
|
|
22
|
+
}
|
|
23
|
+
: undefined,
|
|
24
|
+
website: bucket.website
|
|
25
|
+
? {
|
|
26
|
+
code: bucket.website.code,
|
|
27
|
+
domain: bucket.website.domain,
|
|
28
|
+
index: bucket.website.index ?? 'index.html',
|
|
29
|
+
error_page: bucket.website.error_page ?? '404.html',
|
|
30
|
+
error_code: bucket.website.error_code ?? 404,
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
exports.parseBucket = parseBucket;
|
|
@@ -9,12 +9,21 @@ const parseFunction = (functions) => {
|
|
|
9
9
|
return Object.entries(functions).map(([key, func]) => ({
|
|
10
10
|
key,
|
|
11
11
|
name: func.name,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
code: func.code,
|
|
13
|
+
container: func.container,
|
|
14
14
|
memory: func.memory,
|
|
15
|
+
gpu: func.gpu,
|
|
15
16
|
timeout: func.timeout,
|
|
16
17
|
environment: func.environment,
|
|
17
|
-
|
|
18
|
+
log: func.log,
|
|
19
|
+
network: func.network,
|
|
20
|
+
storage: {
|
|
21
|
+
disk: func.storage?.disk,
|
|
22
|
+
nas: func.storage?.nas?.map((nasItem) => ({
|
|
23
|
+
mount_path: nasItem.mount_path,
|
|
24
|
+
storage_class: nasItem.storage_class,
|
|
25
|
+
})),
|
|
26
|
+
},
|
|
18
27
|
}));
|
|
19
28
|
};
|
|
20
29
|
exports.parseFunction = parseFunction;
|
package/dist/src/parser/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const databaseParser_1 = require("./databaseParser");
|
|
|
8
8
|
const tagParser_1 = require("./tagParser");
|
|
9
9
|
const yaml_1 = require("yaml");
|
|
10
10
|
const validator_1 = require("../validator");
|
|
11
|
+
const bucketParser_1 = require("./bucketParser");
|
|
11
12
|
const validateExistence = (path) => {
|
|
12
13
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
13
14
|
throw new Error(`File does not exist at path: ${path}`);
|
|
@@ -24,6 +25,7 @@ const transformYaml = (iacJson) => {
|
|
|
24
25
|
events: (0, eventParser_1.parseEvent)(iacJson.events),
|
|
25
26
|
databases: (0, databaseParser_1.parseDatabase)(iacJson.databases),
|
|
26
27
|
tags: (0, tagParser_1.parseTag)(iacJson.tags),
|
|
28
|
+
buckets: (0, bucketParser_1.parseBucket)(iacJson.buckets),
|
|
27
29
|
};
|
|
28
30
|
};
|
|
29
31
|
const parseYaml = (iacLocation) => {
|
|
@@ -12,13 +12,13 @@ resource "huaweicloud_fgs_application" "${service}_app" {
|
|
|
12
12
|
const fgsFunction = (fn, context, service) => `
|
|
13
13
|
resource "huaweicloud_fgs_function" "${fn.key}" {
|
|
14
14
|
name = "${fn.name}"
|
|
15
|
-
handler = "${fn.handler}"
|
|
16
|
-
runtime = "${fn.runtime}"
|
|
15
|
+
handler = "${fn.code.handler}"
|
|
16
|
+
runtime = "${fn.code.runtime}"
|
|
17
17
|
memory_size = ${fn.memory}
|
|
18
18
|
timeout = ${fn.timeout}
|
|
19
19
|
environment = ${JSON.stringify(fn.environment)}
|
|
20
20
|
code_type = "inline"
|
|
21
|
-
func_code = "${(0, common_1.resolveCode)(fn.code)}"
|
|
21
|
+
func_code = "${(0, common_1.resolveCode)(fn.code.path)}"
|
|
22
22
|
app = "huaweicloud_fgs_application.${service}_app.id"
|
|
23
23
|
}
|
|
24
24
|
`;
|