@codedazur/cdk-docker-cluster 1.0.0 → 1.1.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/CHANGELOG.md +10 -0
- package/dist/index.d.mts +39 -5
- package/dist/index.d.ts +39 -5
- package/dist/index.js +23 -7
- package/dist/index.mjs +23 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @codedazur/cdk-docker-cluster
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`5a3a979`](https://github.com/codedazur/toolkit/commit/5a3a979ed8de855f6ef4d410eed95db2230e0b2e) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Autoscaling thresholds and cooldowns can now be configured.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [`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.
|
|
12
|
+
|
|
3
13
|
## 1.0.0
|
|
4
14
|
|
|
5
15
|
### 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
|
@@ -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,7 +60,7 @@ 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
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
63
64
|
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;
|
|
64
65
|
const service = new import_aws_ecs_patterns.ApplicationLoadBalancedFargateService(this, "Service", {
|
|
65
66
|
cluster: new import_aws_ecs.Cluster(this, "Cluster"),
|
|
@@ -77,14 +78,29 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
77
78
|
rollback: true
|
|
78
79
|
}
|
|
79
80
|
});
|
|
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
81
|
return service;
|
|
87
82
|
}
|
|
83
|
+
createAutoScaling(service) {
|
|
84
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
85
|
+
if (typeof ((_a = this.props.service) == null ? void 0 : _a.tasks) !== "object") {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const autoScaling = service.service.autoScaleTaskCount({
|
|
89
|
+
minCapacity: (_b = this.props.service) == null ? void 0 : _b.tasks.minimum,
|
|
90
|
+
maxCapacity: (_c = this.props.service) == null ? void 0 : _c.tasks.maximum
|
|
91
|
+
});
|
|
92
|
+
autoScaling.scaleOnMemoryUtilization("MemoryScaling", {
|
|
93
|
+
targetUtilizationPercent: (_f = (_e = (_d = this.props.service) == null ? void 0 : _d.tasks.threshold) == null ? void 0 : _e.memory) != null ? _f : 75,
|
|
94
|
+
scaleInCooldown: (_h = (_g = this.props.service) == null ? void 0 : _g.tasks.cooldown) == null ? void 0 : _h.in,
|
|
95
|
+
scaleOutCooldown: (_j = (_i = this.props.service) == null ? void 0 : _i.tasks.cooldown) == null ? void 0 : _j.out
|
|
96
|
+
});
|
|
97
|
+
autoScaling.scaleOnCpuUtilization("CpuScaling", {
|
|
98
|
+
targetUtilizationPercent: (_m = (_l = (_k = this.props.service) == null ? void 0 : _k.tasks.threshold) == null ? void 0 : _l.cpu) != null ? _m : 75,
|
|
99
|
+
scaleInCooldown: (_o = (_n = this.props.service) == null ? void 0 : _n.tasks.cooldown) == null ? void 0 : _o.in,
|
|
100
|
+
scaleOutCooldown: (_q = (_p = this.props.service) == null ? void 0 : _p.tasks.cooldown) == null ? void 0 : _q.out
|
|
101
|
+
});
|
|
102
|
+
return autoScaling;
|
|
103
|
+
}
|
|
88
104
|
createSiteDistribution() {
|
|
89
105
|
return new import_cdk_site_distribution.SiteDistribution(this, "Distribution", {
|
|
90
106
|
allowedMethods: import_aws_cloudfront.AllowedMethods.ALLOW_ALL,
|
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,7 +44,7 @@ var DockerCluster = class extends Construct {
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
createService() {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
47
48
|
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;
|
|
48
49
|
const service = new ApplicationLoadBalancedFargateService(this, "Service", {
|
|
49
50
|
cluster: new Cluster(this, "Cluster"),
|
|
@@ -61,14 +62,29 @@ var DockerCluster = class extends Construct {
|
|
|
61
62
|
rollback: true
|
|
62
63
|
}
|
|
63
64
|
});
|
|
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
65
|
return service;
|
|
71
66
|
}
|
|
67
|
+
createAutoScaling(service) {
|
|
68
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
69
|
+
if (typeof ((_a = this.props.service) == null ? void 0 : _a.tasks) !== "object") {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const autoScaling = service.service.autoScaleTaskCount({
|
|
73
|
+
minCapacity: (_b = this.props.service) == null ? void 0 : _b.tasks.minimum,
|
|
74
|
+
maxCapacity: (_c = this.props.service) == null ? void 0 : _c.tasks.maximum
|
|
75
|
+
});
|
|
76
|
+
autoScaling.scaleOnMemoryUtilization("MemoryScaling", {
|
|
77
|
+
targetUtilizationPercent: (_f = (_e = (_d = this.props.service) == null ? void 0 : _d.tasks.threshold) == null ? void 0 : _e.memory) != null ? _f : 75,
|
|
78
|
+
scaleInCooldown: (_h = (_g = this.props.service) == null ? void 0 : _g.tasks.cooldown) == null ? void 0 : _h.in,
|
|
79
|
+
scaleOutCooldown: (_j = (_i = this.props.service) == null ? void 0 : _i.tasks.cooldown) == null ? void 0 : _j.out
|
|
80
|
+
});
|
|
81
|
+
autoScaling.scaleOnCpuUtilization("CpuScaling", {
|
|
82
|
+
targetUtilizationPercent: (_m = (_l = (_k = this.props.service) == null ? void 0 : _k.tasks.threshold) == null ? void 0 : _l.cpu) != null ? _m : 75,
|
|
83
|
+
scaleInCooldown: (_o = (_n = this.props.service) == null ? void 0 : _n.tasks.cooldown) == null ? void 0 : _o.in,
|
|
84
|
+
scaleOutCooldown: (_q = (_p = this.props.service) == null ? void 0 : _p.tasks.cooldown) == null ? void 0 : _q.out
|
|
85
|
+
});
|
|
86
|
+
return autoScaling;
|
|
87
|
+
}
|
|
72
88
|
createSiteDistribution() {
|
|
73
89
|
return new SiteDistribution(this, "Distribution", {
|
|
74
90
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|