@fy-stack/app-construct 0.0.141 → 0.0.143
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/dist/index.d.ts +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -15
- package/dist/lib/ecs/apps/image-app-construct.d.ts +17 -0
- package/dist/lib/ecs/apps/image-app-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/image-app-construct.js +55 -0
- package/dist/lib/ecs/apps/next-app-router-construct.d.ts +22 -0
- package/dist/lib/ecs/apps/next-app-router-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/next-app-router-construct.js +52 -0
- package/dist/lib/ecs/apps/task-construct.d.ts +16 -0
- package/dist/lib/ecs/apps/task-construct.d.ts.map +1 -0
- package/dist/lib/ecs/apps/task-construct.js +101 -0
- package/dist/lib/ecs/ecs-construct.d.ts +10 -0
- package/dist/lib/ecs/ecs-construct.d.ts.map +1 -0
- package/dist/lib/ecs/ecs-construct.js +42 -0
- package/dist/lib/ecs/ecs-server-construct.d.ts +28 -0
- package/dist/lib/ecs/ecs-server-construct.d.ts.map +1 -0
- package/dist/lib/ecs/ecs-server-construct.js +161 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.d.ts +13 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.d.ts.map +1 -0
- package/dist/lib/ecs/shared/taskDefinitionImage.js +27 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.d.ts +2 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.d.ts.map +1 -0
- package/dist/lib/ecs/shared/util/ecs-api-gateway.js +5 -0
- package/dist/lib/ecs/types.d.ts +89 -0
- package/dist/lib/ecs/types.d.ts.map +1 -0
- package/dist/lib/ecs/types.js +2 -0
- package/dist/lib/lambda/apps/image-app-construct.d.ts +68 -0
- package/dist/lib/lambda/apps/image-app-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/image-app-construct.js +92 -0
- package/dist/lib/lambda/apps/next-app-router-construct.d.ts +33 -0
- package/dist/lib/lambda/apps/next-app-router-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/next-app-router-construct.js +77 -0
- package/dist/lib/lambda/apps/node-api-construct.d.ts +43 -0
- package/dist/lib/lambda/apps/node-api-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/node-api-construct.js +91 -0
- package/dist/lib/lambda/apps/node-app-construct.d.ts +32 -0
- package/dist/lib/lambda/apps/node-app-construct.d.ts.map +1 -0
- package/dist/lib/lambda/apps/node-app-construct.js +73 -0
- package/dist/lib/lambda/lambda-construct.d.ts +7 -0
- package/dist/lib/lambda/lambda-construct.d.ts.map +1 -0
- package/dist/lib/lambda/lambda-construct.js +34 -0
- package/dist/lib/lambda/types.d.ts +32 -0
- package/dist/lib/lambda/types.d.ts.map +1 -0
- package/dist/lib/lambda/types.js +2 -0
- package/dist/lib/lambda/utils/getDefaultLambda.d.ts +8 -0
- package/dist/lib/lambda/utils/getDefaultLambda.d.ts.map +1 -0
- package/dist/lib/lambda/utils/getDefaultLambda.js +11 -0
- package/dist/lib/lambda/utils/lambda-api.d.ts +6 -0
- package/dist/lib/lambda/utils/lambda-api.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-api.js +17 -0
- package/dist/lib/lambda/utils/lambda-attach.d.ts +4 -0
- package/dist/lib/lambda/utils/lambda-attach.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-attach.js +11 -0
- package/dist/lib/lambda/utils/lambda-grant.d.ts +4 -0
- package/dist/lib/lambda/utils/lambda-grant.d.ts.map +1 -0
- package/dist/lib/lambda/utils/lambda-grant.js +8 -0
- package/dist/lib/next-app-router-construct.d.ts.map +1 -1
- package/dist/lib/next-app-router-construct.js +3 -2
- package/dist/lib/shared/next-app-router.d.ts +12 -0
- package/dist/lib/shared/next-app-router.d.ts.map +1 -0
- package/dist/lib/shared/next-app-router.js +87 -0
- package/dist/lib/shared/util/params-from-attachable.d.ts +5 -0
- package/dist/lib/shared/util/params-from-attachable.d.ts.map +1 -0
- package/dist/lib/shared/util/params-from-attachable.js +11 -0
- package/dist/lib/shared/util/types.d.ts +25 -0
- package/dist/lib/shared/util/types.d.ts.map +1 -0
- package/dist/lib/shared/util/types.js +20 -0
- package/dist/lib/static/apps/next-pages-export-construct.d.ts +16 -0
- package/dist/lib/static/apps/next-pages-export-construct.d.ts.map +1 -0
- package/dist/lib/static/apps/next-pages-export-construct.js +69 -0
- package/dist/lib/static/apps/static-website-construct.d.ts +16 -0
- package/dist/lib/static/apps/static-website-construct.d.ts.map +1 -0
- package/dist/lib/static/apps/static-website-construct.js +62 -0
- package/dist/lib/static/next-pages-export-construct.d.ts +21 -0
- package/dist/lib/static/next-pages-export-construct.d.ts.map +1 -0
- package/dist/lib/static/next-pages-export-construct.js +78 -0
- package/dist/lib/static/static-construct.d.ts +7 -0
- package/dist/lib/static/static-construct.d.ts.map +1 -0
- package/dist/lib/static/static-construct.js +28 -0
- package/dist/lib/static/static-website-construct.d.ts +21 -0
- package/dist/lib/static/static-website-construct.d.ts.map +1 -0
- package/dist/lib/static/static-website-construct.js +71 -0
- package/dist/lib/static/types.d.ts +16 -0
- package/dist/lib/static/types.d.ts.map +1 -0
- package/dist/lib/static/types.js +2 -0
- package/dist/lib/types.d.ts +9 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/util/params-from-attachable.d.ts +5 -0
- package/dist/lib/util/params-from-attachable.d.ts.map +1 -0
- package/dist/lib/util/params-from-attachable.js +11 -0
- package/dist/lib/util/strip-trailing-slash.d.ts +2 -0
- package/dist/lib/util/strip-trailing-slash.d.ts.map +1 -0
- package/dist/lib/util/strip-trailing-slash.js +6 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
9
|
-
export { lambdaGrant } from "./lib/utils/lambda-grant";
|
|
1
|
+
export { EcsConstruct } from './lib/ecs/ecs-construct';
|
|
2
|
+
export type { EcsConstructProps } from './lib/ecs/types';
|
|
3
|
+
export { LambdaConstruct } from './lib/lambda/lambda-construct';
|
|
4
|
+
export type { LambdaConstructProps } from './lib/lambda/types';
|
|
5
|
+
export { lambdaAttach } from './lib/lambda/utils/lambda-attach';
|
|
6
|
+
export { lambdaGrant } from './lib/lambda/utils/lambda-grant';
|
|
7
|
+
export { StaticConstruct } from './lib/static/static-construct';
|
|
8
|
+
export type { StaticConstructProps } from './lib/static/types';
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "NextPagesExportConstruct", { enumerable: true, get: function () { return next_pages_export_construct_1.NextPagesExportConstruct; } });
|
|
10
|
-
var node_api_construct_1 = require("./lib/node-api-construct");
|
|
11
|
-
Object.defineProperty(exports, "NodeApiConstruct", { enumerable: true, get: function () { return node_api_construct_1.NodeApiConstruct; } });
|
|
12
|
-
var node_app_construct_1 = require("./lib/node-app-construct");
|
|
13
|
-
Object.defineProperty(exports, "NodeAppConstruct", { enumerable: true, get: function () { return node_app_construct_1.NodeAppConstruct; } });
|
|
14
|
-
var static_website_construct_1 = require("./lib/static-website-construct");
|
|
15
|
-
Object.defineProperty(exports, "StaticWebsiteConstruct", { enumerable: true, get: function () { return static_website_construct_1.StaticWebsiteConstruct; } });
|
|
16
|
-
var lambda_attach_1 = require("./lib/utils/lambda-attach");
|
|
3
|
+
exports.StaticConstruct = exports.lambdaGrant = exports.lambdaAttach = exports.LambdaConstruct = exports.EcsConstruct = void 0;
|
|
4
|
+
var ecs_construct_1 = require("./lib/ecs/ecs-construct");
|
|
5
|
+
Object.defineProperty(exports, "EcsConstruct", { enumerable: true, get: function () { return ecs_construct_1.EcsConstruct; } });
|
|
6
|
+
var lambda_construct_1 = require("./lib/lambda/lambda-construct");
|
|
7
|
+
Object.defineProperty(exports, "LambdaConstruct", { enumerable: true, get: function () { return lambda_construct_1.LambdaConstruct; } });
|
|
8
|
+
var lambda_attach_1 = require("./lib/lambda/utils/lambda-attach");
|
|
17
9
|
Object.defineProperty(exports, "lambdaAttach", { enumerable: true, get: function () { return lambda_attach_1.lambdaAttach; } });
|
|
18
|
-
var lambda_grant_1 = require("./lib/utils/lambda-grant");
|
|
10
|
+
var lambda_grant_1 = require("./lib/lambda/utils/lambda-grant");
|
|
19
11
|
Object.defineProperty(exports, "lambdaGrant", { enumerable: true, get: function () { return lambda_grant_1.lambdaGrant; } });
|
|
12
|
+
var static_construct_1 = require("./lib/static/static-construct");
|
|
13
|
+
Object.defineProperty(exports, "StaticConstruct", { enumerable: true, get: function () { return static_construct_1.StaticConstruct; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Attachable } from '@fy-stack/types';
|
|
2
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import { BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
5
|
+
import { Construct } from 'constructs';
|
|
6
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
7
|
+
export declare class ImageAppConstruct extends Construct implements AppConstruct {
|
|
8
|
+
private props;
|
|
9
|
+
container: ecs.ContainerDefinition;
|
|
10
|
+
constructor(scope: Construct, id: string, props: AppProperties<unknown>);
|
|
11
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
12
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
13
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
14
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
15
|
+
static parse(params: unknown): unknown;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=image-app-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-app-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/ecs/apps/image-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,qBAAa,iBAAkB,SAAQ,SAAU,YAAW,YAAY;IAMpE,OAAO,CAAC,KAAK;IALR,SAAS,EAAE,GAAG,CAAC,mBAAmB,CAAC;gBAGxC,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACF,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC;IAcvC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAOpD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAyBzD,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageAppConstruct = void 0;
|
|
4
|
+
const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
|
|
5
|
+
const constructs_1 = require("constructs");
|
|
6
|
+
const params_from_attachable_1 = require("../../util/params-from-attachable");
|
|
7
|
+
const taskDefinitionImage_1 = require("../shared/taskDefinitionImage");
|
|
8
|
+
class ImageAppConstruct extends constructs_1.Construct {
|
|
9
|
+
props;
|
|
10
|
+
container;
|
|
11
|
+
constructor(scope, id, props) {
|
|
12
|
+
super(scope, id);
|
|
13
|
+
this.props = props;
|
|
14
|
+
this.container = (0, taskDefinitionImage_1.taskDefinitionImage)(`${props.appName}AppContainer`, {
|
|
15
|
+
taskDefinition: props.taskDefinition,
|
|
16
|
+
port: props.port,
|
|
17
|
+
env: props.env,
|
|
18
|
+
output: props.output,
|
|
19
|
+
container: props.container,
|
|
20
|
+
environmentPath: props.environmentPath,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
attach(attachable) {
|
|
24
|
+
const params = Object.assign({}, ...(0, params_from_attachable_1.paramsFromAttachable)(attachable));
|
|
25
|
+
for (const i in params) {
|
|
26
|
+
this.container.addEnvironment(i, params[i]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
cloudfront(path) {
|
|
30
|
+
const { origin, basePath } = this.props.serverOrigin(this.props.port, this.container.containerName, path, '/health');
|
|
31
|
+
if (!origin)
|
|
32
|
+
throw new Error('No server origin');
|
|
33
|
+
this.container.addEnvironment('BASE_PATH', basePath);
|
|
34
|
+
const appBehaviour = {
|
|
35
|
+
origin,
|
|
36
|
+
cachePolicy: aws_cloudfront_1.CachePolicy.CACHING_DISABLED,
|
|
37
|
+
allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_ALL,
|
|
38
|
+
compress: true,
|
|
39
|
+
viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
40
|
+
originRequestPolicy: aws_cloudfront_1.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
41
|
+
responseHeadersPolicy: aws_cloudfront_1.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
42
|
+
};
|
|
43
|
+
return { [`${path}/*`]: appBehaviour };
|
|
44
|
+
}
|
|
45
|
+
cloudfrontPolicy(distributionId) {
|
|
46
|
+
throw new Error(`cloudfront policy is not supported for ${this}`);
|
|
47
|
+
}
|
|
48
|
+
api(path) {
|
|
49
|
+
throw new Error(`api is not supported for ${this}`);
|
|
50
|
+
}
|
|
51
|
+
static parse(params) {
|
|
52
|
+
return params;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.ImageAppConstruct = ImageAppConstruct;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Attachable } from '@fy-stack/types';
|
|
2
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
5
|
+
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
import { AppConstruct, AppProperties } from '../types';
|
|
8
|
+
type NextAppRouterProps = AppProperties<unknown>;
|
|
9
|
+
export declare class NextAppRouterConstruct extends Construct implements AppConstruct {
|
|
10
|
+
private props;
|
|
11
|
+
container: ecs.ContainerDefinition;
|
|
12
|
+
queue: sqs.Queue | undefined;
|
|
13
|
+
private readonly static;
|
|
14
|
+
constructor(scope: Construct, id: string, props: NextAppRouterProps);
|
|
15
|
+
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
16
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
17
|
+
api(): Record<string, HttpRouteIntegration>;
|
|
18
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
19
|
+
static parse(params: unknown): unknown;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=next-app-router-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/ecs/apps/next-app-router-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAE3C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AASvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,KAAK,kBAAkB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAEjD,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IAMjC,OAAO,CAAC,KAAK;IALhD,SAAS,EAAE,GAAG,CAAC,mBAAmB,CAAC;IACnC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAU,KAAK,EAAE,kBAAkB;IAe3E,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAiBpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAO7C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextAppRouterConstruct = void 0;
|
|
4
|
+
const constructs_1 = require("constructs");
|
|
5
|
+
const next_app_router_1 = require("../../shared/next-app-router");
|
|
6
|
+
const params_from_attachable_1 = require("../../util/params-from-attachable");
|
|
7
|
+
const taskDefinitionImage_1 = require("../shared/taskDefinitionImage");
|
|
8
|
+
class NextAppRouterConstruct extends constructs_1.Construct {
|
|
9
|
+
props;
|
|
10
|
+
container;
|
|
11
|
+
queue;
|
|
12
|
+
static;
|
|
13
|
+
constructor(scope, id, props) {
|
|
14
|
+
super(scope, id);
|
|
15
|
+
this.props = props;
|
|
16
|
+
this.static = (0, next_app_router_1.staticDeployment)(this, props.output);
|
|
17
|
+
this.container = (0, taskDefinitionImage_1.taskDefinitionImage)(`${props.appName}AppContainer`, {
|
|
18
|
+
taskDefinition: props.taskDefinition,
|
|
19
|
+
port: props.port,
|
|
20
|
+
env: props.env,
|
|
21
|
+
output: props.output,
|
|
22
|
+
container: props.container,
|
|
23
|
+
environmentPath: props.environmentPath
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
cloudfront(path) {
|
|
27
|
+
const { origin, basePath } = this.props.serverOrigin(this.props.port, this.container.containerName, path, '/');
|
|
28
|
+
if (!origin)
|
|
29
|
+
throw new Error('No server origin');
|
|
30
|
+
this.container.addEnvironment('BASE_PATH', basePath);
|
|
31
|
+
return {
|
|
32
|
+
...(0, next_app_router_1.serverCloudfrontBehaviour)(this, origin, path),
|
|
33
|
+
...(0, next_app_router_1.staticCloudfrontBehaviour)(this.static, path),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
cloudfrontPolicy(distributionId) {
|
|
37
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
38
|
+
}
|
|
39
|
+
api() {
|
|
40
|
+
throw new Error('api not supported for this construct');
|
|
41
|
+
}
|
|
42
|
+
attach(attachable) {
|
|
43
|
+
const params = Object.assign({}, ...(0, params_from_attachable_1.paramsFromAttachable)(attachable));
|
|
44
|
+
for (const i in params) {
|
|
45
|
+
this.container.addEnvironment(i, params[i]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static parse(params) {
|
|
49
|
+
return params;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.NextAppRouterConstruct = NextAppRouterConstruct;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Attach, Attachable, EventResource, Grant, Grantable } from '@fy-stack/types';
|
|
2
|
+
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
3
|
+
import * as sns from 'aws-cdk-lib/aws-sns';
|
|
4
|
+
import * as snsSubscription from 'aws-cdk-lib/aws-sns-subscriptions';
|
|
5
|
+
import { Construct } from 'constructs';
|
|
6
|
+
import { TaskConstructsProps } from '../types';
|
|
7
|
+
export declare class TaskConstruct extends Construct implements EventResource, Grant, Attach {
|
|
8
|
+
private props;
|
|
9
|
+
taskDefinition: ecs.FargateTaskDefinition;
|
|
10
|
+
constructor(scope: Construct, id: string, props: TaskConstructsProps);
|
|
11
|
+
subscription(props: snsSubscription.SubscriptionProps): sns.ITopicSubscription;
|
|
12
|
+
grant(...grantables: Grantable[]): void;
|
|
13
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
14
|
+
static parse(params: unknown): unknown;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=task-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-construct.d.ts","sourceRoot":"","sources":["../../../../src/lib/ecs/apps/task-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,UAAU,EACV,aAAa,EACb,KAAK,EACL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAI3C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,eAAe,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,aACX,SAAQ,SACR,YAAW,aAAa,EAAE,KAAK,EAAE,MAAM;IAOrC,OAAO,CAAC,KAAK;IALR,cAAc,EAAE,GAAG,CAAC,qBAAqB,CAAC;gBAG/C,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACF,KAAK,EAAE,mBAAmB;IAgCpC,YAAY,CACV,KAAK,EAAE,eAAe,CAAC,iBAAiB,GACvC,GAAG,CAAC,kBAAkB;IA6CzB,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAMvC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAS7C,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ecrAssets = tslib_1.__importStar(require("aws-cdk-lib/aws-ecr-assets"));
|
|
6
|
+
const ecs = tslib_1.__importStar(require("aws-cdk-lib/aws-ecs"));
|
|
7
|
+
const iam = tslib_1.__importStar(require("aws-cdk-lib/aws-iam"));
|
|
8
|
+
const logs = tslib_1.__importStar(require("aws-cdk-lib/aws-logs"));
|
|
9
|
+
const pipes = tslib_1.__importStar(require("aws-cdk-lib/aws-pipes"));
|
|
10
|
+
const snsSubscription = tslib_1.__importStar(require("aws-cdk-lib/aws-sns-subscriptions"));
|
|
11
|
+
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
12
|
+
const constructs_1 = require("constructs");
|
|
13
|
+
const params_from_attachable_1 = require("../../util/params-from-attachable");
|
|
14
|
+
class TaskConstruct extends constructs_1.Construct {
|
|
15
|
+
props;
|
|
16
|
+
taskDefinition;
|
|
17
|
+
constructor(scope, id, props) {
|
|
18
|
+
super(scope, id);
|
|
19
|
+
this.props = props;
|
|
20
|
+
const { container, output, ...definitionProps } = props;
|
|
21
|
+
this.taskDefinition = new ecs.FargateTaskDefinition(this, 'Task', {
|
|
22
|
+
cpu: 256,
|
|
23
|
+
memoryLimitMiB: 512,
|
|
24
|
+
runtimePlatform: {
|
|
25
|
+
cpuArchitecture: ecs.CpuArchitecture.X86_64,
|
|
26
|
+
},
|
|
27
|
+
...definitionProps,
|
|
28
|
+
});
|
|
29
|
+
if (container) {
|
|
30
|
+
const { image: imageProps, logDuration, ...containerProps } = container;
|
|
31
|
+
this.taskDefinition.addContainer('DefaultImage', {
|
|
32
|
+
image: ecs.ContainerImage.fromAsset(output, {
|
|
33
|
+
platform: ecrAssets.Platform.LINUX_AMD64,
|
|
34
|
+
...imageProps,
|
|
35
|
+
}),
|
|
36
|
+
logging: new ecs.AwsLogDriver({
|
|
37
|
+
streamPrefix: `${id}/task-runner`,
|
|
38
|
+
logRetention: logDuration ?? logs.RetentionDays.ONE_DAY,
|
|
39
|
+
}),
|
|
40
|
+
...containerProps,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
subscription(props) {
|
|
45
|
+
const queue = new sqs.Queue(this, 'TaskQueue');
|
|
46
|
+
const pipeRole = new iam.Role(this, 'PipeRole', {
|
|
47
|
+
assumedBy: new iam.ServicePrincipal('pipes.amazonaws.com'),
|
|
48
|
+
});
|
|
49
|
+
new pipes.CfnPipe(this, 'TaskPipe', {
|
|
50
|
+
source: queue.queueArn,
|
|
51
|
+
target: this.props.cluster.clusterArn,
|
|
52
|
+
roleArn: pipeRole.roleArn,
|
|
53
|
+
desiredState: 'RUNNING',
|
|
54
|
+
targetParameters: {
|
|
55
|
+
ecsTaskParameters: {
|
|
56
|
+
taskDefinitionArn: this.taskDefinition.taskDefinitionArn,
|
|
57
|
+
launchType: 'FARGATE',
|
|
58
|
+
networkConfiguration: {
|
|
59
|
+
awsvpcConfiguration: {
|
|
60
|
+
assignPublicIp: 'ENABLED',
|
|
61
|
+
subnets: this.props.vpc.publicSubnets.map((v) => v.subnetId),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
overrides: {
|
|
65
|
+
containerOverrides: [
|
|
66
|
+
{
|
|
67
|
+
name: 'DefaultImage',
|
|
68
|
+
environment: [
|
|
69
|
+
{ name: 'TASK_NAME', value: '$.body.message' },
|
|
70
|
+
{ name: 'PAYLOAD', value: '$.body.payload' },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
queue.grantConsumeMessages(pipeRole);
|
|
79
|
+
this.taskDefinition.grantRun(pipeRole);
|
|
80
|
+
return new snsSubscription.SqsSubscription(queue, {
|
|
81
|
+
...props,
|
|
82
|
+
rawMessageDelivery: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
grant(...grantables) {
|
|
86
|
+
for (const i in grantables) {
|
|
87
|
+
grantables[i].grantable(this.taskDefinition.taskRole);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
attach(attachable) {
|
|
91
|
+
const params = {};
|
|
92
|
+
Object.assign(params, ...(0, params_from_attachable_1.paramsFromAttachable)(attachable));
|
|
93
|
+
for (const i in params) {
|
|
94
|
+
this.taskDefinition.defaultContainer?.addEnvironment(i, params[i]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
static parse(params) {
|
|
98
|
+
return params;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TaskConstruct = TaskConstruct;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { TaskConstruct } from './apps/task-construct';
|
|
3
|
+
import { EcsServerConstruct } from './ecs-server-construct';
|
|
4
|
+
import type { EcsConstructProps } from './types';
|
|
5
|
+
export declare class EcsConstruct extends Construct {
|
|
6
|
+
server?: EcsServerConstruct;
|
|
7
|
+
tasks: Record<string, TaskConstruct>;
|
|
8
|
+
constructor(scope: Construct, id: string, props: EcsConstructProps);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ecs-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecs-construct.d.ts","sourceRoot":"","sources":["../../../src/lib/ecs/ecs-construct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,qBAAa,YAAa,SAAQ,SAAS;IAClC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;gBAErC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB;CAqCnE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EcsConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ecs = tslib_1.__importStar(require("aws-cdk-lib/aws-ecs"));
|
|
6
|
+
const constructs_1 = require("constructs");
|
|
7
|
+
const task_construct_1 = require("./apps/task-construct");
|
|
8
|
+
const ecs_server_construct_1 = require("./ecs-server-construct");
|
|
9
|
+
class EcsConstruct extends constructs_1.Construct {
|
|
10
|
+
server;
|
|
11
|
+
tasks = {};
|
|
12
|
+
constructor(scope, id, props) {
|
|
13
|
+
super(scope, id);
|
|
14
|
+
const appCluster = new ecs.Cluster(this, 'EcsCluster', {
|
|
15
|
+
vpc: props.vpc,
|
|
16
|
+
containerInsightsV2: ecs.ContainerInsights.ENABLED,
|
|
17
|
+
});
|
|
18
|
+
if (props.server) {
|
|
19
|
+
this.server = new ecs_server_construct_1.EcsServerConstruct(this, 'Server', {
|
|
20
|
+
...props.server,
|
|
21
|
+
cluster: appCluster,
|
|
22
|
+
environmentPath: props.environmentPath,
|
|
23
|
+
environment: props.environment,
|
|
24
|
+
vpc: props.vpc,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (props.tasks) {
|
|
28
|
+
Object.assign(this.tasks, Object.fromEntries(Object.entries(props.tasks ?? {}).map(([key, app]) => {
|
|
29
|
+
return [
|
|
30
|
+
key,
|
|
31
|
+
new task_construct_1.TaskConstruct(this, `${key}Task`, {
|
|
32
|
+
buildParams: task_construct_1.TaskConstruct.parse(app.buildParams ?? {}),
|
|
33
|
+
cluster: appCluster,
|
|
34
|
+
vpc: props.vpc,
|
|
35
|
+
...app,
|
|
36
|
+
}),
|
|
37
|
+
];
|
|
38
|
+
})));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.EcsConstruct = EcsConstruct;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Grant, Grantable } from '@fy-stack/types';
|
|
2
|
+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
|
|
3
|
+
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
4
|
+
import * as elbV2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
|
|
5
|
+
import { Construct } from 'constructs';
|
|
6
|
+
import { AppConstruct, EcsConstructProps } from './types';
|
|
7
|
+
type EcsServerConstructProps = EcsConstructProps['server'] & {
|
|
8
|
+
vpc: ec2.IVpc;
|
|
9
|
+
environmentPath: string;
|
|
10
|
+
environment: string;
|
|
11
|
+
cluster: ecs.Cluster;
|
|
12
|
+
};
|
|
13
|
+
export declare class EcsServerConstruct extends Construct implements Grant {
|
|
14
|
+
private props;
|
|
15
|
+
apps: Record<string, AppConstruct>;
|
|
16
|
+
private readonly appTaskDefinition;
|
|
17
|
+
private loadBalancer?;
|
|
18
|
+
constructor(scope: Construct, id: string, props: EcsServerConstructProps);
|
|
19
|
+
grant(...grantables: Grantable[]): void;
|
|
20
|
+
private serverOrigin;
|
|
21
|
+
initLoadBalancer(): {
|
|
22
|
+
alb: elbV2.IApplicationLoadBalancer;
|
|
23
|
+
listener: elbV2.IApplicationListener;
|
|
24
|
+
};
|
|
25
|
+
getAppPriority(appPath: string): number;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=ecs-server-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecs-server-construct.d.ts","sourceRoot":"","sources":["../../../src/lib/ecs/ecs-server-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAG1E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,wCAAwC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAO1D,KAAK,uBAAuB,GAAG,iBAAiB,CAAC,QAAQ,CAAC,GAAG;IAC3D,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC;CACtB,CAAC;AAEF,qBAAa,kBAAmB,SAAQ,SAAU,YAAW,KAAK;IAY9D,OAAO,CAAC,KAAK;IAXR,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAM;IAE/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC,YAAY,CAAC,CAGnB;gBAGA,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,EACF,KAAK,EAAE,uBAAuB;IAqExC,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAMvC,OAAO,CAAC,YAAY;IA8CpB,gBAAgB;;;;IAuChB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CA8CxC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EcsServerConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const types_1 = require("@fy-stack/types");
|
|
8
|
+
const cdn = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
9
|
+
const cdnOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
10
|
+
const ec2 = tslib_1.__importStar(require("aws-cdk-lib/aws-ec2"));
|
|
11
|
+
const ecs = tslib_1.__importStar(require("aws-cdk-lib/aws-ecs"));
|
|
12
|
+
const elbV2 = tslib_1.__importStar(require("aws-cdk-lib/aws-elasticloadbalancingv2"));
|
|
13
|
+
const constructs_1 = require("constructs");
|
|
14
|
+
const image_app_construct_1 = require("./apps/image-app-construct");
|
|
15
|
+
const next_app_router_construct_1 = require("./apps/next-app-router-construct");
|
|
16
|
+
const AppBuilds = {
|
|
17
|
+
[types_1.AppType.NEXT_APP_ROUTER]: next_app_router_construct_1.NextAppRouterConstruct,
|
|
18
|
+
[types_1.AppType.IMAGE_APP]: image_app_construct_1.ImageAppConstruct,
|
|
19
|
+
};
|
|
20
|
+
class EcsServerConstruct extends constructs_1.Construct {
|
|
21
|
+
props;
|
|
22
|
+
apps = {};
|
|
23
|
+
appTaskDefinition;
|
|
24
|
+
loadBalancer;
|
|
25
|
+
constructor(scope, id, props) {
|
|
26
|
+
super(scope, id);
|
|
27
|
+
this.props = props;
|
|
28
|
+
const appSecurityGroup = new ec2.SecurityGroup(this, 'AppSecurityGroup', {
|
|
29
|
+
vpc: props.vpc,
|
|
30
|
+
});
|
|
31
|
+
const { definition, apps, cluster, ...serverProps } = props;
|
|
32
|
+
this.appTaskDefinition = new ecs.FargateTaskDefinition(this, 'ServerTaskDefinition', {
|
|
33
|
+
cpu: 256,
|
|
34
|
+
memoryLimitMiB: 512,
|
|
35
|
+
runtimePlatform: {
|
|
36
|
+
cpuArchitecture: ecs.CpuArchitecture.X86_64,
|
|
37
|
+
operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
|
|
38
|
+
},
|
|
39
|
+
...(definition ?? {}),
|
|
40
|
+
});
|
|
41
|
+
const service = new ecs.FargateService(this, 'ServerService', {
|
|
42
|
+
cluster,
|
|
43
|
+
taskDefinition: this.appTaskDefinition,
|
|
44
|
+
capacityProviderStrategies: [{ capacityProvider: 'FARGATE', weight: 1 }],
|
|
45
|
+
desiredCount: 1,
|
|
46
|
+
vpcSubnets: {
|
|
47
|
+
subnetType: serverProps.assignPublicIp
|
|
48
|
+
? ec2.SubnetType.PUBLIC
|
|
49
|
+
: ec2.SubnetType.PRIVATE_WITH_EGRESS,
|
|
50
|
+
},
|
|
51
|
+
securityGroups: [appSecurityGroup],
|
|
52
|
+
...serverProps,
|
|
53
|
+
});
|
|
54
|
+
const serverOrigin = (port, containerName, appPath, healthPath) => this.serverOrigin(service, port, containerName, appPath, healthPath);
|
|
55
|
+
serverOrigin.bind(this);
|
|
56
|
+
Object.assign(this.apps, Object.fromEntries(Object.entries(apps).map(([key, app]) => {
|
|
57
|
+
const AppTypeConstruct = AppBuilds[app.type];
|
|
58
|
+
return [
|
|
59
|
+
key,
|
|
60
|
+
new AppTypeConstruct(this, `${key}App`, {
|
|
61
|
+
appName: key,
|
|
62
|
+
environmentPath: props.environmentPath,
|
|
63
|
+
buildParams: AppTypeConstruct.parse(app.buildParams ?? {}),
|
|
64
|
+
serverOrigin,
|
|
65
|
+
taskDefinition: this.appTaskDefinition,
|
|
66
|
+
...app,
|
|
67
|
+
}),
|
|
68
|
+
];
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
grant(...grantables) {
|
|
72
|
+
for (const i in grantables) {
|
|
73
|
+
grantables[i].grantable(this.appTaskDefinition.taskRole);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
serverOrigin(service, port, containerName, appPath, healthPath) {
|
|
77
|
+
if (!this.loadBalancer)
|
|
78
|
+
this.loadBalancer = this.initLoadBalancer();
|
|
79
|
+
const appFullPath = node_path_1.default.join(this.props.environmentPath, appPath || '/base');
|
|
80
|
+
const appTargetGroup = new elbV2.ApplicationTargetGroup(this, `${containerName}Target`, {
|
|
81
|
+
vpc: this.props.vpc,
|
|
82
|
+
protocol: elbV2.ApplicationProtocol.HTTP,
|
|
83
|
+
targets: [
|
|
84
|
+
service.loadBalancerTarget({
|
|
85
|
+
containerPort: port,
|
|
86
|
+
containerName: containerName,
|
|
87
|
+
}),
|
|
88
|
+
],
|
|
89
|
+
healthCheck: {
|
|
90
|
+
path: node_path_1.default.join(appFullPath, healthPath ?? ''),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const origin = new cdnOrigin.LoadBalancerV2Origin(this.loadBalancer.alb, {
|
|
94
|
+
originPath: appPath ? this.props.environmentPath : appFullPath,
|
|
95
|
+
protocolPolicy: cdn.OriginProtocolPolicy.HTTP_ONLY,
|
|
96
|
+
});
|
|
97
|
+
this.loadBalancer.listener.addTargetGroups(`${containerName}Rule`, {
|
|
98
|
+
conditions: [elbV2.ListenerCondition.pathPatterns([`${appFullPath}/*`])],
|
|
99
|
+
priority: this.getAppPriority(appFullPath),
|
|
100
|
+
targetGroups: [appTargetGroup],
|
|
101
|
+
});
|
|
102
|
+
return { origin, basePath: appFullPath };
|
|
103
|
+
}
|
|
104
|
+
initLoadBalancer() {
|
|
105
|
+
if (this.props.loadBalancer && 'arn' in this.props.loadBalancer) {
|
|
106
|
+
const alb = elbV2.ApplicationLoadBalancer.fromLookup(this, 'LoadBalancer', { loadBalancerArn: this.props.loadBalancer.arn });
|
|
107
|
+
const listener = elbV2.ApplicationListener.fromLookup(this, 'DefaultListener', { loadBalancerArn: this.props.loadBalancer.arn, listenerPort: 80 });
|
|
108
|
+
if (!listener) {
|
|
109
|
+
throw new Error(`no HTTP:80 listener on ${this.props.loadBalancer.arn}`);
|
|
110
|
+
}
|
|
111
|
+
return { alb, listener };
|
|
112
|
+
}
|
|
113
|
+
const alb = new elbV2.ApplicationLoadBalancer(this, 'LoadBalancer', {
|
|
114
|
+
vpc: this.props.vpc,
|
|
115
|
+
vpcSubnets: {
|
|
116
|
+
subnets: this.props.vpc.publicSubnets,
|
|
117
|
+
},
|
|
118
|
+
internetFacing: true,
|
|
119
|
+
});
|
|
120
|
+
const listener = alb.addListener('Listener', { port: 80 });
|
|
121
|
+
listener.addAction('DefaultAction', {
|
|
122
|
+
action: elbV2.ListenerAction.fixedResponse(400),
|
|
123
|
+
});
|
|
124
|
+
return { alb, listener };
|
|
125
|
+
}
|
|
126
|
+
getAppPriority(appPath) {
|
|
127
|
+
const configPath = './fy-stack.context.json';
|
|
128
|
+
let config = {};
|
|
129
|
+
let priorityRage = [0, 1000];
|
|
130
|
+
if (this.props.loadBalancer && "priorityRange" in this.props.loadBalancer) {
|
|
131
|
+
priorityRage = this.props.loadBalancer.priorityRange;
|
|
132
|
+
}
|
|
133
|
+
let priority = priorityRage[0];
|
|
134
|
+
if (node_fs_1.default.existsSync(configPath)) {
|
|
135
|
+
config = JSON.parse(node_fs_1.default.readFileSync(configPath).toString());
|
|
136
|
+
if (config.loadBalancer?.priorities?.[appPath]) {
|
|
137
|
+
priority = config.loadBalancer?.priorities?.[appPath];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const existingPriorities = Object.values(config.loadBalancer?.priorities ?? {}).sort();
|
|
141
|
+
while (existingPriorities.includes(priority)) {
|
|
142
|
+
priority += 1;
|
|
143
|
+
}
|
|
144
|
+
if (priority > priorityRage[1])
|
|
145
|
+
throw new Error(`Priority ${priority} exceeds priority range`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
config = {
|
|
149
|
+
loadBalancer: {
|
|
150
|
+
...(config.loadBalancer ?? {}),
|
|
151
|
+
priorities: {
|
|
152
|
+
...(config.loadBalancer?.priorities ?? {}),
|
|
153
|
+
[appPath]: priority,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
node_fs_1.default.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
158
|
+
return priority;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.EcsServerConstruct = EcsServerConstruct;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as ecs from 'aws-cdk-lib/aws-ecs';
|
|
2
|
+
import { AppProperties } from '../types';
|
|
3
|
+
type Props = {
|
|
4
|
+
output: string;
|
|
5
|
+
taskDefinition: ecs.TaskDefinition;
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
port: number;
|
|
8
|
+
container?: AppProperties['container'];
|
|
9
|
+
environmentPath: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function taskDefinitionImage(id: string, props: Props): ecs.ContainerDefinition;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=taskDefinitionImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taskDefinitionImage.d.ts","sourceRoot":"","sources":["../../../../src/lib/ecs/shared/taskDefinitionImage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,GAAG,CAAC,cAAc,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACvC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,2BAmB3D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskDefinitionImage = taskDefinitionImage;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
+
const ecrAssets = tslib_1.__importStar(require("aws-cdk-lib/aws-ecr-assets"));
|
|
7
|
+
const ecs = tslib_1.__importStar(require("aws-cdk-lib/aws-ecs"));
|
|
8
|
+
const logs = tslib_1.__importStar(require("aws-cdk-lib/aws-logs"));
|
|
9
|
+
function taskDefinitionImage(id, props) {
|
|
10
|
+
const { image, logDuration, ...containerProps } = props.container ?? {};
|
|
11
|
+
return props.taskDefinition.addContainer(id, {
|
|
12
|
+
image: ecs.ContainerImage.fromAsset(node_path_1.default.join(props.output), {
|
|
13
|
+
platform: ecrAssets.Platform.LINUX_AMD64,
|
|
14
|
+
...(image ?? {}),
|
|
15
|
+
}),
|
|
16
|
+
logging: new ecs.AwsLogDriver({
|
|
17
|
+
streamPrefix: `${props.environmentPath}/${id}`,
|
|
18
|
+
logRetention: logDuration ?? logs.RetentionDays.ONE_DAY,
|
|
19
|
+
}),
|
|
20
|
+
environment: {
|
|
21
|
+
...(props.env ?? {}),
|
|
22
|
+
PORT: props.port.toString(),
|
|
23
|
+
},
|
|
24
|
+
portMappings: [{ containerPort: props.port }],
|
|
25
|
+
...(containerProps ?? {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecs-api-gateway.d.ts","sourceRoot":"","sources":["../../../../../src/lib/ecs/shared/util/ecs-api-gateway.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,SAE5B"}
|