-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdify-cdk.ts
76 lines (63 loc) · 2.13 KB
/
dify-cdk.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
#!/usr/bin/env node
// Load environment variables
import './loadenv';
import { App } from 'aws-cdk-lib';
import { IVpc } from 'aws-cdk-lib/aws-ec2';
import 'source-map-support/register';
import { config } from '../configs';
import { DifyProdStackConstruct } from '../lib/dify-prod-stack';
import { DifyTestStackConstruct } from '../lib/dify-test-stack';
import { ImportedVPCStack, VPCStack } from '../lib/vpc-stack';
const app = new App();
const environment = process.env.ENVIRONMENT;
if (!environment || !['test', 'prod'].includes(environment)) {
throw new Error("Please provide a valid environment name ('test' or 'prod')");
}
console.log(`Detected environment: ${environment}`);
const deployVpcId = process.env.DEPLOY_VPC_ID;
let myVpc: IVpc | undefined;
if (deployVpcId) {
console.log(`Deploying to existing VPC with ID: ${deployVpcId}`);
myVpc = new ImportedVPCStack(app, `Existing-${deployVpcId}`, {
env: {
account: config.prodConfig.account,
region: config.prodConfig.region,
},
description: 'Dify VPC from existing VPC',
}).vpc;
}
const deployStack = (
stackName: string,
vpc: IVpc,
envConfig: { account: string; region: string },
description: string,
StackConstruct: typeof DifyTestStackConstruct | typeof DifyProdStackConstruct
) => {
new StackConstruct(app, stackName, { vpc }, {
env: {
account: envConfig.account,
region: envConfig.region,
},
description,
}).build();
};
if (environment === 'test') {
const vpcTest = myVpc || new VPCStack(app, 'DifyVPCTest', {
env: {
account: config.testConfig.account,
region: config.testConfig.region,
},
description: 'Dify Testing VPC',
}).vpc;
deployStack('DifyStackTest', vpcTest, config.testConfig, 'Dify Testing Environment', DifyTestStackConstruct);
}
if (environment === 'prod') {
const vpcProd = myVpc || new VPCStack(app, 'DifyVPCProd', {
env: {
account: config.prodConfig.account,
region: config.prodConfig.region,
},
description: 'Dify Production VPC',
}).vpc;
deployStack('DifyStackProd', vpcProd, config.prodConfig, 'Dify Production Environment', DifyProdStackConstruct);
}