-
Notifications
You must be signed in to change notification settings - Fork 1
/
live-deploy.sh
executable file
·50 lines (46 loc) · 1.53 KB
/
live-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
#!/usr/bin/env bash
# Get distributions by checking AWS first...
S3_LIVE_BUCKET="s3://mdev.digital"
CF_MAIN_DISTRIBUTION="E1ZHCG9AZMYVVV"
CF_REDIRECT_DISTRIBUTION="EXGWDUWN7ENKU"
# Error Handling Function
error_handle() {
echo
echo "${RED}[ ERROR ] || ${BLACKMESA}: $1${NC}"
echo
exit 1
}
# Color Variables
ORANGE=`tput setaf 5`
GREEN=`tput setaf 2`
RED=`tput setaf 1`
YELLOW=`tput setaf 3`
NC=`tput sgr0`
echo "${YELLOW}"
echo "======================================================================================"
echo "${YELLOW} || THIS SCRIPT DEPLOYS CHANGES TO LIVE ENVIRONMENT ||${NC}"
echo "======================================================================================"
echo
echo
sleep 1s
read -p "${YELLOW}Are you absolutely sure? please type YES or NO (case sensitive)${NC} " confirmation
if [ $confirmation == "YES" ]
then
# Build from most recent master
echo "${GREEN}[ Building from Master ]${NC}"
git fetch && git checkout master
npm run clean
npm run build
# Deploy dist folder to AWS
echo "${GREEN}[ Deploying to AWS ${S3_LIVE_BUCKET} ]${NC}"
aws s3 sync dist $S3_LIVE_BUCKET
echo "${GREEN}[ Deploying Changes to Cloudfront ]${NC}"
# INVALIDATE RECORDS ON MAIN DISTRIBUTION
aws cloudfront create-invalidation --distribution-id $CF_MAIN_DISTRIBUTION --paths /
# INVALIDATE RECORDS ON SECONDARY DISTRIBUTION
aws cloudfront create-invalidation --distribution-id $CF_REDIRECT_DISTRIBUTION --paths /
echo "${GREEN}[ Changes Successfully Deployed to AWS! ]${NC}"
exit 0
else
error_handle "Try again when ready!"
fi