@codedazur/cdk-docker-cluster 1.0.0 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @codedazur/cdk-docker-cluster
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b24894a`](https://github.com/codedazur/toolkit/commit/b24894a2de01e596669c2b5aca51bc0b28533106) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Mark the package as side-effect-free for tree shaking.
8
+
9
+ - Updated dependencies [[`b24894a`](https://github.com/codedazur/toolkit/commit/b24894a2de01e596669c2b5aca51bc0b28533106)]:
10
+ - @codedazur/cdk-site-distribution@1.0.1
11
+
12
+ ## 1.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [`5a3a979`](https://github.com/codedazur/toolkit/commit/5a3a979ed8de855f6ef4d410eed95db2230e0b2e) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Autoscaling thresholds and cooldowns can now be configured.
17
+
18
+ ### Patch Changes
19
+
20
+ - [`78a1ab2`](https://github.com/codedazur/toolkit/commit/78a1ab2f853f66480ff7b240d083aa22883471ab) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - If a minimum and maximum task count is provided, the cluster will now autoscale at 75% cpu or memory utilization by default.
21
+
3
22
  ## 1.0.0
4
23
 
5
24
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as aws_cdk_lib_aws_ecs from 'aws-cdk-lib/aws-ecs';
2
- import { ContainerImage, Secret } from 'aws-cdk-lib/aws-ecs';
2
+ import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
3
3
  import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
4
+ import { Duration } from 'aws-cdk-lib';
4
5
  import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
5
6
  import { Construct } from 'constructs';
6
7
 
@@ -8,10 +9,7 @@ interface DockerClusterProps {
8
9
  source: string | SourceProps | ContainerImage;
9
10
  service?: {
10
11
  port?: number;
11
- tasks?: number | {
12
- minimum: number;
13
- maximum: number;
14
- };
12
+ tasks?: number | AutoScalingConfig;
15
13
  cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"];
16
14
  memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
17
15
  environment?: Record<string, string>;
@@ -19,6 +17,40 @@ interface DockerClusterProps {
19
17
  };
20
18
  distribution?: Omit<SiteDistributionProps, "origin">;
21
19
  }
20
+ interface AutoScalingConfig {
21
+ /**
22
+ * The minimum number of tasks to scale out to.
23
+ */
24
+ minimum: number;
25
+ /**
26
+ * The maximum number of tasks to scale out to.
27
+ */
28
+ maximum: number;
29
+ threshold?: {
30
+ /**
31
+ * The memory utilization percentage above which the service will scale out.
32
+ * @default 75
33
+ */
34
+ memory?: number;
35
+ /**
36
+ * The CPU utilization percentage above which the service will scale out.
37
+ * @default 75
38
+ */
39
+ cpu?: number;
40
+ };
41
+ cooldown?: {
42
+ /**
43
+ * The cooldown period for scaling in.
44
+ * @default Duration.seconds(300)
45
+ */
46
+ in?: Duration;
47
+ /**
48
+ * The cooldown period for scaling out.
49
+ * @default Duration.seconds(300)
50
+ */
51
+ out?: Duration;
52
+ };
53
+ }
22
54
  interface SourceProps {
23
55
  directory: string;
24
56
  exclude?: string[];
@@ -37,10 +69,12 @@ declare class DockerCluster extends Construct {
37
69
  readonly domain?: string;
38
70
  readonly image: ContainerImage;
39
71
  readonly service: ApplicationLoadBalancedFargateService;
72
+ readonly autoScaling?: ScalableTaskCount;
40
73
  readonly siteDistribution: SiteDistribution;
41
74
  constructor(scope: Construct, id: string, props: DockerClusterProps);
42
75
  protected createImage(source: string | SourceProps): aws_cdk_lib_aws_ecs.AssetImage;
43
76
  protected createService(): ApplicationLoadBalancedFargateService;
77
+ protected createAutoScaling(service: ApplicationLoadBalancedFargateService): ScalableTaskCount | undefined;
44
78
  protected createSiteDistribution(): SiteDistribution;
45
79
  protected getOutputDirectory(): string;
46
80
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as aws_cdk_lib_aws_ecs from 'aws-cdk-lib/aws-ecs';
2
- import { ContainerImage, Secret } from 'aws-cdk-lib/aws-ecs';
2
+ import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
3
3
  import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
4
+ import { Duration } from 'aws-cdk-lib';
4
5
  import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
5
6
  import { Construct } from 'constructs';
6
7
 
@@ -8,10 +9,7 @@ interface DockerClusterProps {
8
9
  source: string | SourceProps | ContainerImage;
9
10
  service?: {
10
11
  port?: number;
11
- tasks?: number | {
12
- minimum: number;
13
- maximum: number;
14
- };
12
+ tasks?: number | AutoScalingConfig;
15
13
  cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"];
16
14
  memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
17
15
  environment?: Record<string, string>;
@@ -19,6 +17,40 @@ interface DockerClusterProps {
19
17
  };
20
18
  distribution?: Omit<SiteDistributionProps, "origin">;
21
19
  }
20
+ interface AutoScalingConfig {
21
+ /**
22
+ * The minimum number of tasks to scale out to.
23
+ */
24
+ minimum: number;
25
+ /**
26
+ * The maximum number of tasks to scale out to.
27
+ */
28
+ maximum: number;
29
+ threshold?: {
30
+ /**
31
+ * The memory utilization percentage above which the service will scale out.
32
+ * @default 75
33
+ */
34
+ memory?: number;
35
+ /**
36
+ * The CPU utilization percentage above which the service will scale out.
37
+ * @default 75
38
+ */
39
+ cpu?: number;
40
+ };
41
+ cooldown?: {
42
+ /**
43
+ * The cooldown period for scaling in.
44
+ * @default Duration.seconds(300)
45
+ */
46
+ in?: Duration;
47
+ /**
48
+ * The cooldown period for scaling out.
49
+ * @default Duration.seconds(300)
50
+ */
51
+ out?: Duration;
52
+ };
53
+ }
22
54
  interface SourceProps {
23
55
  directory: string;
24
56
  exclude?: string[];
@@ -37,10 +69,12 @@ declare class DockerCluster extends Construct {
37
69
  readonly domain?: string;
38
70
  readonly image: ContainerImage;
39
71
  readonly service: ApplicationLoadBalancedFargateService;
72
+ readonly autoScaling?: ScalableTaskCount;
40
73
  readonly siteDistribution: SiteDistribution;
41
74
  constructor(scope: Construct, id: string, props: DockerClusterProps);
42
75
  protected createImage(source: string | SourceProps): aws_cdk_lib_aws_ecs.AssetImage;
43
76
  protected createService(): ApplicationLoadBalancedFargateService;
77
+ protected createAutoScaling(service: ApplicationLoadBalancedFargateService): ScalableTaskCount | undefined;
44
78
  protected createSiteDistribution(): SiteDistribution;
45
79
  protected getOutputDirectory(): string;
46
80
  }
package/dist/index.js CHANGED
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  DockerCluster: () => DockerCluster
24
24
  });
25
- module.exports = __toCommonJS(src_exports);
25
+ module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/constructs/DockerCluster.ts
28
28
  var import_cdk_site_distribution = require("@codedazur/cdk-site-distribution");
@@ -39,6 +39,7 @@ var DockerCluster = class extends import_constructs.Construct {
39
39
  this.props = props;
40
40
  this.image = this.props.source instanceof import_aws_ecs.ContainerImage ? this.props.source : this.createImage(this.props.source);
41
41
  this.service = this.createService();
42
+ this.autoScaling = this.createAutoScaling(this.service);
42
43
  this.siteDistribution = this.createSiteDistribution();
43
44
  }
44
45
  createImage(source) {
@@ -59,32 +60,45 @@ var DockerCluster = class extends import_constructs.Construct {
59
60
  });
60
61
  }
61
62
  createService() {
62
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
63
- const desiredTasks = typeof ((_a = this.props.service) == null ? void 0 : _a.tasks) === "number" ? (_b = this.props.service) == null ? void 0 : _b.tasks : (_d = (_c = this.props.service) == null ? void 0 : _c.tasks) == null ? void 0 : _d.minimum;
63
+ const desiredTasks = typeof this.props.service?.tasks === "number" ? this.props.service?.tasks : this.props.service?.tasks?.minimum;
64
64
  const service = new import_aws_ecs_patterns.ApplicationLoadBalancedFargateService(this, "Service", {
65
65
  cluster: new import_aws_ecs.Cluster(this, "Cluster"),
66
- cpu: (_e = this.props.service) == null ? void 0 : _e.cpu,
67
- memoryLimitMiB: (_f = this.props.service) == null ? void 0 : _f.memory,
66
+ cpu: this.props.service?.cpu,
67
+ memoryLimitMiB: this.props.service?.memory,
68
68
  desiredCount: desiredTasks,
69
69
  taskImageOptions: {
70
70
  image: this.image,
71
- containerPort: (_g = this.props.service) == null ? void 0 : _g.port,
72
- environment: (_h = this.props.service) == null ? void 0 : _h.environment,
73
- secrets: (_i = this.props.service) == null ? void 0 : _i.secrets
71
+ containerPort: this.props.service?.port,
72
+ environment: this.props.service?.environment,
73
+ secrets: this.props.service?.secrets
74
74
  },
75
75
  circuitBreaker: {
76
76
  enable: true,
77
77
  rollback: true
78
78
  }
79
79
  });
80
- if (typeof ((_j = this.props.service) == null ? void 0 : _j.tasks) === "object") {
81
- service.service.autoScaleTaskCount({
82
- minCapacity: (_k = this.props.service) == null ? void 0 : _k.tasks.minimum,
83
- maxCapacity: (_l = this.props.service) == null ? void 0 : _l.tasks.maximum
84
- });
85
- }
86
80
  return service;
87
81
  }
82
+ createAutoScaling(service) {
83
+ if (typeof this.props.service?.tasks !== "object") {
84
+ return;
85
+ }
86
+ const autoScaling = service.service.autoScaleTaskCount({
87
+ minCapacity: this.props.service?.tasks.minimum,
88
+ maxCapacity: this.props.service?.tasks.maximum
89
+ });
90
+ autoScaling.scaleOnMemoryUtilization("MemoryScaling", {
91
+ targetUtilizationPercent: this.props.service?.tasks.threshold?.memory ?? 75,
92
+ scaleInCooldown: this.props.service?.tasks.cooldown?.in,
93
+ scaleOutCooldown: this.props.service?.tasks.cooldown?.out
94
+ });
95
+ autoScaling.scaleOnCpuUtilization("CpuScaling", {
96
+ targetUtilizationPercent: this.props.service?.tasks.threshold?.cpu ?? 75,
97
+ scaleInCooldown: this.props.service?.tasks.cooldown?.in,
98
+ scaleOutCooldown: this.props.service?.tasks.cooldown?.out
99
+ });
100
+ return autoScaling;
101
+ }
88
102
  createSiteDistribution() {
89
103
  return new import_cdk_site_distribution.SiteDistribution(this, "Distribution", {
90
104
  allowedMethods: import_aws_cloudfront.AllowedMethods.ALLOW_ALL,
@@ -116,8 +130,7 @@ var DockerCluster = class extends import_constructs.Construct {
116
130
  });
117
131
  }
118
132
  getOutputDirectory() {
119
- var _a, _b;
120
- return (_b = (_a = import_aws_cdk_lib.App.of(this)) == null ? void 0 : _a.outdir) != null ? _b : "cdk.out";
133
+ return import_aws_cdk_lib.App.of(this)?.outdir ?? "cdk.out";
121
134
  }
122
135
  };
123
136
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -23,6 +23,7 @@ var DockerCluster = class extends Construct {
23
23
  this.props = props;
24
24
  this.image = this.props.source instanceof ContainerImage ? this.props.source : this.createImage(this.props.source);
25
25
  this.service = this.createService();
26
+ this.autoScaling = this.createAutoScaling(this.service);
26
27
  this.siteDistribution = this.createSiteDistribution();
27
28
  }
28
29
  createImage(source) {
@@ -43,32 +44,45 @@ var DockerCluster = class extends Construct {
43
44
  });
44
45
  }
45
46
  createService() {
46
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
47
- const desiredTasks = typeof ((_a = this.props.service) == null ? void 0 : _a.tasks) === "number" ? (_b = this.props.service) == null ? void 0 : _b.tasks : (_d = (_c = this.props.service) == null ? void 0 : _c.tasks) == null ? void 0 : _d.minimum;
47
+ const desiredTasks = typeof this.props.service?.tasks === "number" ? this.props.service?.tasks : this.props.service?.tasks?.minimum;
48
48
  const service = new ApplicationLoadBalancedFargateService(this, "Service", {
49
49
  cluster: new Cluster(this, "Cluster"),
50
- cpu: (_e = this.props.service) == null ? void 0 : _e.cpu,
51
- memoryLimitMiB: (_f = this.props.service) == null ? void 0 : _f.memory,
50
+ cpu: this.props.service?.cpu,
51
+ memoryLimitMiB: this.props.service?.memory,
52
52
  desiredCount: desiredTasks,
53
53
  taskImageOptions: {
54
54
  image: this.image,
55
- containerPort: (_g = this.props.service) == null ? void 0 : _g.port,
56
- environment: (_h = this.props.service) == null ? void 0 : _h.environment,
57
- secrets: (_i = this.props.service) == null ? void 0 : _i.secrets
55
+ containerPort: this.props.service?.port,
56
+ environment: this.props.service?.environment,
57
+ secrets: this.props.service?.secrets
58
58
  },
59
59
  circuitBreaker: {
60
60
  enable: true,
61
61
  rollback: true
62
62
  }
63
63
  });
64
- if (typeof ((_j = this.props.service) == null ? void 0 : _j.tasks) === "object") {
65
- service.service.autoScaleTaskCount({
66
- minCapacity: (_k = this.props.service) == null ? void 0 : _k.tasks.minimum,
67
- maxCapacity: (_l = this.props.service) == null ? void 0 : _l.tasks.maximum
68
- });
69
- }
70
64
  return service;
71
65
  }
66
+ createAutoScaling(service) {
67
+ if (typeof this.props.service?.tasks !== "object") {
68
+ return;
69
+ }
70
+ const autoScaling = service.service.autoScaleTaskCount({
71
+ minCapacity: this.props.service?.tasks.minimum,
72
+ maxCapacity: this.props.service?.tasks.maximum
73
+ });
74
+ autoScaling.scaleOnMemoryUtilization("MemoryScaling", {
75
+ targetUtilizationPercent: this.props.service?.tasks.threshold?.memory ?? 75,
76
+ scaleInCooldown: this.props.service?.tasks.cooldown?.in,
77
+ scaleOutCooldown: this.props.service?.tasks.cooldown?.out
78
+ });
79
+ autoScaling.scaleOnCpuUtilization("CpuScaling", {
80
+ targetUtilizationPercent: this.props.service?.tasks.threshold?.cpu ?? 75,
81
+ scaleInCooldown: this.props.service?.tasks.cooldown?.in,
82
+ scaleOutCooldown: this.props.service?.tasks.cooldown?.out
83
+ });
84
+ return autoScaling;
85
+ }
72
86
  createSiteDistribution() {
73
87
  return new SiteDistribution(this, "Distribution", {
74
88
  allowedMethods: AllowedMethods.ALLOW_ALL,
@@ -100,8 +114,7 @@ var DockerCluster = class extends Construct {
100
114
  });
101
115
  }
102
116
  getOutputDirectory() {
103
- var _a, _b;
104
- return (_b = (_a = App.of(this)) == null ? void 0 : _a.outdir) != null ? _b : "cdk.out";
117
+ return App.of(this)?.outdir ?? "cdk.out";
105
118
  }
106
119
  };
107
120
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codedazur/cdk-docker-cluster",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "main": ".dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "access": "public"
15
15
  },
16
16
  "license": "MIT",
17
+ "sideEffects": false,
17
18
  "scripts": {
18
19
  "develop": "tsup src/index.ts --format esm,cjs --dts --watch",
19
20
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -27,12 +28,12 @@
27
28
  "constructs": ">=10"
28
29
  },
29
30
  "dependencies": {
30
- "@codedazur/cdk-site-distribution": "^1.0.0"
31
+ "@codedazur/cdk-site-distribution": "^1.0.1"
31
32
  },
32
33
  "devDependencies": {
33
- "@types/node": "^20.14.10",
34
- "aws-cdk-lib": "^2.149.0",
35
- "constructs": "^10.3.0",
36
- "esbuild": "^0.23.0"
34
+ "@types/node": "^24.0.3",
35
+ "aws-cdk-lib": "^2.201.0",
36
+ "constructs": "^10.4.2",
37
+ "esbuild": "^0.25.5"
37
38
  }
38
39
  }