@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
@@ -36,15 +36,13 @@ 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.publishAssets = exports.rosStackDelete = exports.rosStackDeploy = void 0;
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");
45
+ const context_1 = require("./context");
48
46
  const client = new ros20190910_1.default(new openapi_client_1.Config({
49
47
  accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
50
48
  accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
@@ -88,7 +86,7 @@ const updateStack = async (stackId, templateBody, context) => {
88
86
  return await getStackActionResult(response.body?.stackId || '', context.region);
89
87
  }
90
88
  catch (err) {
91
- const { Message: message, statusCode } = err?.data || {};
89
+ const { message, statusCode } = err || {};
92
90
  if (statusCode === 400 && message.includes('Update the completely same stack')) {
93
91
  logger_1.logger.warn(`${lang_1.lang.__('UPDATE_COMPLETELY_SAME_STACK')}`);
94
92
  return null;
@@ -157,7 +155,8 @@ const getStackActionResult = async (stackId, region) => {
157
155
  }, 5000); // 5 seconds interval
158
156
  });
159
157
  };
160
- const rosStackDeploy = async (stackName, templateBody, context) => {
158
+ const rosStackDeploy = async (stackName, templateBody) => {
159
+ const context = (0, context_1.getContext)();
161
160
  const stackInfo = await getStackByName(stackName, context.region);
162
161
  if (stackInfo) {
163
162
  const { Status: stackStatus } = stackInfo;
@@ -189,7 +188,7 @@ const rosStackDelete = async ({ stackName, region, }) => {
189
188
  });
190
189
  await client.deleteStack(deleteStackRequest);
191
190
  await getStackActionResult(stackInfo.stackId, region);
192
- logger_1.logger.info(`Stack: ${stackName} deleted! ♻️`);
191
+ logger_1.logger.info(`Stack: ${stackName} deleted!🗑 `);
193
192
  }
194
193
  catch (err) {
195
194
  logger_1.logger.error(`Stack: ${stackName} delete failed! ❌, error: ${JSON.stringify(err)}`);
@@ -197,52 +196,3 @@ const rosStackDelete = async ({ stackName, region, }) => {
197
196
  }
198
197
  };
199
198
  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;
@@ -10,6 +10,7 @@ const parseEvent = (events) => {
10
10
  name: event.name,
11
11
  type: event.type,
12
12
  triggers: event.triggers,
13
+ domain: event.domain,
13
14
  }));
14
15
  };
15
16
  exports.parseEvent = parseEvent;
@@ -9,13 +9,21 @@ const parseFunction = (functions) => {
9
9
  return Object.entries(functions).map(([key, func]) => ({
10
10
  key,
11
11
  name: func.name,
12
- runtime: func.runtime,
13
- handler: func.handler,
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
- code: func.code,
18
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
+ },
19
27
  }));
20
28
  };
21
29
  exports.parseFunction = parseFunction;
