@geek-fun/serverlessinsight 0.2.1 → 0.3.1

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.
Files changed (50) hide show
  1. package/dist/package.json +35 -28
  2. package/dist/src/commands/deploy.js +3 -3
  3. package/dist/src/commands/destroy.js +6 -3
  4. package/dist/src/commands/index.js +35 -7
  5. package/dist/src/commands/template.js +2 -2
  6. package/dist/src/commands/validate.js +3 -2
  7. package/dist/src/common/base64.js +3 -1
  8. package/dist/src/common/constants.js +2 -1
  9. package/dist/src/common/context.js +51 -0
  10. package/dist/src/common/domainHelper.js +10 -0
  11. package/dist/src/common/iacHelper.js +55 -28
  12. package/dist/src/common/index.d.ts +3 -1
  13. package/dist/src/common/index.js +3 -1
  14. package/dist/src/common/rosAssets.js +177 -0
  15. package/dist/src/common/rosClient.js +6 -56
  16. package/dist/src/parser/bucketParser.js +35 -0
  17. package/dist/src/parser/eventParser.js +1 -0
  18. package/dist/src/parser/functionParser.js +11 -3
  19. package/dist/src/parser/index.js +2 -0
  20. package/dist/src/stack/deploy.js +30 -13
  21. package/dist/src/stack/rfsStack/function.js +3 -3
  22. package/dist/src/stack/rfsStack/index.d.ts +2 -2
  23. package/dist/src/stack/rfsStack/index.js +2 -1
  24. package/dist/src/stack/rosStack/bootstrap.js +5 -4
  25. package/dist/src/stack/rosStack/bucket.js +126 -0
  26. package/dist/src/stack/rosStack/database.js +10 -10
  27. package/dist/src/stack/rosStack/event.js +62 -55
  28. package/dist/src/stack/rosStack/function.js +175 -30
  29. package/dist/src/stack/rosStack/index.d.ts +2 -2
  30. package/dist/src/stack/rosStack/index.js +6 -3
  31. package/dist/src/stack/rosStack/stage.js +1 -1
  32. package/dist/src/stack/rosStack/tag.js +1 -1
  33. package/dist/src/stack/rosStack/vars.js +3 -3
  34. package/dist/src/types/domains/bucket.js +9 -0
  35. package/dist/src/types/domains/function.js +19 -0
  36. package/dist/src/types/index.d.ts +6 -0
  37. package/dist/src/types/index.js +1 -0
  38. package/dist/src/validator/bucketSchema.js +76 -0
  39. package/dist/src/validator/eventSchema.js +3 -7
  40. package/dist/src/validator/functionSchema.js +93 -19
  41. package/dist/src/validator/iacSchema.js +2 -0
  42. package/dist/src/validator/rootSchema.js +3 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +35 -28
  45. package/samples/{aliyun-poc-fc.yml → aliyun-poc-api.yml} +9 -20
  46. package/samples/aliyun-poc-bucket.yml +20 -0
  47. package/samples/aliyun-poc-domain.yml +23 -0
  48. package/samples/aliyun-poc-fc-gpu.yml +55 -0
  49. package/samples/huawei-poc-fc.yml +4 -3
  50. package/dist/src/common/actionContext.js +0 -31
@@ -39,15 +39,18 @@ const ram = __importStar(require("@alicloud/ros-cdk-ram"));
39
39
  const common_1 = require("../../common");
40
40
  const agw = __importStar(require("@alicloud/ros-cdk-apigateway"));
41
41
  const lodash_1 = require("lodash");
