-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ts
138 lines (122 loc) · 4.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { Stack, StackProps, App, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { MockIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway';
import { ContainerImageBuild, NodejsBuild, SociIndexBuild } from '../src/';
import { BlockPublicAccess, Bucket, BucketEncryption } from 'aws-cdk-lib/aws-s3';
import { DockerImageAsset, Platform } from 'aws-cdk-lib/aws-ecr-assets';
import { DockerImageFunction } from 'aws-cdk-lib/aws-lambda';
import { AwsLogDriver, Cluster, CpuArchitecture, FargateTaskDefinition } from 'aws-cdk-lib/aws-ecs';
import { SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2';
import { OriginAccessIdentity, CloudFrontWebDistribution } from 'aws-cdk-lib/aws-cloudfront';
class NodejsTestStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const api = new RestApi(this, 'ExampleApi');
api.root.addMethod(
'ANY',
new MockIntegration({
integrationResponses: [{ statusCode: '200' }],
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}),
{
methodResponses: [{ statusCode: '200' }],
}
);
const dstBucket = new Bucket(this, 'DstBucket', {
// autoDeleteObjects: true,
// removalPolicy: RemovalPolicy.DESTROY,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
encryption: BucketEncryption.S3_MANAGED,
});
const dstPath = '/';
const originAccessIdentity = new OriginAccessIdentity(this, 'OriginAccessIdentity');
const distribution = new CloudFrontWebDistribution(this, 'Distribution', {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: dstBucket,
originAccessIdentity,
// originPath: dstPath,
},
behaviors: [
{
isDefaultBehavior: true,
},
],
},
],
});
new CfnOutput(this, 'DistributionUrl', {
value: `https://${distribution.distributionDomainName}`,
});
new NodejsBuild(this, 'ExampleBuild', {
assets: [
{
path: 'example-app',
exclude: ['dist', 'node_modules'],
},
],
destinationBucket: dstBucket,
destinationKeyPrefix: dstPath,
outputSourceDirectory: 'dist',
distribution,
buildCommands: ['npm ci', 'npm run build'],
buildEnvironment: {
VITE_API_ENDPOINT: api.url,
AAA: 'asdf',
BBB: dstBucket.bucketName,
},
nodejsVersion: 20,
outputEnvFile: true,
});
}
}
class SociIndexTestStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const asset = new DockerImageAsset(this, 'Image', { directory: 'example-image' });
new SociIndexBuild(this, 'Index', { imageTag: asset.assetHash, repository: asset.repository });
}
}
class ContainerImageTestStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const image = new ContainerImageBuild(this, 'Build', { directory: 'example-image', buildArgs: { DUMMY_FILE_SIZE_MB: '15' } });
const armImage = new ContainerImageBuild(this, 'BuildArm', {
directory: 'example-image',
platform: Platform.LINUX_ARM64,
repository: image.repository,
zstdCompression: true,
});
new DockerImageFunction(this, 'Function', {
code: image.toLambdaDockerImageCode(),
});
new Cluster(this, 'Cluster', {
vpc: new Vpc(this, 'Vpc', {
maxAzs: 1,
subnetConfiguration: [
{
cidrMask: 24,
name: 'public',
subnetType: SubnetType.PUBLIC,
},
],
}),
});
new FargateTaskDefinition(this, 'TaskDefinition', { runtimePlatform: { cpuArchitecture: CpuArchitecture.ARM64 } }).addContainer('main', {
image: armImage.toEcsDockerImageCode(),
logging: new AwsLogDriver({ streamPrefix: 'main' }),
});
}
}
class TestApp extends App {
constructor() {
super();
new NodejsTestStack(this, 'NodejsTestStack');
new SociIndexTestStack(this, 'SociIndexTestStack');
new ContainerImageTestStack(this, 'ContainerImageTestStack');
}
}
new TestApp().synth();