This repository was archived by the owner on Dec 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
283 lines (245 loc) · 7.84 KB
/
config.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import * as pulumi from "@pulumi/pulumi"
import * as AWS from "aws-sdk"
// Latest released Code Ocean Enterprise AMIs per region
export interface AMIConfig {
services: {
[region: string]: string,
},
worker: {
[region: string]: string,
}
}
interface SAMLIdPConfig {
entityID: string,
ssoUrl: string,
certificate: string,
}
interface AuthConfig {
allowedDomains?: string[],
builtin: {
reCaptchaApiKey?: pulumi.Output<string>,
},
google: {
clientID?: string,
clientSecret?: pulumi.Output<string>,
},
saml?: SAMLIdPConfig,
systemAPIKey?: pulumi.Output<string>,
}
interface AWSConfig {
accountId?: string, // injected during runtime
keyPair: string,
region: string,
}
interface DeploymentConfig {
singleInstance: boolean,
}
interface DomainConfig {
app: string,
cloudWorkstation: string,
files: string,
git: string,
}
// Elastic Load Balancing Account ID per region
// Used in ELB access log configuration
interface ElbAccountIdConfig {
[region: string]: string,
}
interface FeaturesConfig {
capsuleCache: boolean,
disablePackageSuggestions: boolean,
enableIntercom: boolean,
onboarding: string,
useRInstallPackages: boolean,
}
interface GitProvidersConfig {
github: {
org: string,
},
}
interface FlexLMConfig {
enabled?: boolean,
macAddress?: string,
hostname?: string,
}
interface RedisConfig {
enabled?: boolean,
instanceType?: string,
multiAZ?: boolean,
}
interface ElasticsearchConfig {
enabled?: boolean,
instanceType?: string,
multiAZ?: boolean,
}
interface AnalyticsDBConfig {
instanceClass: string,
multiAZ?: boolean,
}
interface ServicesConfig {
registryHost: string,
aws: {
redis: RedisConfig,
elasticsearch: ElasticsearchConfig,
analyticsdb: AnalyticsDBConfig,
},
segment: {
backend: {
apiKey?: pulumi.Output<string>,
},
frontend: {
apiKey?: pulumi.Output<string>,
},
}
}
interface VersionConfig {
label: string
version: string
}
interface VpcConfig {
cidrBlock: string,
ingressCidrBlocks: string[],
}
interface MountTarget {
availabilityZoneId: string,
mountTargetIP: string,
}
interface SharedVolumeConfig {
efsId?: string,
mountTargets: MountTarget[],
}
interface WorkerConfig {
autoScalingMaxSize: number,
autoScalingMinSize: number,
autoScalingIdleTimeout: number,
instanceType: string,
maintainIdleWorker: boolean,
useInstanceStore?: boolean,
}
interface WorkersConfig {
general: WorkerConfig,
gpu: WorkerConfig,
sharedVolume?: SharedVolumeConfig,
}
/**
* Config extends `pulumi.Config` with extra functionality.
*/
class Config extends pulumi.Config {
/**
* getObjectWithDefaults extends `pulumi.Config.getObject` to assign default values
* to the loaded config object.
*
* @param key The key to lookup.
* @param defaults The default values.
*/
getObjectWithDefaults<T>(key: string, defaults: T): T {
const o = this.getObject<T>(key)
return Object.assign(defaults, o)
}
}
const config = new Config()
const awsConfig = new pulumi.Config("aws")
export const project = pulumi.getProject()
export const stackname = pulumi.getStack()
export const deploymentName = `codeocean-${project}-${stackname}`
export const version: VersionConfig = {
label: "Productive Mode",
version: "0.13.3",
}
export const deployment: DeploymentConfig = {
singleInstance: config.getBoolean("singleInstance") === true,
}
export const aws: AWSConfig = {
keyPair: config.require("aws.keyPair"),
region: awsConfig.require("region"),
}
// Make sure aws-sdk has region configured either from env or config
if (!AWS.config.region) {
AWS.config.region = aws.region
}
export const vpc = config.getObject<VpcConfig>("vpc")
export const domains: DomainConfig = {
app: config.require("domains.app"),
cloudWorkstation: config.get("domains.cloudWorkstation") || config.require("domains.app"),
files: config.get("domains.files") || config.require("domains.app"),
git: config.get("domains.git") || config.require("domains.app"),
}
export const gitProviders = config.getObject<GitProvidersConfig>("gitProviders")
export const flexlm = config.getObject<FlexLMConfig>("flexlm")
export const services: ServicesConfig = {
registryHost: deployment.singleInstance ? "localhost:5000" : `registry.${config.require("domains.app")}`,
aws: {
redis: config.getObjectWithDefaults<RedisConfig>("aws.redis", {
instanceType: "cache.t3.micro",
}),
elasticsearch: config.getObjectWithDefaults<ElasticsearchConfig>("aws.elasticsearch", {
instanceType: "t3.small.elasticsearch",
}),
analyticsdb: config.getObjectWithDefaults<AnalyticsDBConfig>("aws.analyticsdb", {
instanceClass: "db.t3.micro",
}),
},
segment: {
backend: {
apiKey: config.getSecret("segment.backend.apiKey"),
},
frontend: {
apiKey: config.getSecret("segment.frontend.apiKey"),
},
},
}
export const auth: AuthConfig = {
builtin: {
reCaptchaApiKey: config.getSecret("auth.builtin.reCaptchaApiKey"),
},
google: {
clientID: config.get("auth.google.clientID"),
clientSecret: config.getSecret("auth.google.clientSecret"),
},
saml: config.getObject("saml"),
systemAPIKey: config.getSecret("auth.systemAPIKey"),
}
if (config.get("auth.allowedDomains")) {
auth.allowedDomains = config.require("auth.allowedDomains").split(",").map((x) => x.trim())
}
export const workers: WorkersConfig = {
general: {
autoScalingMaxSize: config.getNumber("workers.autoScalingMaxSize") || 3,
autoScalingMinSize: config.getNumber("workers.autoScalingMinSize") || 0,
autoScalingIdleTimeout: config.getNumber("workers.autoScalingIdleTimeout") || 60,
instanceType: config.get("workers.instanceType", { pattern: RegExp(/^r5d\..*$/) } ) || "r5d.4xlarge",
maintainIdleWorker: config.getBoolean("workers.maintainIdleWorker") || false,
useInstanceStore: config.getBoolean("workers.useInstanceStore") || true,
},
gpu: {
autoScalingMaxSize: config.getNumber("workers.gpu.autoScalingMaxSize") || 3,
autoScalingMinSize: config.getNumber("workers.gpu.autoScalingMinSize") || 0,
autoScalingIdleTimeout: config.getNumber("workers.gpu.autoScalingIdleTimeout") || 60,
instanceType: config.get("workers.gpu.instanceType", { pattern: RegExp(/^p[234]d?\..*$/) } ) || "p2.xlarge",
maintainIdleWorker: config.getBoolean("workers.gpu.maintainIdleWorker") || false,
useInstanceStore: config.getBoolean("workers.useInstanceStore") || false,
},
sharedVolume: config.getObject<WorkersConfig>("workers")?.sharedVolume,
}
// Validation
if (workers.general.maintainIdleWorker && workers.general.autoScalingMinSize < 1) {
throw new Error("'workers.autoScalingMinSize' must be greater than 1 when specifying 'workers.maintainIdleWorker'")
}
if (workers.gpu.maintainIdleWorker && workers.gpu.autoScalingMinSize < 1) {
throw new Error("'workers.gpu.autoScalingMinSize' must be greater than 1 when specifying 'workers.gpu.maintainIdleWorker'")
}
export const features = config.getObject<FeaturesConfig>("features")
export const ami: AMIConfig = {
services: {
"us-east-1": config.get("services.ami") || "ami-054d04c3e26909cd7",
"eu-central-1": config.get("services.ami") || "ami-0416815b8295032e6",
},
worker: {
"us-east-1": config.get("workers.ami") || "ami-0f0012aa4588e14d5",
"eu-central-1": config.get("workers.ami") || "ami-0a4dccebd573cb996",
},
}
export const elbAccountId: ElbAccountIdConfig = {
"us-east-1": "127311923021",
"eu-central-1": "054676820928",
}