@codedazur/cdk-docker-cluster 1.1.2 → 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 CHANGED
@@ -1,5 +1,16 @@
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
+
3
14
  ## 1.1.2
4
15
 
5
16
  ### Patch Changes
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
- var import_cdk_site_distribution = require("@codedazur/cdk-site-distribution");
29
- var import_aws_cdk_lib = require("aws-cdk-lib");
30
- var import_aws_cloudfront = require("aws-cdk-lib/aws-cloudfront");
31
- var import_aws_cloudfront_origins = require("aws-cdk-lib/aws-cloudfront-origins");
32
- var import_aws_ecr_assets = require("aws-cdk-lib/aws-ecr-assets");
33
- var import_aws_ecs = require("aws-cdk-lib/aws-ecs");
34
- var import_aws_ecs_patterns = require("aws-cdk-lib/aws-ecs-patterns");
35
- var import_constructs = require("constructs");
36
- var DockerCluster = class extends import_constructs.Construct {
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 import_aws_ecs.ContainerImage ? this.props.source : this.createImage(this.props.source);
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: import_aws_ecr_assets.Platform.LINUX_AMD64
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 import_aws_ecs.ContainerImage.fromAsset(source, props);
39
+ return ContainerImage.fromAsset(source, props);
54
40
  }
55
- return import_aws_ecs.ContainerImage.fromAsset(source.directory, {
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 import_aws_ecs_patterns.ApplicationLoadBalancedFargateService(this, "Service", {
65
- cluster: new import_aws_ecs.Cluster(this, "Cluster"),
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,
@@ -101,13 +87,13 @@ var DockerCluster = class extends import_constructs.Construct {
101
87
  }
102
88
  createSiteDistribution() {
103
89
  const { cachePolicy, originRequestPolicy, ...distribution } = this.props.distribution ?? {};
104
- return new import_cdk_site_distribution.SiteDistribution(this, "Distribution", {
105
- allowedMethods: import_aws_cloudfront.AllowedMethods.ALLOW_ALL,
90
+ return new SiteDistribution(this, "Distribution", {
91
+ allowedMethods: AllowedMethods.ALLOW_ALL,
106
92
  cachePolicy: cachePolicy ?? this.createCachePolicy(),
107
93
  originRequestPolicy: originRequestPolicy ?? this.createOriginRequestPolicy(),
108
94
  ...distribution,
109
- origin: new import_aws_cloudfront_origins.LoadBalancerV2Origin(this.service.loadBalancer, {
110
- protocolPolicy: import_aws_cloudfront.OriginProtocolPolicy.HTTP_ONLY
95
+ origin: new LoadBalancerV2Origin(this.service.loadBalancer, {
96
+ protocolPolicy: OriginProtocolPolicy.HTTP_ONLY
111
97
  })
112
98
  });
113
99
  }
@@ -119,7 +105,7 @@ var DockerCluster = class extends import_constructs.Construct {
119
105
  * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-policy-origin-cache-headers-query-strings
120
106
  */
121
107
  createCachePolicy() {
122
- return import_aws_cloudfront.CachePolicy.fromCachePolicyId(
108
+ return CachePolicy.fromCachePolicyId(
123
109
  this,
124
110
  "CachePolicy",
125
111
  "4cc15a8a-d715-48a4-82b8-cc0b614638fe" /* UseOriginCacheControlHeadersQueryStrings */
@@ -132,17 +118,16 @@ var DockerCluster = class extends import_constructs.Construct {
132
118
  * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-origin-request-policies.html#managed-origin-request-policy-all-viewer
133
119
  */
134
120
  createOriginRequestPolicy() {
135
- return import_aws_cloudfront.OriginRequestPolicy.fromOriginRequestPolicyId(
121
+ return OriginRequestPolicy.fromOriginRequestPolicyId(
136
122
  this,
137
123
  "OriginRequestPolicy",
138
124
  "216adef6-5c7f-47e4-b989-5492eafa07d3" /* AllViewer */
139
125
  );
140
126
  }
141
127
  getOutputDirectory() {
142
- return import_aws_cdk_lib.App.of(this)?.outdir ?? "cdk.out";
128
+ return App.of(this)?.outdir ?? "cdk.out";
143
129
  }
144
130
  };
145
- // Annotate the CommonJS export names for ESM import in node:
146
- 0 && (module.exports = {
131
+ export {
147
132
  DockerCluster
148
- });
133
+ };
package/eslint.config.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { cdk, distribution } from "@codedazur/eslint-config";
1
+ import { distribution } from "@codedazur/eslint-config";
2
+ import { cdk } from "@codedazur/eslint-config/cdk";
2
3
  import { defineConfig } from "eslint/config";
3
4
  import root from "../../eslint.config";
4
5
 
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
2
  "name": "@codedazur/cdk-docker-cluster",
3
- "version": "1.1.2",
4
- "main": ".dist/index.js",
5
- "module": "./dist/index.mjs",
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,cjs --dts --watch",
20
- "build": "tsup src/index.ts --format esm,cjs --dts",
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": "^1.0.2"
26
+ "@codedazur/cdk-site-distribution": "^2.0.0"
32
27
  },
33
28
  "devDependencies": {
34
- "@types/node": "^25.0.3",
35
- "aws-cdk-lib": "^2.233.0",
36
- "constructs": "^10.4.4",
29
+ "@types/node": "^25.0.9",
30
+ "aws-cdk-lib": "^2.235.1",
31
+ "constructs": "^10.4.5",
37
32
  "esbuild": "^0.27.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
- };