-
Notifications
You must be signed in to change notification settings - Fork 19
/
deploy.ts
75 lines (67 loc) · 1.9 KB
/
deploy.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
import { executeAsyncCmd } from '../utils'
interface Props {
stackName: string
appPath: string
bootstrap: boolean
region?: string
lambdaMemory?: number
lambdaTimeout?: number
lambdaRuntime?: string
imageLambdaMemory?: number
imageLambdaTimeout?: number
customApiDomain?: string
domainNames?: string
redirectFromApex?: boolean
profile?: string
hotswap: boolean
}
const cdkExecutable = require.resolve('aws-cdk/bin/cdk')
export const deployHandler = async ({
stackName,
appPath,
bootstrap,
region,
lambdaMemory,
lambdaTimeout,
lambdaRuntime,
imageLambdaMemory,
imageLambdaTimeout,
domainNames,
customApiDomain,
redirectFromApex,
hotswap,
profile,
}: Props) => {
// All paths are absolute.
const cdkBootstrapArgs = [`--app "node ${appPath}"`]
const cdkDeployArgs = [`--app "node ${appPath}"`, '--require-approval never', '--ci']
if (hotswap) {
cdkDeployArgs.push(`--hotswap`)
}
if (profile) {
cdkDeployArgs.push(`--profile ${profile}`)
cdkBootstrapArgs.push(`--profile ${profile}`)
}
const variables = {
STACK_NAME: stackName,
...(region && { AWS_REGION: region }),
...(lambdaMemory && { LAMBDA_MEMORY: lambdaMemory.toString() }),
...(lambdaTimeout && { LAMBDA_TIMEOUT: lambdaTimeout.toString() }),
...(lambdaRuntime && { LAMBDA_RUNTIME: lambdaRuntime.toString() }),
...(imageLambdaMemory && { IMAGE_LAMBDA_MEMORY: imageLambdaMemory.toString() }),
...(imageLambdaTimeout && { IMAGE_LAMBDA_TIMEOUT: imageLambdaTimeout.toString() }),
...(domainNames && { DOMAIN_NAMES: domainNames }),
...(customApiDomain && { CUSTOM_API_DOMAIN: customApiDomain }),
...(redirectFromApex && { REDIRECT_FROM_APEX: redirectFromApex.toString() }),
}
if (bootstrap) {
await executeAsyncCmd({
cmd: `${cdkExecutable} bootstrap ${cdkBootstrapArgs.join(' ')}`,
env: variables,
})
}
await executeAsyncCmd({
cmd: `${cdkExecutable} deploy ${cdkDeployArgs.join(' ')}`,
env: variables,
})
}