@@ -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) => {
@@ -43,7 +43,8 @@ const common_1 = require("../common");
43
43
  const rosStack_1 = require("./rosStack");
44
44
  const rfsStack_1 = require("./rfsStack");
45
45
  const lodash_1 = require("lodash");
46
- const generateRosStackTemplate = (stackName, iac, context) => {
46
+ const generateRosStackTemplate = (stackName, iac) => {
47
+ const context = (0, common_1.getContext)();
47
48
  const app = new ros.App();
48
49
  new rosStack_1.RosStack(app, iac, context);
49
50
  const assembly = app.synth();
@@ -57,29 +58,45 @@ const generateRosStackTemplate = (stackName, iac, context) => {
57
58
  return { template, assets };
58
59
  };
59
60
  exports.generateRosStackTemplate = generateRosStackTemplate;
60
- const generateRfsStackTemplate = (stackName, iac, context) => {
61
- const stack = new rfsStack_1.RfsStack(iac, context);
61
+ const generateRfsStackTemplate = (stackName, iac) => {
62
+ const stack = new rfsStack_1.RfsStack(iac);
62
63
  const hcl = stack.toHclTerraform();
63
64
  console.log('HCL:', hcl);
64
65
  return { template: hcl };
65
66
  };
66
67
  exports.generateRfsStackTemplate = generateRfsStackTemplate;
67
- const deployStack = async (stackName, iac, context) => {
68
- const { template, assets } = (0, exports.generateRosStackTemplate)(stackName, iac, context);
69
- await (0, rosStack_1.prepareBootstrapStack)(context);
68
+ const deployStack = async (stackName, iac) => {
69
+ const { template, assets } = (0, exports.generateRosStackTemplate)(stackName, iac);
70
+ await (0, rosStack_1.prepareBootstrapStack)();
70
71
  common_1.logger.info(`Deploying stack, publishing assets...`);
71
- await (0, common_1.publishAssets)(assets, context);
72
- common_1.logger.info(`Assets published! 🎉`);
73
- await (0, common_1.rosStackDeploy)(stackName, template, context);
74
- common_1.logger.info(`Stack deployed! 🎉`);
72
+ const constructedAssets = await (0, common_1.constructAssets)(assets);
73
+ try {
74
+ await (0, common_1.publishAssets)(constructedAssets);
75
+ common_1.logger.info(`Assets published! 🎉`);
76
+ await (0, common_1.rosStackDeploy)(stackName, template);
77
+ }
78
+ catch (e) {
79
+ common_1.logger.error(`Failed to deploy stack: ${e}`);
80
+ throw e;
81
+ }
82
+ finally {
83
+ try {
84
+ common_1.logger.info(`Cleaning up temporary Assets...`);
85
+ await (0, common_1.cleanupAssets)(constructedAssets);
86
+ common_1.logger.info(`Assets cleaned up!♻️`);
87
+ }
88
+ catch (e) {
89
+ common_1.logger.error(`Failed to cleanup assets, it wont affect the deployment result, but to avoid potential cost, you can delete the temporary bucket : ${constructedAssets?.[0].bucketName}, error details:${e}`);
90
+ }
91
+ }
75
92
  };
76
93
  exports.deployStack = deployStack;
77
- const generateStackTemplate = (stackName, iac, context) => {
94
+ const generateStackTemplate = (stackName, iac) => {
78
95
  if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
79
- return (0, exports.generateRosStackTemplate)(stackName, iac, context);
96
+ return (0, exports.generateRosStackTemplate)(stackName, iac);
80
97
  }
81
98
  else if (iac.provider.name === common_1.ProviderEnum.HUAWEI) {
82
- return (0, exports.generateRfsStackTemplate)(stackName, iac, context);
99
+ return (0, exports.generateRfsStackTemplate)(stackName, iac);
83
100
  }
84
101
  return { template: '' };
85
102
  };
@@ -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
  `;
@@ -1,9 +1,9 @@
1
- import { ActionContext, ServerlessIac } from '../../types';
1
+ import { Context, ServerlessIac } from '../../types';
2
2
  export declare class RfsStack {
3
3
  private readonly iac;
4
4
  private readonly context;
5
5
  private hcl;
6
- constructor(iac: ServerlessIac, context: ActionContext);
6
+ constructor(iac: ServerlessIac, context?: Context);
7
7
  toHclTerraform(): string;
8
8
  appendHcl(hcl: string): void;
9
9
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RfsStack = void 0;
4
4
  const function_1 = require("./function");
5
+ const common_1 = require("../../common");
5
6
  const provider = (stack, context) => {
6
7
  const hcl = `
7
8
  terraform {
@@ -22,7 +23,7 @@ provider "huaweicloud" {
22
23
  stack.appendHcl(hcl);
23
24
  };
24
25
  class RfsStack {
25
- constructor(iac, context) {
26
+ constructor(iac, context = (0, common_1.getContext)()) {
26
27
  this.iac = iac;
27
28
  this.context = context;
28
29
  this.hcl = '';
@@ -4,7 +4,7 @@ exports.prepareBootstrapStack = void 0;
4
4
  const common_1 = require("../../common");
5
5
  const getBootstrapTemplate = async (context) => {
6
6
  const iamInfo = await (0, common_1.getIamInfo)(context);
7
- const stackName = `serverlessInsight-bootstrap-${iamInfo?.accountId}-${context.region}`;
7
+ const stackName = `si-bootstrap-${iamInfo?.accountId}-${context.region}`;
8
8
  const template = {
9
9
  Description: 'ServerlessInsight Bootstrap Stack',
10
10
  Metadata: {
@@ -14,7 +14,7 @@ const getBootstrapTemplate = async (context) => {
14
14
  },
15
15
  ROSTemplateFormatVersion: '2015-09-01',
16
16
  Resources: {
17
- ServerlessInsight_artifacts_bucket: {
17
+ si_auto_artifacts_bucket: {
18
18
  Type: 'ALIYUN::OSS::Bucket',
19
19
  Properties: {
20
20
  BucketName: {
@@ -33,8 +33,9 @@ const getBootstrapTemplate = async (context) => {
33
33
  };
34
34
  return { stackName, template };
35
35
  };
36
- const prepareBootstrapStack = async (context) => {
36
+ const prepareBootstrapStack = async () => {
37
+ const context = (0, common_1.getContext)();
37
38
  const { stackName, template } = await getBootstrapTemplate(context);
38
- await (0, common_1.rosStackDeploy)(stackName, template, context);
39
+ await (0, common_1.rosStackDeploy)(stackName, template);
39
40
  };
40
41
  exports.prepareBootstrapStack = prepareBootstrapStack;
@@ -0,0 +1,126 @@
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.resolveBuckets = void 0;
40
+ const types_1 = require("../../types");
41
+ const oss = __importStar(require("@alicloud/ros-cdk-oss"));
42
+ const ros = __importStar(require("@alicloud/ros-cdk-core"));
43
+ const common_1 = require("../../common");
44
+ const ossDeployment = __importStar(require("@alicloud/ros-cdk-ossdeployment"));
45
+ const dns = __importStar(require("@alicloud/ros-cdk-dns"));
46
+ const node_path_1 = __importDefault(require("node:path"));
47
+ const ros_cdk_ram_1 = require("@alicloud/ros-cdk-ram");
48
+ const aclMap = new Map([
49
+ [types_1.BucketAccessEnum.PRIVATE, 'private'],
50
+ [types_1.BucketAccessEnum.PUBLIC_READ, 'public-read'],
51
+ [types_1.BucketAccessEnum.PUBLIC_READ_WRITE, 'public-read-write'],
52
+ ]);
53
+ const resolveBuckets = (scope, buckets, context) => {
54
+ if (!buckets) {
55
+ return undefined;
56
+ }
57
+ const bucketSources = buckets.some((bucket) => bucket?.website?.code);
58
+ let siAutoOssDeploymentBucketRole;
59
+ if (bucketSources) {
60
+ siAutoOssDeploymentBucketRole = new ros_cdk_ram_1.RosRole(scope, 'si_auto_od_bucket_role', {
61
+ roleName: ros.Fn.sub('si-auto-od-bucket-role-${ALIYUN::StackId}'),
62
+ description: 'roles created by ServerlessInsight for oss deployment to put files to oss bucket during deployment',
63
+ deletionForce: false,
64
+ ignoreExisting: false,
65
+ assumeRolePolicyDocument: {
66
+ version: '1',
67
+ statement: [
68
+ {
69
+ action: 'sts:AssumeRole',
70
+ effect: 'Allow',
71
+ principal: { service: ['fc.aliyuncs.com'] },
72
+ },
73
+ ],
74
+ },
75
+ policyAttachments: {
76
+ system: ['AliyunOSSFullAccess', 'AliyunLogFullAccess'],
77
+ },
78
+ }, true);
79
+ }
80
+ buckets.forEach((bucket) => {
81
+ const ossBucket = new oss.Bucket(scope, bucket.key, {
82
+ bucketName: (0, common_1.calcRefs)(bucket.name, context),
83
+ accessControl: aclMap.get((0, common_1.calcRefs)(bucket.security?.acl, context) ?? ''),
84
+ websiteConfigurationV2: bucket.website
85
+ ? {
86
+ indexDocument: {
87
+ type: '0',
88
+ suffix: (0, common_1.calcRefs)(bucket.website.index, context),
89
+ supportSubDir: 'true',
90
+ },
91
+ errorDocument: {
92
+ httpStatus: `${(0, common_1.calcRefs)(bucket.website.error_code, context)}`,
93
+ key: (0, common_1.calcRefs)(bucket.website.error_page, context),
94
+ },
95
+ }
96
+ : undefined,
97
+ });
98
+ if (bucket.website?.code) {
99
+ const filePath = node_path_1.default.resolve(process.cwd(), (0, common_1.calcValue)(bucket.website.code, context));
100
+ new ossDeployment.BucketDeployment(scope, (0, common_1.formatRosId)(`si_auto_${bucket.key}_bucket_code_deployment`), {
101
+ sources: (0, common_1.getAssets)(filePath),
102
+ destinationBucket: ossBucket.attrName,
103
+ roleArn: siAutoOssDeploymentBucketRole.attrArn,
104
+ timeout: common_1.OSS_DEPLOYMENT_TIMEOUT,
105
+ logMonitoring: false,
106
+ retainOnCreate: false,
107
+ }, true);
108
+ }
109
+ if (bucket.website?.domain) {
110
+ const { rr, domainName } = (0, common_1.splitDomain)(bucket.website.domain);
111
+ new oss.Domain(scope, (0, common_1.formatRosId)(`${bucket.key}_custom_domain`), {
112
+ bucketName: ossBucket.attrName,
113
+ domainName: (0, common_1.calcRefs)(bucket.website.domain, context),
114
+ });
115
+ new dns.DomainRecord(scope, (0, common_1.formatRosId)(`${bucket.key}_custom_domain_record`), {
116
+ domainName: domainName,
117
+ rr,
118
+ type: 'CNAME',
119
+ value: [types_1.BucketAccessEnum.PUBLIC_READ, types_1.BucketAccessEnum.PUBLIC_READ_WRITE].includes(bucket.security?.acl ?? '')
120
+ ? ossBucket.attrDomainName
121
+ : ossBucket.attrInternalDomainName,
122
+ });
123
+ }
124
+ });
125
+ };
126
+ exports.resolveBuckets = resolveBuckets;
@@ -212,13 +212,13 @@ const resolveDatabases = (scope, databases, context) => {
212
212
  databases.forEach((db) => {
213
213
  const { engine, version, category, dbInstanceClass, quota, storage } = rdsEngineMap.get(`${db.type}-${db.version}`) ?? {};
214
214
  if (["ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */].includes(db.type)) {
215
- new esServerless.App(scope, (0, common_1.replaceReference)(db.key, context), {
216
- appName: (0, common_1.replaceReference)(db.name, context),
215
+ new esServerless.App(scope, db.key, {
216
+ appName: (0, common_1.calcRefs)(db.name, context),
217
217
  appVersion: version,
218
218
  authentication: {
219
219
  basicAuth: [
220
220
  {
221
- password: (0, common_1.replaceReference)(db.security.basicAuth.password, context),
221
+ password: (0, common_1.calcRefs)(db.security.basicAuth.password, context),
222
222
  },
223
223
  ],
224
224
  },
@@ -246,7 +246,7 @@ const resolveDatabases = (scope, databases, context) => {
246
246
  "RDS_PGSQL_SERVERLESS" /* DatabaseEnum.RDS_PGSQL_SERVERLESS */,
247
247
  "RDS_MSSQL_SERVERLESS" /* DatabaseEnum.RDS_MSSQL_SERVERLESS */,
248
248
  ].includes(db.type)) {
249
- new rds.DBInstance(scope, (0, common_1.replaceReference)(db.key, context), {
249
+ new rds.DBInstance(scope, db.key, {
250
250
  engine: engine,
251
251
  /**
252
252
  * Serverless 实例
@@ -255,7 +255,7 @@ const resolveDatabases = (scope, databases, context) => {
255
255
  * PostgreSQL:14.0、15.0、16.0 - PGSQL_HA_14, PGSQL_14 PGSQL_HA_15, PGSQL_15, PGSQL_HA_16,PGSQL_16
256
256
  */
257
257
  engineVersion: version,
258
- dbInstanceStorage: (0, common_1.replaceReference)(db.storage.min, context),
258
+ dbInstanceStorage: (0, common_1.calcRefs)(db.storage.min, context),
259
259
  /** Serverless 实例
260
260
  * serverless_basic:Serverless 基础系列。(仅适用 MySQL 和 PostgreSQL)
261
261
  * serverless_standard:Serverless 高可用系列。(仅适用 MySQL 和 PostgreSQL)
@@ -293,18 +293,18 @@ const resolveDatabases = (scope, databases, context) => {
293
293
  */
294
294
  serverlessConfig: {
295
295
  // @TODO db.cu.min should get parameter value when it refer to a parameter
296
- minCapacity: (0, common_1.replaceReference)(db.cu.min === 0 ? quota.minCapacity : db.cu.min + quota.minCapacity, context),
297
- maxCapacity: (0, common_1.replaceReference)(db.cu.max + quota.minCapacity <= quota.maxCapacity
296
+ minCapacity: (0, common_1.calcRefs)(db.cu.min === 0 ? quota.minCapacity : db.cu.min + quota.minCapacity, context),
297
+ maxCapacity: (0, common_1.calcRefs)(db.cu.max + quota.minCapacity <= quota.maxCapacity
298
298
  ? db.cu.max + quota.minCapacity
299
299
  : quota.maxCapacity, context),
300
300
  autoPause: db.cu.min === 0,
301
301
  switchForce: false,
302
302
  },
303
- masterUsername: (0, common_1.replaceReference)(db.security.basicAuth.username, context),
304
- masterUserPassword: (0, common_1.replaceReference)(db.security.basicAuth.password, context),
303
+ masterUsername: (0, common_1.calcRefs)(db.security.basicAuth.username, context),
304
+ masterUserPassword: (0, common_1.calcRefs)(db.security.basicAuth.password, context),
305
305
  masterUserType: 'Super',
306
306
  multiAz: quota.ha,
307
- securityIpList: (0, common_1.replaceReference)(db.network.ingressRules.join(','), context),
307
+ securityIpList: (0, common_1.calcRefs)(db.network.ingressRules.join(','), context),
308
308
  connectionStringType: db.network.type === 'PRIVATE' ? 'Inner' : 'Public',
309
309
  dbInstanceNetType: db.network.type === 'PRIVATE' ? 'Intranet' : 'Internet',
310
310
  }, true);