@codedazur/cdk-docker-cluster 1.1.2 → 2.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 +17 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +41 -51
- package/eslint.config.ts +2 -1
- package/package.json +11 -16
- package/dist/index.d.mts +0 -99
- package/dist/index.mjs +0 -133
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @codedazur/cdk-docker-cluster
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`f361c4c`](https://github.com/codedazur/toolkit/commit/f361c4cbf2974360c9eeec0feb04c9c2cc33b730) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Add support for Container Insights on ECS clusters (`cluster.containerInsights`) and custom health checks on ALB target groups (`service.healthCheck`).
|
|
8
|
+
|
|
9
|
+
## 2.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [`4f12708`](https://github.com/codedazur/toolkit/commit/4f12708f7b35ce7e96af62c10a6f637e347c3c69) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Custom domain names with external DNS registry are now supported. A HostedZone will no longer be looked up and must be provided instead if needed.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`4f12708`](https://github.com/codedazur/toolkit/commit/4f12708f7b35ce7e96af62c10a6f637e347c3c69)]:
|
|
18
|
+
- @codedazur/cdk-site-distribution@2.0.0
|
|
19
|
+
|
|
3
20
|
## 1.1.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,21 @@ import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
|
|
|
4
4
|
import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
|
|
5
5
|
import { Duration } from 'aws-cdk-lib';
|
|
6
6
|
import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
|
|
7
|
+
import { HealthCheck } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
|
|
7
8
|
import { Construct } from 'constructs';
|
|
8
9
|
|
|
10
|
+
interface ClusterConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Enable CloudWatch Container Insights for the ECS Cluster.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
readonly containerInsights?: boolean;
|
|
16
|
+
}
|
|
9
17
|
interface DockerClusterProps {
|
|
10
18
|
readonly source: string | SourceProps | ContainerImage;
|
|
11
19
|
readonly service?: ServiceProps;
|
|
12
20
|
readonly distribution?: Omit<SiteDistributionProps, "origin">;
|
|
21
|
+
readonly cluster?: ClusterConfig;
|
|
13
22
|
}
|
|
14
23
|
interface ServiceProps {
|
|
15
24
|
readonly port?: number;
|
|
@@ -18,6 +27,10 @@ interface ServiceProps {
|
|
|
18
27
|
readonly memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
|
|
19
28
|
readonly environment?: Record<string, string>;
|
|
20
29
|
readonly secrets?: Record<string, Secret>;
|
|
30
|
+
/**
|
|
31
|
+
* Health check configuration for the Application Load Balancer target group.
|
|
32
|
+
*/
|
|
33
|
+
readonly healthCheck?: HealthCheck;
|
|
21
34
|
}
|
|
22
35
|
interface AutoScalingConfig {
|
|
23
36
|
/**
|
|
@@ -96,4 +109,4 @@ declare class DockerCluster extends Construct {
|
|
|
96
109
|
protected getOutputDirectory(): string;
|
|
97
110
|
}
|
|
98
111
|
|
|
99
|
-
export { DockerCluster, type DockerClusterProps, type ServiceProps };
|
|
112
|
+
export { type ClusterConfig, DockerCluster, type DockerClusterProps, type ServiceProps };
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
DockerCluster: () => DockerCluster
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
|
|
27
1
|
// src/constructs/DockerCluster.ts
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
import {
|
|
3
|
+
SiteDistribution
|
|
4
|
+
} from "@codedazur/cdk-site-distribution";
|
|
5
|
+
import { App } from "aws-cdk-lib";
|
|
6
|
+
import {
|
|
7
|
+
AllowedMethods,
|
|
8
|
+
CachePolicy,
|
|
9
|
+
OriginProtocolPolicy,
|
|
10
|
+
OriginRequestPolicy
|
|
11
|
+
} from "aws-cdk-lib/aws-cloudfront";
|
|
12
|
+
import { LoadBalancerV2Origin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
13
|
+
import { Platform } from "aws-cdk-lib/aws-ecr-assets";
|
|
14
|
+
import {
|
|
15
|
+
Cluster,
|
|
16
|
+
ContainerImage
|
|
17
|
+
} from "aws-cdk-lib/aws-ecs";
|
|
18
|
+
import {
|
|
19
|
+
ApplicationLoadBalancedFargateService
|
|
20
|
+
} from "aws-cdk-lib/aws-ecs-patterns";
|
|
21
|
+
import { Construct } from "constructs";
|
|
22
|
+
var DockerCluster = class extends Construct {
|
|
37
23
|
constructor(scope, id, props) {
|
|
38
24
|
super(scope, id);
|
|
39
25
|
this.props = props;
|
|
40
|
-
this.image = this.props.source instanceof
|
|
26
|
+
this.image = this.props.source instanceof ContainerImage ? this.props.source : this.createImage(this.props.source);
|
|
41
27
|
this.service = this.createService();
|
|
42
28
|
this.autoScaling = this.createAutoScaling(this.service);
|
|
43
29
|
this.siteDistribution = this.createSiteDistribution();
|
|
@@ -45,14 +31,14 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
45
31
|
createImage(source) {
|
|
46
32
|
const props = {
|
|
47
33
|
exclude: [`**/${this.getOutputDirectory()}`],
|
|
48
|
-
platform:
|
|
34
|
+
platform: Platform.LINUX_AMD64
|
|
49
35
|
// networkMode: NetworkMode.HOST, // @todo Use the host network mode.
|
|
50
36
|
// cacheFrom: [], // @todo Use the previously built image as a cache.
|
|
51
37
|
};
|
|
52
38
|
if (typeof source === "string") {
|
|
53
|
-
return
|
|
39
|
+
return ContainerImage.fromAsset(source, props);
|
|
54
40
|
}
|
|
55
|
-
return
|
|
41
|
+
return ContainerImage.fromAsset(source.directory, {
|
|
56
42
|
...props,
|
|
57
43
|
file: source.file,
|
|
58
44
|
buildArgs: source.arguments,
|
|
@@ -61,8 +47,10 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
61
47
|
}
|
|
62
48
|
createService() {
|
|
63
49
|
const desiredTasks = typeof this.props.service?.tasks === "number" ? this.props.service?.tasks : this.props.service?.tasks?.minimum;
|
|
64
|
-
const service = new
|
|
65
|
-
cluster: new
|
|
50
|
+
const service = new ApplicationLoadBalancedFargateService(this, "Service", {
|
|
51
|
+
cluster: new Cluster(this, "Cluster", {
|
|
52
|
+
containerInsights: this.props.cluster?.containerInsights
|
|
53
|
+
}),
|
|
66
54
|
cpu: this.props.service?.cpu,
|
|
67
55
|
memoryLimitMiB: this.props.service?.memory,
|
|
68
56
|
desiredCount: desiredTasks,
|
|
@@ -77,6 +65,9 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
77
65
|
rollback: true
|
|
78
66
|
}
|
|
79
67
|
});
|
|
68
|
+
if (this.props.service?.healthCheck) {
|
|
69
|
+
service.targetGroup.configureHealthCheck(this.props.service.healthCheck);
|
|
70
|
+
}
|
|
80
71
|
return service;
|
|
81
72
|
}
|
|
82
73
|
createAutoScaling(service) {
|
|
@@ -101,13 +92,13 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
101
92
|
}
|
|
102
93
|
createSiteDistribution() {
|
|
103
94
|
const { cachePolicy, originRequestPolicy, ...distribution } = this.props.distribution ?? {};
|
|
104
|
-
return new
|
|
105
|
-
allowedMethods:
|
|
95
|
+
return new SiteDistribution(this, "Distribution", {
|
|
96
|
+
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
106
97
|
cachePolicy: cachePolicy ?? this.createCachePolicy(),
|
|
107
98
|
originRequestPolicy: originRequestPolicy ?? this.createOriginRequestPolicy(),
|
|
108
99
|
...distribution,
|
|
109
|
-
origin: new
|
|
110
|
-
protocolPolicy:
|
|
100
|
+
origin: new LoadBalancerV2Origin(this.service.loadBalancer, {
|
|
101
|
+
protocolPolicy: OriginProtocolPolicy.HTTP_ONLY
|
|
111
102
|
})
|
|
112
103
|
});
|
|
113
104
|
}
|
|
@@ -119,7 +110,7 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
119
110
|
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
|
|
120
111
|
*/
|
|
121
112
|
createCachePolicy() {
|
|
122
|
-
return
|
|
113
|
+
return CachePolicy.fromCachePolicyId(
|
|
123
114
|
this,
|
|
124
115
|
"CachePolicy",
|
|
125
116
|
"4cc15a8a-d715-48a4-82b8-cc0b614638fe" /* UseOriginCacheControlHeadersQueryStrings */
|
|
@@ -132,17 +123,16 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
132
123
|
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
|
|
133
124
|
*/
|
|
134
125
|
createOriginRequestPolicy() {
|
|
135
|
-
return
|
|
126
|
+
return OriginRequestPolicy.fromOriginRequestPolicyId(
|
|
136
127
|
this,
|
|
137
128
|
"OriginRequestPolicy",
|
|
138
129
|
"216adef6-5c7f-47e4-b989-5492eafa07d3" /* AllViewer */
|
|
139
130
|
);
|
|
140
131
|
}
|
|
141
132
|
getOutputDirectory() {
|
|
142
|
-
return
|
|
133
|
+
return App.of(this)?.outdir ?? "cdk.out";
|
|
143
134
|
}
|
|
144
135
|
};
|
|
145
|
-
|
|
146
|
-
0 && (module.exports = {
|
|
136
|
+
export {
|
|
147
137
|
DockerCluster
|
|
148
|
-
}
|
|
138
|
+
};
|
package/eslint.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codedazur/cdk-docker-cluster",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports":
|
|
8
|
-
".": {
|
|
9
|
-
"require": "./dist/index.js",
|
|
10
|
-
"import": "./dist/index.mjs"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
7
|
+
"exports": "./dist/index.js",
|
|
13
8
|
"publishConfig": {
|
|
14
9
|
"access": "public"
|
|
15
10
|
},
|
|
16
11
|
"license": "MIT",
|
|
17
12
|
"sideEffects": false,
|
|
18
13
|
"scripts": {
|
|
19
|
-
"develop": "tsup src/index.ts --format esm
|
|
20
|
-
"build": "tsup src/index.ts --format esm
|
|
14
|
+
"develop": "tsup src/index.ts --clean --format esm --dts --watch",
|
|
15
|
+
"build": "tsup src/index.ts --clean --format esm --dts",
|
|
21
16
|
"audit": "npm audit --omit dev --audit-level high",
|
|
22
17
|
"lint": "eslint .",
|
|
23
18
|
"types": "tsc --noEmit",
|
|
@@ -28,12 +23,12 @@
|
|
|
28
23
|
"constructs": ">=10"
|
|
29
24
|
},
|
|
30
25
|
"dependencies": {
|
|
31
|
-
"@codedazur/cdk-site-distribution": "
|
|
26
|
+
"@codedazur/cdk-site-distribution": "~2.0.0"
|
|
32
27
|
},
|
|
33
28
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^25.
|
|
35
|
-
"aws-cdk-lib": "^2.
|
|
36
|
-
"constructs": "^10.
|
|
37
|
-
"esbuild": "^0.
|
|
29
|
+
"@types/node": "^25.9.1",
|
|
30
|
+
"aws-cdk-lib": "^2.268.0",
|
|
31
|
+
"constructs": "^10.8.1",
|
|
32
|
+
"esbuild": "^0.28.2"
|
|
38
33
|
}
|
|
39
34
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import * as aws_cdk_lib_aws_cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
2
|
-
import * as aws_cdk_lib_aws_ecs from 'aws-cdk-lib/aws-ecs';
|
|
3
|
-
import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
|
|
4
|
-
import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
|
|
5
|
-
import { Duration } from 'aws-cdk-lib';
|
|
6
|
-
import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
|
|
7
|
-
import { Construct } from 'constructs';
|
|
8
|
-
|
|
9
|
-
interface DockerClusterProps {
|
|
10
|
-
readonly source: string | SourceProps | ContainerImage;
|
|
11
|
-
readonly service?: ServiceProps;
|
|
12
|
-
readonly distribution?: Omit<SiteDistributionProps, "origin">;
|
|
13
|
-
}
|
|
14
|
-
interface ServiceProps {
|
|
15
|
-
readonly port?: number;
|
|
16
|
-
readonly tasks?: number | AutoScalingConfig;
|
|
17
|
-
readonly cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"];
|
|
18
|
-
readonly memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
|
|
19
|
-
readonly environment?: Record<string, string>;
|
|
20
|
-
readonly secrets?: Record<string, Secret>;
|
|
21
|
-
}
|
|
22
|
-
interface AutoScalingConfig {
|
|
23
|
-
/**
|
|
24
|
-
* The minimum number of tasks to scale out to.
|
|
25
|
-
*/
|
|
26
|
-
minimum: number;
|
|
27
|
-
/**
|
|
28
|
-
* The maximum number of tasks to scale out to.
|
|
29
|
-
*/
|
|
30
|
-
maximum: number;
|
|
31
|
-
threshold?: {
|
|
32
|
-
/**
|
|
33
|
-
* The memory utilization percentage above which the service will scale out.
|
|
34
|
-
* @default 75
|
|
35
|
-
*/
|
|
36
|
-
memory?: number;
|
|
37
|
-
/**
|
|
38
|
-
* The CPU utilization percentage above which the service will scale out.
|
|
39
|
-
* @default 75
|
|
40
|
-
*/
|
|
41
|
-
cpu?: number;
|
|
42
|
-
};
|
|
43
|
-
cooldown?: {
|
|
44
|
-
/**
|
|
45
|
-
* The cooldown period for scaling in.
|
|
46
|
-
* @default Duration.seconds(300)
|
|
47
|
-
*/
|
|
48
|
-
in?: Duration;
|
|
49
|
-
/**
|
|
50
|
-
* The cooldown period for scaling out.
|
|
51
|
-
* @default Duration.seconds(300)
|
|
52
|
-
*/
|
|
53
|
-
out?: Duration;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
interface SourceProps {
|
|
57
|
-
readonly directory: string;
|
|
58
|
-
readonly exclude?: string[];
|
|
59
|
-
readonly file?: string;
|
|
60
|
-
readonly arguments?: Record<string, string>;
|
|
61
|
-
readonly secrets?: Record<string, string>;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* An Docker cluster on a load balanced Fargate service on EC2, using an image
|
|
65
|
-
* built from a Dockerfile in a directory and pushed to ECR.
|
|
66
|
-
* @todo Make the distribution and load balancer optional, to reduce cost and
|
|
67
|
-
* increase deployment speed for development environments.
|
|
68
|
-
*/
|
|
69
|
-
declare class DockerCluster extends Construct {
|
|
70
|
-
protected readonly props: DockerClusterProps;
|
|
71
|
-
readonly domain?: string;
|
|
72
|
-
readonly image: ContainerImage;
|
|
73
|
-
readonly service: ApplicationLoadBalancedFargateService;
|
|
74
|
-
readonly autoScaling?: ScalableTaskCount;
|
|
75
|
-
readonly siteDistribution: SiteDistribution;
|
|
76
|
-
constructor(scope: Construct, id: string, props: DockerClusterProps);
|
|
77
|
-
protected createImage(source: string | SourceProps): aws_cdk_lib_aws_ecs.AssetImage;
|
|
78
|
-
protected createService(): ApplicationLoadBalancedFargateService;
|
|
79
|
-
protected createAutoScaling(service: ApplicationLoadBalancedFargateService): ScalableTaskCount | undefined;
|
|
80
|
-
protected createSiteDistribution(): SiteDistribution;
|
|
81
|
-
/**
|
|
82
|
-
* The managed "UseOriginCacheControlHeaders-QueryStrings" cache policy, which
|
|
83
|
-
* is designed for use with an origin that sends Cache-Control headers with
|
|
84
|
-
* the object, which is recommended for use with an Application Load Balancer,
|
|
85
|
-
* and includes query strings in the cache key.
|
|
86
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
|
|
87
|
-
*/
|
|
88
|
-
protected createCachePolicy(): aws_cdk_lib_aws_cloudfront.ICachePolicy;
|
|
89
|
-
/**
|
|
90
|
-
* The managed "AllViewer" origin request policy, which includes all values
|
|
91
|
-
* (query strings, headers, and cookies) in the viewer request, which is
|
|
92
|
-
* recommended for use with an Application Load Balancer endpoint.
|
|
93
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
|
|
94
|
-
*/
|
|
95
|
-
protected createOriginRequestPolicy(): aws_cdk_lib_aws_cloudfront.IOriginRequestPolicy;
|
|
96
|
-
protected getOutputDirectory(): string;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export { DockerCluster, type DockerClusterProps, type ServiceProps };
|
package/dist/index.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// src/constructs/DockerCluster.ts
|
|
2
|
-
import {
|
|
3
|
-
SiteDistribution
|
|
4
|
-
} from "@codedazur/cdk-site-distribution";
|
|
5
|
-
import { App } from "aws-cdk-lib";
|
|
6
|
-
import {
|
|
7
|
-
AllowedMethods,
|
|
8
|
-
CachePolicy,
|
|
9
|
-
OriginProtocolPolicy,
|
|
10
|
-
OriginRequestPolicy
|
|
11
|
-
} from "aws-cdk-lib/aws-cloudfront";
|
|
12
|
-
import { LoadBalancerV2Origin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
13
|
-
import { Platform } from "aws-cdk-lib/aws-ecr-assets";
|
|
14
|
-
import {
|
|
15
|
-
Cluster,
|
|
16
|
-
ContainerImage
|
|
17
|
-
} from "aws-cdk-lib/aws-ecs";
|
|
18
|
-
import {
|
|
19
|
-
ApplicationLoadBalancedFargateService
|
|
20
|
-
} from "aws-cdk-lib/aws-ecs-patterns";
|
|
21
|
-
import { Construct } from "constructs";
|
|
22
|
-
var DockerCluster = class extends Construct {
|
|
23
|
-
constructor(scope, id, props) {
|
|
24
|
-
super(scope, id);
|
|
25
|
-
this.props = props;
|
|
26
|
-
this.image = this.props.source instanceof ContainerImage ? this.props.source : this.createImage(this.props.source);
|
|
27
|
-
this.service = this.createService();
|
|
28
|
-
this.autoScaling = this.createAutoScaling(this.service);
|
|
29
|
-
this.siteDistribution = this.createSiteDistribution();
|
|
30
|
-
}
|
|
31
|
-
createImage(source) {
|
|
32
|
-
const props = {
|
|
33
|
-
exclude: [`**/${this.getOutputDirectory()}`],
|
|
34
|
-
platform: Platform.LINUX_AMD64
|
|
35
|
-
// networkMode: NetworkMode.HOST, // @todo Use the host network mode.
|
|
36
|
-
// cacheFrom: [], // @todo Use the previously built image as a cache.
|
|
37
|
-
};
|
|
38
|
-
if (typeof source === "string") {
|
|
39
|
-
return ContainerImage.fromAsset(source, props);
|
|
40
|
-
}
|
|
41
|
-
return ContainerImage.fromAsset(source.directory, {
|
|
42
|
-
...props,
|
|
43
|
-
file: source.file,
|
|
44
|
-
buildArgs: source.arguments,
|
|
45
|
-
buildSecrets: source.secrets
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
createService() {
|
|
49
|
-
const desiredTasks = typeof this.props.service?.tasks === "number" ? this.props.service?.tasks : this.props.service?.tasks?.minimum;
|
|
50
|
-
const service = new ApplicationLoadBalancedFargateService(this, "Service", {
|
|
51
|
-
cluster: new Cluster(this, "Cluster"),
|
|
52
|
-
cpu: this.props.service?.cpu,
|
|
53
|
-
memoryLimitMiB: this.props.service?.memory,
|
|
54
|
-
desiredCount: desiredTasks,
|
|
55
|
-
taskImageOptions: {
|
|
56
|
-
image: this.image,
|
|
57
|
-
containerPort: this.props.service?.port,
|
|
58
|
-
environment: this.props.service?.environment,
|
|
59
|
-
secrets: this.props.service?.secrets
|
|
60
|
-
},
|
|
61
|
-
circuitBreaker: {
|
|
62
|
-
enable: true,
|
|
63
|
-
rollback: true
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return service;
|
|
67
|
-
}
|
|
68
|
-
createAutoScaling(service) {
|
|
69
|
-
if (typeof this.props.service?.tasks !== "object") {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const autoScaling = service.service.autoScaleTaskCount({
|
|
73
|
-
minCapacity: this.props.service?.tasks.minimum,
|
|
74
|
-
maxCapacity: this.props.service?.tasks.maximum
|
|
75
|
-
});
|
|
76
|
-
autoScaling.scaleOnMemoryUtilization("MemoryScaling", {
|
|
77
|
-
targetUtilizationPercent: this.props.service?.tasks.threshold?.memory ?? 75,
|
|
78
|
-
scaleInCooldown: this.props.service?.tasks.cooldown?.in,
|
|
79
|
-
scaleOutCooldown: this.props.service?.tasks.cooldown?.out
|
|
80
|
-
});
|
|
81
|
-
autoScaling.scaleOnCpuUtilization("CpuScaling", {
|
|
82
|
-
targetUtilizationPercent: this.props.service?.tasks.threshold?.cpu ?? 75,
|
|
83
|
-
scaleInCooldown: this.props.service?.tasks.cooldown?.in,
|
|
84
|
-
scaleOutCooldown: this.props.service?.tasks.cooldown?.out
|
|
85
|
-
});
|
|
86
|
-
return autoScaling;
|
|
87
|
-
}
|
|
88
|
-
createSiteDistribution() {
|
|
89
|
-
const { cachePolicy, originRequestPolicy, ...distribution } = this.props.distribution ?? {};
|
|
90
|
-
return new SiteDistribution(this, "Distribution", {
|
|
91
|
-
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
92
|
-
cachePolicy: cachePolicy ?? this.createCachePolicy(),
|
|
93
|
-
originRequestPolicy: originRequestPolicy ?? this.createOriginRequestPolicy(),
|
|
94
|
-
...distribution,
|
|
95
|
-
origin: new LoadBalancerV2Origin(this.service.loadBalancer, {
|
|
96
|
-
protocolPolicy: OriginProtocolPolicy.HTTP_ONLY
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The managed "UseOriginCacheControlHeaders-QueryStrings" cache policy, which
|
|
102
|
-
* is designed for use with an origin that sends Cache-Control headers with
|
|
103
|
-
* the object, which is recommended for use with an Application Load Balancer,
|
|
104
|
-
* and includes query strings in the cache key.
|
|
105
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
|
|
106
|
-
*/
|
|
107
|
-
createCachePolicy() {
|
|
108
|
-
return CachePolicy.fromCachePolicyId(
|
|
109
|
-
this,
|
|
110
|
-
"CachePolicy",
|
|
111
|
-
"4cc15a8a-d715-48a4-82b8-cc0b614638fe" /* UseOriginCacheControlHeadersQueryStrings */
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The managed "AllViewer" origin request policy, which includes all values
|
|
116
|
-
* (query strings, headers, and cookies) in the viewer request, which is
|
|
117
|
-
* recommended for use with an Application Load Balancer endpoint.
|
|
118
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
|
|
119
|
-
*/
|
|
120
|
-
createOriginRequestPolicy() {
|
|
121
|
-
return OriginRequestPolicy.fromOriginRequestPolicyId(
|
|
122
|
-
this,
|
|
123
|
-
"OriginRequestPolicy",
|
|
124
|
-
"216adef6-5c7f-47e4-b989-5492eafa07d3" /* AllViewer */
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
getOutputDirectory() {
|
|
128
|
-
return App.of(this)?.outdir ?? "cdk.out";
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
export {
|
|
132
|
-
DockerCluster
|
|
133
|
-
};
|