@codedazur/cdk-docker-cluster 1.1.1 → 2.0.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 +22 -0
- package/dist/index.d.ts +33 -16
- package/dist/index.js +65 -71
- package/eslint.config.ts +6 -0
- package/package.json +12 -17
- package/dist/index.d.mts +0 -82
- package/dist/index.mjs +0 -122
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @codedazur/cdk-docker-cluster
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`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.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`4f12708`](https://github.com/codedazur/toolkit/commit/4f12708f7b35ce7e96af62c10a6f637e347c3c69)]:
|
|
12
|
+
- @codedazur/cdk-site-distribution@2.0.0
|
|
13
|
+
|
|
14
|
+
## 1.1.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [`2734c9d`](https://github.com/codedazur/toolkit/commit/2734c9d2f1a6fbdbae8e7d676b1e06437200df23) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Props are now marked as readonly.
|
|
19
|
+
|
|
20
|
+
- [`62b823b`](https://github.com/codedazur/toolkit/commit/62b823bfb366f0b7b037b0485aafe7084fe3743f) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Following a CDK update, the cache policy and origin request policy are now created as constructs instead of using a simple object.
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`2734c9d`](https://github.com/codedazur/toolkit/commit/2734c9d2f1a6fbdbae8e7d676b1e06437200df23)]:
|
|
23
|
+
- @codedazur/cdk-site-distribution@1.0.2
|
|
24
|
+
|
|
3
25
|
## 1.1.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as aws_cdk_lib_aws_cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
1
2
|
import * as aws_cdk_lib_aws_ecs from 'aws-cdk-lib/aws-ecs';
|
|
2
3
|
import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
|
|
3
4
|
import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
|
|
@@ -6,16 +7,17 @@ import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFarg
|
|
|
6
7
|
import { Construct } from 'constructs';
|
|
7
8
|
|
|
8
9
|
interface DockerClusterProps {
|
|
9
|
-
source: string | SourceProps | ContainerImage;
|
|
10
|
-
service?:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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>;
|
|
19
21
|
}
|
|
20
22
|
interface AutoScalingConfig {
|
|
21
23
|
/**
|
|
@@ -52,11 +54,11 @@ interface AutoScalingConfig {
|
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
interface SourceProps {
|
|
55
|
-
directory: string;
|
|
56
|
-
exclude?: string[];
|
|
57
|
-
file?: string;
|
|
58
|
-
arguments?: Record<string, string>;
|
|
59
|
-
secrets?: Record<string, string>;
|
|
57
|
+
readonly directory: string;
|
|
58
|
+
readonly exclude?: string[];
|
|
59
|
+
readonly file?: string;
|
|
60
|
+
readonly arguments?: Record<string, string>;
|
|
61
|
+
readonly secrets?: Record<string, string>;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* An Docker cluster on a load balanced Fargate service on EC2, using an image
|
|
@@ -76,7 +78,22 @@ declare class DockerCluster extends Construct {
|
|
|
76
78
|
protected createService(): ApplicationLoadBalancedFargateService;
|
|
77
79
|
protected createAutoScaling(service: ApplicationLoadBalancedFargateService): ScalableTaskCount | undefined;
|
|
78
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;
|
|
79
96
|
protected getOutputDirectory(): string;
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
export { DockerCluster, type DockerClusterProps };
|
|
99
|
+
export { 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,8 @@ 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"),
|
|
66
52
|
cpu: this.props.service?.cpu,
|
|
67
53
|
memoryLimitMiB: this.props.service?.memory,
|
|
68
54
|
desiredCount: desiredTasks,
|
|
@@ -100,40 +86,48 @@ var DockerCluster = class extends import_constructs.Construct {
|
|
|
100
86
|
return autoScaling;
|
|
101
87
|
}
|
|
102
88
|
createSiteDistribution() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* key.
|
|
112
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
|
|
113
|
-
*/
|
|
114
|
-
cachePolicyId: "4cc15a8a-d715-48a4-82b8-cc0b614638fe"
|
|
115
|
-
},
|
|
116
|
-
originRequestPolicy: {
|
|
117
|
-
/**
|
|
118
|
-
* The managed "AllViewer" origin request policy, which includes all
|
|
119
|
-
* values (query strings, headers, and cookies) in the viewer request,
|
|
120
|
-
* which is recommended for use with an Application Load Balancer
|
|
121
|
-
* endpoint.
|
|
122
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
|
|
123
|
-
*/
|
|
124
|
-
originRequestPolicyId: "216adef6-5c7f-47e4-b989-5492eafa07d3"
|
|
125
|
-
},
|
|
126
|
-
...this.props.distribution,
|
|
127
|
-
origin: new import_aws_cloudfront_origins.LoadBalancerV2Origin(this.service.loadBalancer, {
|
|
128
|
-
protocolPolicy: import_aws_cloudfront.OriginProtocolPolicy.HTTP_ONLY
|
|
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
|
|
129
97
|
})
|
|
130
98
|
});
|
|
131
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
|
+
}
|
|
132
127
|
getOutputDirectory() {
|
|
133
|
-
return
|
|
128
|
+
return App.of(this)?.outdir ?? "cdk.out";
|
|
134
129
|
}
|
|
135
130
|
};
|
|
136
|
-
|
|
137
|
-
0 && (module.exports = {
|
|
131
|
+
export {
|
|
138
132
|
DockerCluster
|
|
139
|
-
}
|
|
133
|
+
};
|
package/eslint.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codedazur/cdk-docker-cluster",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.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
|
-
"lint": "
|
|
17
|
+
"lint": "eslint .",
|
|
23
18
|
"types": "tsc --noEmit",
|
|
24
19
|
"test": "vitest run --passWithNoTests"
|
|
25
20
|
},
|
|
@@ -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": "^
|
|
35
|
-
"aws-cdk-lib": "^2.
|
|
36
|
-
"constructs": "^10.4.
|
|
37
|
-
"esbuild": "^0.
|
|
29
|
+
"@types/node": "^25.0.9",
|
|
30
|
+
"aws-cdk-lib": "^2.235.1",
|
|
31
|
+
"constructs": "^10.4.5",
|
|
32
|
+
"esbuild": "^0.27.2"
|
|
38
33
|
}
|
|
39
34
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as aws_cdk_lib_aws_ecs from 'aws-cdk-lib/aws-ecs';
|
|
2
|
-
import { ContainerImage, Secret, ScalableTaskCount } from 'aws-cdk-lib/aws-ecs';
|
|
3
|
-
import { SiteDistributionProps, SiteDistribution } from '@codedazur/cdk-site-distribution';
|
|
4
|
-
import { Duration } from 'aws-cdk-lib';
|
|
5
|
-
import { ApplicationLoadBalancedFargateServiceProps, ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
|
|
6
|
-
import { Construct } from 'constructs';
|
|
7
|
-
|
|
8
|
-
interface DockerClusterProps {
|
|
9
|
-
source: string | SourceProps | ContainerImage;
|
|
10
|
-
service?: {
|
|
11
|
-
port?: number;
|
|
12
|
-
tasks?: number | AutoScalingConfig;
|
|
13
|
-
cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"];
|
|
14
|
-
memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
|
|
15
|
-
environment?: Record<string, string>;
|
|
16
|
-
secrets?: Record<string, Secret>;
|
|
17
|
-
};
|
|
18
|
-
distribution?: Omit<SiteDistributionProps, "origin">;
|
|
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
|
-
}
|
|
54
|
-
interface SourceProps {
|
|
55
|
-
directory: string;
|
|
56
|
-
exclude?: string[];
|
|
57
|
-
file?: string;
|
|
58
|
-
arguments?: Record<string, string>;
|
|
59
|
-
secrets?: Record<string, string>;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* An Docker cluster on a load balanced Fargate service on EC2, using an image
|
|
63
|
-
* built from a Dockerfile in a directory and pushed to ECR.
|
|
64
|
-
* @todo Make the distribution and load balancer optional, to reduce cost and
|
|
65
|
-
* increase deployment speed for development environments.
|
|
66
|
-
*/
|
|
67
|
-
declare class DockerCluster extends Construct {
|
|
68
|
-
protected readonly props: DockerClusterProps;
|
|
69
|
-
readonly domain?: string;
|
|
70
|
-
readonly image: ContainerImage;
|
|
71
|
-
readonly service: ApplicationLoadBalancedFargateService;
|
|
72
|
-
readonly autoScaling?: ScalableTaskCount;
|
|
73
|
-
readonly siteDistribution: SiteDistribution;
|
|
74
|
-
constructor(scope: Construct, id: string, props: DockerClusterProps);
|
|
75
|
-
protected createImage(source: string | SourceProps): aws_cdk_lib_aws_ecs.AssetImage;
|
|
76
|
-
protected createService(): ApplicationLoadBalancedFargateService;
|
|
77
|
-
protected createAutoScaling(service: ApplicationLoadBalancedFargateService): ScalableTaskCount | undefined;
|
|
78
|
-
protected createSiteDistribution(): SiteDistribution;
|
|
79
|
-
protected getOutputDirectory(): string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { DockerCluster, type DockerClusterProps };
|
package/dist/index.mjs
DELETED
|
@@ -1,122 +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
|
-
OriginProtocolPolicy
|
|
9
|
-
} from "aws-cdk-lib/aws-cloudfront";
|
|
10
|
-
import { LoadBalancerV2Origin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
11
|
-
import { Platform } from "aws-cdk-lib/aws-ecr-assets";
|
|
12
|
-
import {
|
|
13
|
-
Cluster,
|
|
14
|
-
ContainerImage
|
|
15
|
-
} from "aws-cdk-lib/aws-ecs";
|
|
16
|
-
import {
|
|
17
|
-
ApplicationLoadBalancedFargateService
|
|
18
|
-
} from "aws-cdk-lib/aws-ecs-patterns";
|
|
19
|
-
import { Construct } from "constructs";
|
|
20
|
-
var DockerCluster = class extends Construct {
|
|
21
|
-
constructor(scope, id, props) {
|
|
22
|
-
super(scope, id);
|
|
23
|
-
this.props = props;
|
|
24
|
-
this.image = this.props.source instanceof ContainerImage ? this.props.source : this.createImage(this.props.source);
|
|
25
|
-
this.service = this.createService();
|
|
26
|
-
this.autoScaling = this.createAutoScaling(this.service);
|
|
27
|
-
this.siteDistribution = this.createSiteDistribution();
|
|
28
|
-
}
|
|
29
|
-
createImage(source) {
|
|
30
|
-
const props = {
|
|
31
|
-
exclude: [`**/${this.getOutputDirectory()}`],
|
|
32
|
-
platform: Platform.LINUX_AMD64
|
|
33
|
-
// networkMode: NetworkMode.HOST, // @todo Use the host network mode.
|
|
34
|
-
// cacheFrom: [], // @todo Use the previously built image as a cache.
|
|
35
|
-
};
|
|
36
|
-
if (typeof source === "string") {
|
|
37
|
-
return ContainerImage.fromAsset(source, props);
|
|
38
|
-
}
|
|
39
|
-
return ContainerImage.fromAsset(source.directory, {
|
|
40
|
-
...props,
|
|
41
|
-
file: source.file,
|
|
42
|
-
buildArgs: source.arguments,
|
|
43
|
-
buildSecrets: source.secrets
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
createService() {
|
|
47
|
-
const desiredTasks = typeof this.props.service?.tasks === "number" ? this.props.service?.tasks : this.props.service?.tasks?.minimum;
|
|
48
|
-
const service = new ApplicationLoadBalancedFargateService(this, "Service", {
|
|
49
|
-
cluster: new Cluster(this, "Cluster"),
|
|
50
|
-
cpu: this.props.service?.cpu,
|
|
51
|
-
memoryLimitMiB: this.props.service?.memory,
|
|
52
|
-
desiredCount: desiredTasks,
|
|
53
|
-
taskImageOptions: {
|
|
54
|
-
image: this.image,
|
|
55
|
-
containerPort: this.props.service?.port,
|
|
56
|
-
environment: this.props.service?.environment,
|
|
57
|
-
secrets: this.props.service?.secrets
|
|
58
|
-
},
|
|
59
|
-
circuitBreaker: {
|
|
60
|
-
enable: true,
|
|
61
|
-
rollback: true
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return service;
|
|
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
|
-
}
|
|
86
|
-
createSiteDistribution() {
|
|
87
|
-
return new SiteDistribution(this, "Distribution", {
|
|
88
|
-
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
89
|
-
cachePolicy: {
|
|
90
|
-
/**
|
|
91
|
-
* The managed "UseOriginCacheControlHeaders-QueryStrings" cache policy,
|
|
92
|
-
* which is designed for use with an origin that sends Cache-Control
|
|
93
|
-
* headers with the object, which is recommended for use with an
|
|
94
|
-
* Application Load Balancer, and includes query strings in the cache
|
|
95
|
-
* key.
|
|
96
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
|
|
97
|
-
*/
|
|
98
|
-
cachePolicyId: "4cc15a8a-d715-48a4-82b8-cc0b614638fe"
|
|
99
|
-
},
|
|
100
|
-
originRequestPolicy: {
|
|
101
|
-
/**
|
|
102
|
-
* The managed "AllViewer" origin request policy, which includes all
|
|
103
|
-
* values (query strings, headers, and cookies) in the viewer request,
|
|
104
|
-
* which is recommended for use with an Application Load Balancer
|
|
105
|
-
* endpoint.
|
|
106
|
-
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
|
|
107
|
-
*/
|
|
108
|
-
originRequestPolicyId: "216adef6-5c7f-47e4-b989-5492eafa07d3"
|
|
109
|
-
},
|
|
110
|
-
...this.props.distribution,
|
|
111
|
-
origin: new LoadBalancerV2Origin(this.service.loadBalancer, {
|
|
112
|
-
protocolPolicy: OriginProtocolPolicy.HTTP_ONLY
|
|
113
|
-
})
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
getOutputDirectory() {
|
|
117
|
-
return App.of(this)?.outdir ?? "cdk.out";
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
export {
|
|
121
|
-
DockerCluster
|
|
122
|
-
};
|