-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·109 lines (97 loc) · 2.37 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh
INDEX_YAML="index.yaml"
CRON_YAML="cron.yaml"
QUEUE_YAML="queue.yaml"
APP="ap"
rollback(){
echo -e "\nRolling back.....\n"
python APPCFG rollback --oauth2 $(dirname $0)
}
check_server_tests(){
./run_tests.sh
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "\nSERVER UNIT TESTS FAILED!\n"
cancel_deploy
fi
}
check_js_tests(){
npm test
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "\nJEST UNIT TESTS FAILED!\n"
cancel_deploy
fi
}
check_indexes(){
indexes_diff=$(git diff index.yaml)
if [[ -n $indexes_diff ]]; then
echo
echo "$indexes_diff"
echo
echo -e "\nUNCOMMITED INDEXES FOUND!\n"
cancel_deploy
fi
}
deploy(){
check_indexes
check_server_tests
check_js_tests
gulp production
gcloud config configurations activate $APP
if [ "$env" == "staging" ]; then
gcloud app deploy $deploy_configs --version=$version --no-promote
else
gcloud app deploy $deploy_configs --version=$version
fi
}
cancel_deploy(){
echo -e "\nExitted without updating $version!\n"
exit 1
}
version=$1
deploy_configs="${@:2}" # Remaining args
# first do a git pull to bring down tags
git pull
# production versions only contain digits, hf and - (dash)
production_version=false
# note: keep in sync with constants.PROD_VERSION_REGEX
if [[ $version =~ ^[0-9hf\-]+[a-z]?$ ]]; then
production_version=true
env="production"
# if deploying to production, it is compulsory to deploy all services
deploy_configs="app.yaml $INDEX_YAML $CRON_YAML $QUEUE_YAML"
else
# cron/index/queue must be specified explicitly
env="staging"
fi
s_length=$(echo $deploy_configs | wc -c)
if [ "$s_length" -gt 1 ]; then
prom="Are you sure you want to deploy to $version with configs $deploy_configs? (y/n) "
else
prom="Are you sure you want to deploy to $version? (y/n) "
fi
read -p "$prom" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
#production versions only contain digits, hf and - (dash)
if [[ $version =~ ^[0-9hf\-]+$ ]]; then
read -p "This looks like a production version ($version), Are you really sure? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# if no tag yet create it, then push tags
git tag -a -m "New production version by $(whoami) on $(date)" "v$version"
git push --tags
# deploy production version
deploy
echo -e "\n\nDeploy to production Successful!\n"
else
cancel_deploy
fi
else
#deploy non-production version
deploy
fi
else
cancel_deploy
fi