forked from grandivory/mods-optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·79 lines (65 loc) · 1.85 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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
if [[ "$1" == "" ]]
then
echo "Please specify a version to deploy."
exit 1;
else
REACT_APP_VERSION=$1
fi
if [[ "$2" == "" ]]
then
echo "Please specify an environment to deploy to (prod or staging)"
exit 1;
fi
if [[ ! "$2" =~ ^(prod|staging)$ ]]
then
echo "The environment must be specified as either prod or staging"
exit 1;
fi
if [[ "$2" == "prod" ]]
then
read -r -p "Overwriting your production site! Are you sure? [y/N] " response
response=${response,,} # tolower
if [[ ! "$response" =~ ^(yes|y)$ ]]
then
exit 0;
fi
endpoint="s3://mods-optimizer.swgoh.grandivory.com"
cloudfront_id="E1JP7YU7NLGZNZ"
else
endpoint="s3://staging.mods-optimizer.swgoh.grandivory.com"
cloudfront_id="E3FV4P0N9FDZ3B"
fi
current_version=`git branch | grep \* | cut -d ' ' -f 2`
if [[ "(HEAD" == "${current_version}" ]]
then
current_version=`git rev-parse --abrev-ref HEAD -- | grep '^[0-9a-f]'`
fi
# Checkout the version you want to build and build it before deploying to AWS
git checkout ${REACT_APP_VERSION}
# If the checkout failed, then stop the build
if [ $? -ne 0 ]
then
exit 1;
fi
# Stash any un-committed changes
stash_result=$(git stash)
# We only want to try to unstash if we successfully stashed something. Otherwise, we'll be trying to apply
# changes that we don't want on top of our working branch
if [[ ${stash_result} == Saved* ]]
then
unstash=true
fi
export REACT_APP_VERSION=${REACT_APP_VERSION}
# Build the app
npm run build
# Deploy the app to S3
aws s3 sync --delete --profile grandivory build/ ${endpoint}
# Make sure that index.html is not cached
aws s3 cp --profile grandivory ${endpoint}/index.html ${endpoint}/index.html --cache-control no-store --metadata "{\"Cache-control\": \"no-cache\"}"
# Return to the previous working state
if [ "${unstash}" = true ]
then
git stash pop
fi
git checkout ${current_version}