42
+ const dns = __importStar(require("@alicloud/ros-cdk-dns"));
42
43
  const resolveEvents = (scope, events, tags, context, service) => {
43
44
  if ((0, lodash_1.isEmpty)(events)) {
44
45
  return undefined;
45
46
  }
46
47
  const apiGateway = events.filter((event) => event.type === types_1.EventTypes.API_GATEWAY);
47
- if (apiGateway?.length) {
48
- const gatewayAccessRole = new ram.RosRole(scope, (0, common_1.replaceReference)(`${service}_role`, context), {
49
- roleName: (0, common_1.replaceReference)(`${service}-gateway-access-role`, context),
50
- description: (0, common_1.replaceReference)(`${service} role`, context),
48
+ if (!apiGateway?.length)
49
+ return;
50
+ apiGateway.forEach((event) => {
51
+ const gatewayAccessRole = new ram.RosRole(scope, (0, common_1.formatRosId)(`${event.key}_agw_role`), {
52
+ roleName: (0, common_1.calcRefs)(`${event.name}-agw-access-role`, context),
53
+ description: (0, common_1.calcRefs)(`${service} role`, context),
51
54
  assumeRolePolicyDocument: {
52
55
  version: '1',
53
56
  statement: [
@@ -62,7 +65,7 @@ const resolveEvents = (scope, events, tags, context, service) => {
62
65
  },
63
66
  policies: [
64
67
  {
65
- policyName: (0, common_1.replaceReference)(`${service}-policy`, context),
68
+ policyName: (0, common_1.calcRefs)(`${service}-${event.name}-policy`, context),
66
69
  policyDocument: {
67
70
  version: '1',
68
71
  statement: [
@@ -77,60 +80,64 @@ const resolveEvents = (scope, events, tags, context, service) => {
77
80
  },
78
81
  ],
79
82
  }, true);
80
- const apiGatewayGroup = new agw.RosGroup(scope, (0, common_1.replaceReference)(`${service}_apigroup`, context), {
81
- groupName: (0, common_1.replaceReference)(`${service}_apigroup`, context),
82
- tags: (0, common_1.replaceReference)(tags, context),
83
+ const apiGatewayGroup = new agw.RosGroup(scope, (0, common_1.formatRosId)(`${event.key}_agw_group`), {
84
+ groupName: (0, common_1.calcRefs)(`${service}-agw-group`, context),
85
+ tags: (0, common_1.calcRefs)(tags, context),
83
86
  passthroughHeaders: 'host',
84
87
  }, true);
85
- // new agw.RosCustomDomain(
86
- // this,
87
- // 'customDomain',
88
- // {
89
- // domainName: 'example.com',
90
- // certificateName: 'example.com',
91
- // certificateBody: 'example.com',
92
- // certificatePrivateKey: 'example.com',
93
- // groupId: apiGatewayGroup.attrGroupId,
94
- // },
95
- // true,
96
- // );
97
- apiGateway.forEach((event) => {
98
- event.triggers.forEach((trigger) => {
99
- const key = (0, common_1.encodeBase64)((0, common_1.replaceReference)(`${trigger.method}_${trigger.path}`, context)).replace(/=+$/, '');
100
- const api = new agw.RosApi(scope, `${event.key}_api_${key}`, {
101
- apiName: (0, common_1.replaceReference)(`${event.name}_api_${key}`, context),
102
- groupId: apiGatewayGroup.attrGroupId,
103
- visibility: 'PRIVATE',
104
- authType: 'ANONYMOUS',
105
- requestConfig: {
106
- requestProtocol: 'HTTP',
107
- requestHttpMethod: (0, common_1.replaceReference)(trigger.method, context),
108
- requestPath: (0, common_1.replaceReference)(trigger.path, context),
109
- requestMode: 'PASSTHROUGH',
110
- },
111
- serviceConfig: {
112
- serviceProtocol: 'FunctionCompute',
113
- functionComputeConfig: {
114
- fcRegionId: context.region,
115
- functionName: (0, common_1.replaceReference)(trigger.backend, context),
116
- roleArn: gatewayAccessRole.attrArn,
117
- fcVersion: '3.0',
118
- method: (0, common_1.replaceReference)(trigger.method, context),
119
- },
88
+ if (event.domain) {
89
+ const dnsRecordId = (0, common_1.formatRosId)(`${event.key}_agw_custom_domain_record`);
90
+ const { domainName, rr } = (0, common_1.splitDomain)(event.domain?.domain_name);
91
+ new dns.DomainRecord(scope, dnsRecordId, {
92
+ domainName,
93
+ rr,
94
+ type: 'CNAME',
95
+ value: apiGatewayGroup.attrSubDomain,
96
+ });
97
+ const agwCustomDomain = new agw.RosCustomDomain(scope, (0, common_1.formatRosId)(`${event.key}_agw_custom_domain`), {
98
+ groupId: apiGatewayGroup.attrGroupId,
99
+ domainName: event.domain.domain_name,
100
+ certificateName: event.domain.certificate_name,
101
+ certificateBody: event.domain.certificate_body,
102
+ certificatePrivateKey: event.domain.certificate_private_key,
103
+ }, true);
104
+ agwCustomDomain.addRosDependency(dnsRecordId);
105
+ }
106
+ event.triggers.forEach((trigger) => {
107
+ const key = (0, common_1.formatRosId)((0, common_1.calcValue)(`${trigger.method}_${trigger.path}`, context));
108
+ const api = new agw.RosApi(scope, (0, common_1.formatRosId)(`${event.key}_agw_api_${key}`), {
109
+ apiName: (0, common_1.calcRefs)(`${event.name}-agw-api-${key.replace(/_/g, '-')}`, context),
110
+ groupId: apiGatewayGroup.attrGroupId,
111
+ visibility: 'PRIVATE',
112
+ authType: 'ANONYMOUS',
113
+ requestConfig: {
114
+ requestProtocol: 'HTTP',
115
+ requestHttpMethod: (0, common_1.calcRefs)(trigger.method, context),
116
+ requestPath: (0, common_1.calcRefs)(trigger.path, context),
117
+ requestMode: 'PASSTHROUGH',
118
+ },
119
+ serviceConfig: {
120
+ serviceProtocol: 'FunctionCompute',
121
+ functionComputeConfig: {
122
+ fcRegionId: context.region,
123
+ functionName: (0, common_1.calcRefs)(trigger.backend, context),
124
+ roleArn: gatewayAccessRole.attrArn,
125
+ fcVersion: '3.0',
126
+ method: (0, common_1.calcRefs)(trigger.method, context),
120
127
  },
121
- resultSample: 'ServerlessInsight resultSample',
122
- resultType: 'PASSTHROUGH',
123
- tags: (0, common_1.replaceReference)(tags, context),
124
- }, true);
125
- api.addDependsOn(apiGatewayGroup);
126
- new agw.Deployment(scope, `${service}_deployment`, {
127
- apiId: api.attrApiId,
128
- groupId: apiGatewayGroup.attrGroupId,
129
- stageName: 'RELEASE',
130
- description: `${service} Api Gateway deployment`,
131
- });
128
+ },
129
+ resultSample: 'ServerlessInsight resultSample',
130
+ resultType: 'PASSTHROUGH',
131
+ tags: (0, common_1.calcRefs)(tags, context),
132
+ }, true);
133
+ api.addDependsOn(apiGatewayGroup);
134
+ new agw.Deployment(scope, (0, common_1.formatRosId)(`${event.key}_agw_api_deployment_${key}`), {
135
+ apiId: api.attrApiId,
136
+ groupId: apiGatewayGroup.attrGroupId,
137
+ stageName: 'RELEASE',
138
+ description: (0, common_1.calcRefs)(`${service} Api Gateway deployment for api: ${trigger.method} ${trigger.path}`, context),
132
139
  });
133
140
  });
134
- }
141
+ });
135
142
  };
136
143
  exports.resolveEvents = resolveEvents;
@@ -34,26 +34,79 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.resolveFunctions = void 0;
37
+ const types_1 = require("../../types");
37
38
  const common_1 = require("../../common");
38
39
  const fc = __importStar(require("@alicloud/ros-cdk-fc3"));
39
40
  const lodash_1 = require("lodash");
40
41
  const ossDeployment = __importStar(require("@alicloud/ros-cdk-ossdeployment"));
41
42
  const ros = __importStar(require("@alicloud/ros-cdk-core"));
42
43
  const sls = __importStar(require("@alicloud/ros-cdk-sls"));
44
+ const nas = __importStar(require("@alicloud/ros-cdk-nas"));
45
+ const ecs = __importStar(require("@alicloud/ros-cdk-ecs"));
46
+ const vpc = __importStar(require("@alicloud/ros-cdk-vpc"));
47
+ const storageClassMap = {
48
+ [types_1.NasStorageClassEnum.STANDARD_CAPACITY]: { fileSystemType: 'standard', storageType: 'Capacity' },
49
+ [types_1.NasStorageClassEnum.STANDARD_PERFORMANCE]: {
50
+ fileSystemType: 'standard',
51
+ storageType: 'Performance',
52
+ },
53
+ [types_1.NasStorageClassEnum.EXTREME_STANDARD]: { fileSystemType: 'extreme', storageType: 'standard' },
54
+ [types_1.NasStorageClassEnum.EXTREME_ADVANCE]: { fileSystemType: 'extreme', storageType: 'advance' },
55
+ };
56
+ const securityGroupRangeMap = {
57
+ TCP: '1/65535',
58
+ UDP: '1/65535',
59
+ ICMP: '-1/-1',
60
+ GRE: '-1/-1',
61
+ ALL: '-1/-1',
62
+ };
63
+ const gpuConfigMap = {
64
+ [types_1.FunctionGpuEnum.TESLA_8]: { gpuMemorySize: 8192, gpuType: 'fc.gpu.tesla.1' },
65
+ [types_1.FunctionGpuEnum.TESLA_12]: { gpuMemorySize: 12288, gpuType: 'fc.gpu.tesla.1' },
66
+ [types_1.FunctionGpuEnum.TESLA_16]: { gpuMemorySize: 16384, gpuType: 'fc.gpu.tesla.1' },
67
+ [types_1.FunctionGpuEnum.AMPERE_8]: { gpuMemorySize: 8192, gpuType: 'fc.gpu.ampere.1' },
68
+ [types_1.FunctionGpuEnum.AMPERE_12]: { gpuMemorySize: 12288, gpuType: 'fc.gpu.ampere.1' },
69
+ [types_1.FunctionGpuEnum.AMPERE_16]: { gpuMemorySize: 16384, gpuType: 'fc.gpu.ampere.1' },
70
+ [types_1.FunctionGpuEnum.AMPERE_24]: { gpuMemorySize: 24576, gpuType: 'fc.gpu.ampere.1' },
71
+ [types_1.FunctionGpuEnum.ADA_48]: { gpuMemorySize: 49152, gpuType: 'fc.gpu.ada.1' },
72
+ };
73
+ const transformSecurityRules = (rules, ruleType) => {
74
+ return rules.map((rule) => {
75
+ const [protocol, cidrIp, portRange] = rule.split(':');
76
+ return {
77
+ ipProtocol: protocol.toLowerCase(),
78
+ portRange: portRange.toUpperCase() === 'ALL'
79
+ ? securityGroupRangeMap[protocol.toUpperCase()]
80
+ : portRange.includes('/')
81
+ ? portRange
82
+ : `${portRange}/${portRange}`,
83
+ [ruleType === 'INGRESS' ? 'sourceCidrIp' : 'destCidrIp']: cidrIp,
84
+ };
85
+ });
86
+ };
87
+ const transformGpuConfig = (gpu) => {
88
+ if (!gpu) {
89
+ return undefined;
90
+ }
91
+ return gpuConfigMap[gpu];
92
+ };
43
93
  const resolveFunctions = (scope, functions, tags, context, service) => {
44
94
  if ((0, lodash_1.isEmpty)(functions)) {
45
95
  return undefined;
46
96
  }
47
97
  let logConfig = undefined;
48
98
  const enableLog = functions?.some(({ log }) => log);
49
- const slsService = new sls.Project(scope, `${service}_sls`, { name: `${service}-sls`, tags: (0, common_1.replaceReference)(tags, context) }, true);
50
- const slsLogstore = new sls.Logstore(scope, `${service}_sls_logstore`, {
51
- logstoreName: `${service}-sls-logstore`,
52
- projectName: slsService.attrName,
99
+ const slsProjectId = 'sls_project';
100
+ const slsLogstoreId = 'sls_logstore';
101
+ const slsIndexId = 'sls_index';
102
+ const slsProject = new sls.Project(scope, slsProjectId, { name: (0, common_1.calcRefs)(`${service}-sls`, context), tags: (0, common_1.calcRefs)(tags, context) }, true);
103
+ const slsLogstore = new sls.Logstore(scope, slsLogstoreId, {
104
+ logstoreName: (0, common_1.calcRefs)(`${service}-sls-logstore`, context),
105
+ projectName: slsProject.attrName,
53
106
  ttl: 7,
54
107
  }, true);
55
- new sls.Index(scope, `${service}_sls_index`, {
56
- projectName: slsService.attrName,
108
+ new sls.Index(scope, slsIndexId, {
109
+ projectName: slsProject.attrName,
57
110
  logstoreName: slsLogstore.attrLogstoreName,
58
111
  fullTextIndex: { enable: true },
59
112
  }, true);
@@ -65,50 +118,142 @@ const resolveFunctions = (scope, functions, tags, context, service) => {
65
118
  };
66
119
  }
67
120
  const fileSources = functions
68
- ?.filter(({ code }) => (0, common_1.readCodeSize)(code) > common_1.CODE_ZIP_SIZE_LIMIT)
121
+ ?.filter(({ code }) => code?.path && (0, common_1.readCodeSize)(code.path) > common_1.CODE_ZIP_SIZE_LIMIT)
69
122
  .map(({ code, name }) => {
70
- const fcName = (0, common_1.replaceReference)(name, context);
71
- return { fcName, ...(0, common_1.getFileSource)(fcName, code) };
123
+ const fcName = (0, common_1.calcRefs)(name, context);
124
+ return { fcName, ...(0, common_1.getFileSource)(fcName, code.path) };
72
125
  });
73
126
  const destinationBucketName = ros.Fn.sub('si-bootstrap-artifacts-${ALIYUN::AccountId}-${ALIYUN::Region}');
74
- const ossDeploymentId = `${service}_artifacts_code_deployment`;
127
+ const ossDeploymentId = 'si_auto_artifacts_code_deployment';
75
128
  if (!(0, lodash_1.isEmpty)(fileSources)) {
76
129
  new ossDeployment.BucketDeployment(scope, ossDeploymentId, {
77
130
  sources: fileSources.map(({ source }) => source),
78
131
  destinationBucket: destinationBucketName,
79
- timeout: 3000,
132
+ timeout: common_1.OSS_DEPLOYMENT_TIMEOUT,
80
133
  logMonitoring: false,
81
134
  retainOnCreate: false,
82
135
  }, true);
83
136
  }
84
137
  functions?.forEach((fnc) => {
85
- const storeInBucket = (0, common_1.readCodeSize)(fnc.code) > common_1.CODE_ZIP_SIZE_LIMIT;
86
- let code = {
87
- zipFile: (0, common_1.resolveCode)(fnc.code),
88
- };
89
- if (storeInBucket) {
90
- code = {
91
- ossBucketName: destinationBucketName,
92
- ossObjectName: fileSources?.find(({ fcName }) => fcName === (0, common_1.replaceReference)(fnc.name, context))?.objectKey,
138
+ let runtimeConfig;
139
+ const storeInBucket = !!fnc.code?.path && (0, common_1.readCodeSize)((0, common_1.calcValue)(fnc.code.path, context)) > common_1.CODE_ZIP_SIZE_LIMIT;
140
+ if (fnc.container) {
141
+ runtimeConfig = {
142
+ runtime: 'custom-container',
143
+ handler: 'index.handler',
144
+ customContainerConfig: {
145
+ image: (0, common_1.calcRefs)(fnc.container.image, context),
146
+ command: (0, common_1.calcRefs)(fnc.container.cmd, context)?.split(' '),
147
+ port: (0, common_1.calcRefs)(fnc.container.port, context),
148
+ },
149
+ };
150
+ }
151
+ else {
152
+ let code = {
153
+ zipFile: (0, common_1.resolveCode)((0, common_1.calcValue)(fnc.code.path, context)),
154
+ };
155
+ if (storeInBucket) {
156
+ code = {
157
+ ossBucketName: destinationBucketName,
158
+ ossObjectName: fileSources?.find(({ fcName }) => fcName === (0, common_1.calcRefs)(fnc.name, context))
159
+ ?.objectKey,
160
+ };
161
+ }
162
+ runtimeConfig = {
163
+ code,
164
+ handler: (0, common_1.calcRefs)(fnc.code.handler, context),
165
+ runtime: (0, common_1.calcRefs)(fnc.code.runtime, context),
93
166
  };
94
167
  }
168
+ let vpcConfig = undefined;
169
+ if (fnc.network) {
170
+ const securityGroup = new ecs.SecurityGroup(scope, (0, common_1.formatRosId)(`${fnc.key}_security_group`), {
171
+ securityGroupName: fnc.network.security_group.name,
172
+ vpcId: (0, common_1.calcRefs)(fnc.network.vpc_id, context),
173
+ tags: (0, common_1.calcRefs)(tags, context),
174
+ securityGroupIngress: transformSecurityRules(fnc.network.security_group.ingress, 'INGRESS'),
175
+ securityGroupEgress: transformSecurityRules(fnc.network.security_group.egress, 'EGRESS'),
176
+ }, true);
177
+ vpcConfig = {
178
+ vpcId: (0, common_1.calcRefs)(fnc.network.vpc_id, context),
179
+ vSwitchIds: (0, common_1.calcRefs)(fnc.network.subnet_ids, context),
180
+ securityGroupId: securityGroup.attrSecurityGroupId,
181
+ };
182
+ }
183
+ let fcNas;
184
+ if (fnc.storage?.nas) {
185
+ fcNas = fnc.storage.nas.map((nasItem) => {
186
+ const storageClass = (0, common_1.calcValue)(nasItem.storage_class, context);
187
+ const { fileSystemType, storageType } = storageClassMap[storageClass];
188
+ const mountPathValue = (0, common_1.formatRosId)((0, common_1.calcValue)(nasItem.mount_path, context));
189
+ const nasMountTargetId = (0, common_1.formatRosId)(`${fnc.key}_nas_mount_${mountPathValue}`);
190
+ const accessGroup = new nas.AccessGroup(scope, (0, common_1.formatRosId)(`${fnc.key}_nas_access_${mountPathValue}`), {
191
+ accessGroupName: (0, common_1.calcRefs)(`${fnc.name}-nas-access-${mountPathValue.replace(/_/g, '-')}`, context),
192
+ accessGroupType: 'Vpc',
193
+ }, true);
194
+ const fcVpcSubnets = fnc.network?.subnet_ids.map((subnet) => new vpc.datasource.VSwitch(scope, (0, common_1.formatRosId)((0, common_1.calcValue)(`${fnc.key}_datasource_subnet_${subnet}`, context)), {
195
+ vSwitchId: subnet,
196
+ refreshOptions: 'Always',
197
+ }));
198
+ fcVpcSubnets?.forEach((subnetDatasource, index) => {
199
+ new nas.AccessRule(scope, (0, common_1.formatRosId)((0, common_1.calcValue)(`${fnc.key}_nas_rule_${fnc.network.subnet_ids[index]}`, context)), {
200
+ accessGroupName: accessGroup.attrAccessGroupName,
201
+ sourceCidrIp: subnetDatasource.attrCidrBlock,
202
+ }, true);
203
+ });
204
+ const nasResource = new nas.FileSystem(scope, (0, common_1.formatRosId)(`${fnc.key}_nas_${mountPathValue}`), {
205
+ fileSystemType,
206
+ storageType,
207
+ protocolType: 'NFS',
208
+ tags: [
209
+ ...((0, common_1.calcRefs)(tags, context) ?? []),
210
+ { key: 'function-name', value: (0, common_1.calcRefs)(fnc.name, context) },
211
+ ],
212
+ }, true);
213
+ const nasMountTarget = new nas.MountTarget(scope, nasMountTargetId, {
214
+ fileSystemId: nasResource.attrFileSystemId,
215
+ networkType: 'Vpc',
216
+ accessGroupName: accessGroup.attrAccessGroupName,
217
+ vpcId: (0, common_1.calcRefs)(fnc.network.vpc_id, context),
218
+ vSwitchId: (0, common_1.calcRefs)(fnc.network.subnet_ids[0], context),
219
+ }, true);
220
+ return {
221
+ nas: nasResource,
222
+ nasMount: nasMountTarget,
223
+ mountDir: (0, common_1.calcRefs)(nasItem.mount_path, context),
224
+ nasMountTargetId,
225
+ };
226
+ });
227
+ }
95
228
  const fcn = new fc.RosFunction(scope, fnc.key, {
96
- functionName: (0, common_1.replaceReference)(fnc.name, context),
97
- handler: (0, common_1.replaceReference)(fnc.handler, context),
98
- runtime: (0, common_1.replaceReference)(fnc.runtime, context),
99
- memorySize: (0, common_1.replaceReference)(fnc.memory, context),
100
- timeout: (0, common_1.replaceReference)(fnc.timeout, context),
101
- environmentVariables: (0, common_1.replaceReference)(fnc.environment, context),
102
- code,
229
+ functionName: (0, common_1.calcRefs)(fnc.name, context),
230
+ memorySize: (0, common_1.calcRefs)(fnc.memory, context),
231
+ diskSize: (0, common_1.calcRefs)(fnc.storage?.disk, context),
232
+ gpuConfig: transformGpuConfig(fnc.gpu),
233
+ timeout: (0, common_1.calcRefs)(fnc.timeout, context),
234
+ environmentVariables: (0, common_1.calcRefs)(fnc.environment, context),
103
235
  logConfig,
236
+ vpcConfig,
237
+ ...runtimeConfig,
238
+ nasConfig: fcNas?.length
239
+ ? {
240
+ mountPoints: fcNas?.map(({ nasMount, mountDir }) => ({
241
+ mountDir,
242
+ serverAddr: `${nasMount.attrMountTargetDomain}:/`,
243
+ })),
244
+ }
245
+ : undefined,
104
246
  }, true);
105
247
  if (enableLog) {
106
- fcn.addRosDependency(`${service}_sls`);
107
- fcn.addRosDependency(`${service}_sls_logstore`);
108
- fcn.addRosDependency(`${service}_sls_index`);
248
+ fcn.addRosDependency(slsProjectId);
249
+ fcn.addRosDependency(slsLogstoreId);
250
+ fcn.addRosDependency(slsIndexId);
109
251
  }
110
252
  if (storeInBucket) {
111
- fcn.addRosDependency(`${service}_artifacts_code_deployment`);
253
+ fcn.addRosDependency(ossDeploymentId);
254
+ }
255
+ if (fcNas?.length) {
256
+ fcNas.forEach(({ nasMountTargetId }) => fcn.addRosDependency(nasMountTargetId));
112
257
  }
113
258
  });
114
259
  };
@@ -1,7 +1,7 @@
1
1
  import * as ros from '@alicloud/ros-cdk-core';
2
- import { ActionContext, ServerlessIac } from '../../types';
2
+ import { Context, ServerlessIac } from '../../types';
3
3
  export * from './bootstrap';
4
4
  export declare class RosStack extends ros.Stack {
5
5
  private readonly service;
6
- constructor(scope: ros.Construct, iac: ServerlessIac, context: ActionContext);
6
+ constructor(scope: ros.Construct, iac: ServerlessIac, context: Context);
7
7
  }
@@ -45,17 +45,18 @@ const stage_1 = require("./stage");
45
45
  const vars_1 = require("./vars");
46
46
  const database_1 = require("./database");
47
47
  const event_1 = require("./event");
48
+ const bucket_1 = require("./bucket");
48
49
  __exportStar(require("./bootstrap"), exports);
49
50
  class RosStack extends ros.Stack {
50
51
  constructor(scope, iac, context) {
51
- super(scope, (0, common_1.replaceReference)(iac.service, context), {
52
+ super(scope, (0, common_1.calcRefs)(iac.service, context), {
52
53
  stackName: context.stackName,
53
54
  tags: (0, tag_1.resolveTags)(iac.tags, context),
54
55
  });
55
- this.service = (0, common_1.replaceReference)(iac.service, context);
56
+ this.service = (0, common_1.calcRefs)(iac.service, context);
56
57
  new ros.RosInfo(this, ros.RosInfo.description, `${this.service} stack`);
57
58
  // Define Parameters
58
- (0, vars_1.resloveVars)(this, iac.vars);
59
+ (0, vars_1.resolveVars)(this, iac.vars);
59
60
  // Define Mappings
60
61
  (0, stage_1.resolveStages)(this, iac.stages, context);
61
62
  // Define functions
@@ -64,6 +65,8 @@ class RosStack extends ros.Stack {
64
65
  (0, event_1.resolveEvents)(this, iac.events, iac.tags, context, this.service);
65
66
  // Define Databases
66
67
  (0, database_1.resolveDatabases)(this, iac.databases, context);
68
+ // Define Buckets
69
+ (0, bucket_1.resolveBuckets)(this, iac.buckets, context);
67
70
  }
68
71
  }
69
72
  exports.RosStack = RosStack;
@@ -41,6 +41,6 @@ const resolveStages = (scope, stages, context) => {
41
41
  if ((0, lodash_1.isEmpty)(stages)) {
42
42
  return undefined;
43
43
  }
44
- new ros.RosMapping(scope, 'stages', { mapping: (0, common_1.replaceReference)(stages, context) });
44
+ new ros.RosMapping(scope, 'stages', { mapping: (0, common_1.calcRefs)(stages, context) });
45
45
  };
46
46
  exports.resolveStages = resolveStages;
@@ -4,7 +4,7 @@ exports.resolveTags = void 0;
4
4
  const common_1 = require("../../common");
5
5
  const resolveTags = (tags, context) => {
6
6
  return tags?.reduce((acc, tag) => {
7
- acc[tag.key] = (0, common_1.replaceReference)(tag.value, context);
7
+ acc[tag.key] = (0, common_1.calcRefs)(tag.value, context);
8
8
  return acc;
9
9
  }, {});
10
10
  };
@@ -33,11 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.resloveVars = void 0;
36
+ exports.resolveVars = void 0;
37
37
  const ros = __importStar(require("@alicloud/ros-cdk-core"));
38
38
  const ros_cdk_core_1 = require("@alicloud/ros-cdk-core");
39
39
  const lodash_1 = require("lodash");
40
- const resloveVars = (scope, vars) => {
40
+ const resolveVars = (scope, vars) => {
41
41
  if ((0, lodash_1.isEmpty)(vars)) {
42
42
  return undefined;
43
43
  }
@@ -46,4 +46,4 @@ const resloveVars = (scope, vars) => {
46
46
  defaultValue: value,
47
47
  }));
48
48
  };
49
- exports.resloveVars = resloveVars;
49
+ exports.resolveVars = resolveVars;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BucketAccessEnum = void 0;
4
+ var BucketAccessEnum;
5
+ (function (BucketAccessEnum) {
6
+ BucketAccessEnum["PRIVATE"] = "PRIVATE";
7
+ BucketAccessEnum["PUBLIC_READ"] = "PUBLIC_READ";
8
+ BucketAccessEnum["PUBLIC_READ_WRITE"] = "PUBLIC_READ_WRITE";
9
+ })(BucketAccessEnum || (exports.BucketAccessEnum = BucketAccessEnum = {}));
@@ -1,2 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionGpuEnum = exports.NasStorageClassEnum = void 0;
4
+ var NasStorageClassEnum;
5
+ (function (NasStorageClassEnum) {
6
+ NasStorageClassEnum["STANDARD_PERFORMANCE"] = "STANDARD_PERFORMANCE";
7
+ NasStorageClassEnum["STANDARD_CAPACITY"] = "STANDARD_CAPACITY";
8
+ NasStorageClassEnum["EXTREME_STANDARD"] = "EXTREME_STANDARD";
9
+ NasStorageClassEnum["EXTREME_ADVANCE"] = "EXTREME_ADVANCE";
10
+ })(NasStorageClassEnum || (exports.NasStorageClassEnum = NasStorageClassEnum = {}));
11
+ var FunctionGpuEnum;
12
+ (function (FunctionGpuEnum) {
13
+ FunctionGpuEnum["TESLA_8"] = "TESLA_8";
14
+ FunctionGpuEnum["TESLA_12"] = "TESLA_12";
15
+ FunctionGpuEnum["TESLA_16"] = "TESLA_16";
16
+ FunctionGpuEnum["AMPERE_8"] = "AMPERE_8";
17
+ FunctionGpuEnum["AMPERE_12"] = "AMPERE_12";
18
+ FunctionGpuEnum["AMPERE_16"] = "AMPERE_16";
19
+ FunctionGpuEnum["AMPERE_24"] = "AMPERE_24";
20
+ FunctionGpuEnum["ADA_48"] = "ADA_48";
21
+ })(FunctionGpuEnum || (exports.FunctionGpuEnum = FunctionGpuEnum = {}));
@@ -4,12 +4,14 @@ import { EventDomain, EventRaw } from './domains/event';
4
4
  import { DatabaseDomain, DatabaseRaw } from './domains/database';
5
5
  import { FunctionDomain, FunctionRaw } from './domains/function';
6
6
  import { Provider } from './domains/provider';
7
+ import { BucketDomain, BucketRaw } from './domains/bucket';
7
8
  export * from './domains/database';
8
9
  export * from './domains/event';
9
10
  export * from './domains/function';
10
11
  export * from './domains/tag';
11
12
  export * from './domains/vars';
12
13
  export * from './domains/context';
14
+ export * from './domains/bucket';
13
15
  export * from './assets';
14
16
  export type ServerlessIacRaw = {
15
17
  version: string;
@@ -27,6 +29,9 @@ export type ServerlessIacRaw = {
27
29
  databases: {
28
30
  [key: string]: DatabaseRaw;
29
31
  };
32
+ buckets: {
33
+ [key: string]: BucketRaw;
34
+ };
30
35
  };
31
36
  export type ServerlessIac = {
32
37
  version: string;
@@ -41,4 +46,5 @@ export type ServerlessIac = {
41
46
  functions?: Array<FunctionDomain>;
42
47
  events?: Array<EventDomain>;
43
48
  databases?: Array<DatabaseDomain>;
49
+ buckets?: Array<BucketDomain>;
44
50
  };
@@ -20,4 +20,5 @@ __exportStar(require("./domains/function"), exports);
20
20
  __exportStar(require("./domains/tag"), exports);
21
21
  __exportStar(require("./domains/vars"), exports);
22
22
  __exportStar(require("./domains/context"), exports);
23
+ __exportStar(require("./domains/bucket"), exports);
23
24
  __exportStar(require("./assets"), exports);
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bucketSchema = void 0;
4
+ exports.bucketSchema = {
5
+ $id: 'https://serverlessinsight.geekfun.club/schemas/bucketschema.json',
6
+ type: 'object',
7
+ patternProperties: {
8
+ '.*': {
9
+ type: 'object',
10
+ properties: {
11
+ name: {
12
+ type: 'string',
13
+ },
14
+ storage: {
15
+ type: 'object',
16
+ properties: {
17
+ class: {
18
+ type: 'string',
19
+ },
20
+ },
21
+ required: ['class'],
22
+ },
23
+ versioning: {
24
+ type: 'object',
25
+ properties: {
26
+ status: {
27
+ type: 'string',
28
+ },
29
+ },
30
+ required: ['status'],
31
+ },
32
+ security: {
33
+ type: 'object',
34
+ properties: {
35
+ access: {
36
+ type: 'string',
37
+ enum: ['PRIVATE', 'PUBLIC_READ', 'PUBLIC_READ_WRITE'],
38
+ },
39
+ force_delete: {
40
+ type: 'boolean',
41
+ },
42
+ sse_algorithm: {
43
+ type: 'string',
44
+ },
45
+ sse_kms_master_key_id: {
46
+ type: 'string',
47
+ },
48
+ },
49
+ },
50
+ website: {
51
+ type: 'object',
52
+ properties: {
53
+ code: {
54
+ type: 'string',
55
+ },
56
+ domain: {
57
+ type: 'string',
58
+ },
59
+ index: {
60
+ type: 'string',
61
+ },
62
+ error_page: {
63
+ type: 'string',
64
+ },
65
+ error_code: {
66
+ type: 'number',
67
+ },
68
+ },
69
+ required: ['code'],
70
+ },
71
+ },
72
+ required: ['name'],
73
+ additionalProperties: false,
74
+ },
75
+ },
76
+ };