-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
144 lines (128 loc) · 3.15 KB
/
run.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
venv() {
pip install virtualenv
virtualenv -p python3 env
}
build_lambdas() {
docker-compose up && docker-compose down
}
deploy_lambdas() {
AWS_ACCOUNT_ID=`env/bin/aws sts get-caller-identity --output text --query 'Account'`
S3_BUCKET="lambdacodestore-$AWS_ACCOUNT_ID"
AWS_REGION='us-west-2'
sed "s/region_placeholder/$AWS_REGION/g" 'swagger.yml' | sed "s/account_placeholder/$AWS_ACCOUNT_ID/g" > swagger-export.yml
env/bin/aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template lambda-template-export.yml
env/bin/aws cloudformation deploy --template lambda-template-export.yml --stack-name DLAppLambdas --capabilities CAPABILITY_IAM
env/bin/aws cloudformation describe-stacks --stack-name DLAppLambdas > src/LambdaOutput.json
for dir in $LAMBDA_DIRS
do
env/bin/aws cloudformation describe-stacks --stack-name DLAppLambdas > lambdas/$dir/LambdaOutput.json
done
}
node_reqs() {
rm -rf node_modules
npm install
}
build_website() {
node_reqs
npm run gulp build
}
environment_reqs() {
env/bin/pip install -r env_requirements.txt --upgrade
}
LAMBDA_DIRS="image_processing"
lambda_reqs() {
pushd lambdas
for dir in $LAMBDA_DIRS
do
pushd $dir
mkdir requirements
touch requirements/__init__.py
pip install -r requirements.txt -t requirements/ --upgrade
pushd requirements
rm -r external
rm -r pip
rm -r pip-9.0.1.dist-info
rm -r wheel
rm -r wheel-0.30.0.dist-info
rm easy_install.py
find . -name \*.pyc -delete
if [ -d "google" ]; then
touch google/__init__.py
fi
zip -r ../requirements.zip .
popd
rm -rf requirements
popd
done
popd
}
deploy_stack() {
env/bin/aws cloudformation deploy --template cfn-template.yml --stack-name DLApp --capabilities CAPABILITY_NAMED_IAM
env/bin/aws cloudformation describe-stacks --stack-name DLApp > src/StackOutput.json
for dir in $LAMBDA_DIRS
do
env/bin/aws cloudformation describe-stacks --stack-name DLApp > lambdas/$dir/StackOutput.json
done
}
deploy_models() {
AWS_ACCOUNT_ID=`env/bin/aws sts get-caller-identity --output text --query 'Account'`
S3_BUCKET="dlmodelstore-$AWS_ACCOUNT_ID"
env/bin/aws s3 cp ./models/ s3://$S3_BUCKET/ --recursive
}
deploy_website() {
AWS_ACCOUNT_ID=`env/bin/aws sts get-caller-identity --output text --query 'Account'`
S3_BUCKET="website-$AWS_ACCOUNT_ID"
build_website
env/bin/aws s3 cp ./dist/ s3://$S3_BUCKET/ --recursive
}
deploy() {
deploy_stack
deploy_models
deploy_lambdas
deploy_website
}
setup() {
venv
environment_reqs
}
aws_config() {
env/bin/aws configure
}
case $1 in
deploy)
deploy
;;
deploy_stack)
deploy_stack
;;
deploy_lambdas)
deploy_lambdas
;;
deploy_website)
deploy_website
;;
deploy_models)
deploy_models
;;
build_lambdas)
build_lambdas
;;
build_website)
build_website
;;
lambda_reqs)
lambda_reqs
;;
aws_config)
aws_config
;;
setup)
setup
;;
venv)
venv
;;
*)
echo "Usage: $0 {venv|setup|deploy_website|deploy_lambdas|deploy_stack|build_website|build_lambdas|build_stack|aws_config}"
esac