-
Notifications
You must be signed in to change notification settings - Fork 44
/
package.sh
executable file
·121 lines (102 loc) · 2.86 KB
/
package.sh
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
#!/bin/bash
set -e
# Set workspace paths
WORKSPACE=$(pwd)
CDK_DIR=$WORKSPACE/cdk
FRONTEND_DIR=$WORKSPACE/frontend
BACKEND_DIR=$WORKSPACE/backend
EXAMPLES_DIR=$WORKSPACE/examples
if [ "$#" -ne 2 ]; then
echo "package.sh <environment> <cloudformation output directory>"
exit 1
fi
# Validate environment name from input
environment=$1
if [ "$environment" != "" ]; then
echo "Environment = $environment"
export CDK_ENV_NAME=$environment
else
echo "Please specify environment name as first argument (i.e. dev)"
exit 1
fi
outputdir=$2
if [ "$outputdir" == "" ]; then
echo "Please specify CloudFormation output directory as second argument"
exit 1
fi
exampleLanguage=${3:-english}
if [ "$exampleLanguage" != "" ]; then
echo "Example Language = $exampleLanguage"
else
echo "Please specify an example language name as third argument (i.e. en|es|pt)"
exit 0
fi
verify_prereqs() {
# Verify necessary commands
echo "node version"
node --version
echo "npm version"
npm --version
echo "cdk version"
cdk --version
}
create_build_directories() {
# CDK complains if the backend/build and frontend/build
# directories don't exist during synth. So we need to trick
# CDK by creating empty directories for now. Later on, these
# directories will be populated by building the backend and
# frontend for real.
mkdir -p $FRONTEND_DIR/build
mkdir -p $BACKEND_DIR/build
mkdir -p $EXAMPLES_DIR/build
}
package_auth() {
echo "Packaging auth stack"
cd $CDK_DIR
if [ "$CDK_ADMIN_EMAIL" != "" ]; then
npm run cdk -- synth Auth --parameters adminEmail=$CDK_ADMIN_EMAIL --parameters bucketNamePrefix=$CDK_ENV_NAME --output=$outputdir
else
npm run cdk -- synth Auth --parameters bucketNamePrefix=$CDK_ENV_NAME --output=$outputdir
fi
}
package_backend() {
echo "Building backend application"
cd $BACKEND_DIR
npm run build
cd $CDK_DIR
echo "Packaging backend stack"
npm run cdk -- synth Backend --parameters bucketNamePrefix=$CDK_ENV_NAME --output=$outputdir
}
package_frontend() {
echo "Building frontend application"
cd $FRONTEND_DIR
npm run build
cd $CDK_DIR
echo "Packaging frontend stack"
npm run cdk -- synth Frontend --output=$outputdir
}
package_ops() {
echo "Packaging ops stack"
cd $CDK_DIR
npm run cdk -- synth Ops --output=$outputdir
}
package_examples() {
echo "Packaging examples stack"
cd $EXAMPLES_DIR
npm run build
cd $CDK_DIR
npm run cdk -- synth DashboardExamples --require-approval never --output=$outputdir --parameters PerformanceDash-${environment}-DashboardExamples:exampleLanguage=${exampleLanguage}
}
build_cdk() {
cd $CDK_DIR
npm run build
}
# Start execution
verify_prereqs
create_build_directories
build_cdk
package_auth
package_backend
package_frontend
package_ops
package_examples