-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
executable file
·85 lines (74 loc) · 2.28 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
80
81
82
83
84
85
#!/bin/bash
# Builds the web app and deploys to electrifygame.com, including invalidating the files on cloudfront (CDN)
# Requires the aws cli for s3 deploys (make sure to set your bucket region!)
# Requires that you run `aws configure set preview.cloudfront true` to enable cloudfront invalidation
TARGETS="beta prod local-beta local-prod"
target="$1"
getTarget() {
if [[ ! $TARGETS =~ $target ]];
then
echo "Where would you like to deploy?"
select t in $TARGETS; do
target=$t
break
done
fi
}
deploy() {
echo "Deploying to $target"
if [ "$target" = "beta" ]; then
beta
elif [ "$target" = "local-beta" ]; then
betabuild
elif [ "$target" = "local-prod" ]; then
prodbuild
elif [ "$target" = "prod" ]; then
read -p "Did you test on beta? (y/N) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Are you on the master branch? (y/N) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
prod
else
echo "Prod build cancelled until on master branch."
fi
else
echo "Prod build cancelled until tested on beta."
fi
else
echo "Invalid target"
fi
}
prebuild() {
# clear out old build files to prevent conflicts
rm -rf build
}
betabuild() {
prebuild
export NODE_ENV='development'
npm run build
}
beta() {
betabuild
aws s3 cp build s3://beta.electrifygame.com --recursive --region us-east-2
}
prodbuild() {
prebuild
export NODE_ENV='production'
export OAUTH2_CLIENT_ID='545484140970-r95j0rmo8q1mefo0pko6l3v6p4s771ul.apps.googleusercontent.com'
npm run build
}
prod() {
prodbuild
# Deploy web app to prod with 1 day cache for most files, 6 month cache for art assets
export AWS_DEFAULT_REGION='us-east-2'
aws s3 cp build s3://electrifygame.com --recursive --exclude '*.mp3' --exclude '*.jpg' --exclude '*.png' --cache-control max-age=86400 --cache-control public
aws s3 cp build s3://electrifygame.com --recursive --exclude '*' --include '*.mp3' --include '*.jpg' --include '*.png' --cache-control max-age=15552000 --cache-control public
# Upload package.json for API's version check
aws s3 cp package.json s3://electrifygame.com/package.json
# Invalidate files on cloudfront
aws cloudfront create-invalidation --distribution-id E38D57AILAHD00 --paths /\*
}
getTarget
deploy