forked from Associated-Engineering/Foo-Inc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
66 lines (60 loc) · 2.15 KB
/
deploy.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
while getopts "p:e:c" opt; do
case $opt in
p)
userProfile=$OPTARG
echo "User profile set to: $userProfile"
;;
e)
export DEPLOY_ENVIRONMENT=$OPTARG
echo "Deploy environment: $DEPLOY_ENVIRONMENT"
copy /b src/Project/ProjectStack.cs +,,
;;
c)
clean=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Run the commented command manually if you haven't before
# dotnet tool install -g Amazon.Lambda.Tools
cd Handler/src/Handler
echo "***Building backend***"
dotnet build -c Release
dotnet lambda package
cd ../../..
echo "***Deploying backend***"
if [ $userProfile ]
then
cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never --profile $userProfile
if [ $clean ]
then
dbinitName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
dropTablesName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
aws lambda invoke --function-name $dropTablesName --profile $userProfile response.json
aws lambda invoke --function-name $dbinitName --profile $userProfile response.json
fi
else
cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never
if [ $clean ]
then
dbinitName=`aws lambda list-functions | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
dropTablesName=`aws lambda list-functions | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'`
aws lambda invoke --function-name $dropTablesName sresponse.json
aws lambda invoke --function-name $dbinitName response.json
fi
fi
cd Frontend
echo "***Building frontend***"
yarn install
yarn build
cd ..
echo "***Deploying frontend***"
cdk deploy FrontendStack --require-approval never
echo "Done"