-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·125 lines (104 loc) · 2.71 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
print_in_color() {
printf "%b" \
"$(tput setaf "$2" 2> /dev/null)" \
"$1" \
"$(tput sgr0 2> /dev/null)"
}
print_in_green() {
print_in_color "$1" 2
}
print_in_purple() {
print_in_color "$1" 5
}
print_in_red() {
print_in_color "$1" 1
}
print_in_yellow() {
print_in_color "$1" 3
}
print_question() {
print_in_yellow " [?] $1"
}
set -euo pipefail
environment=""
target=""
deploy_token=""
build_file_path=""
deploy_file_path=""
firebase_project=""
env_vars=""
build_tag=""
dashboard_env_vars=""
setDesktopParams() {
target="desktop"
firebase_project="staging-merit-dashboard"
build_file_path="desktop"
deploy_file_path="desktop"
}
setRunLevelProduction() {
environment="production"
firebase_project="production-merit-dashboard"
build_tag=":prod"
dashboard_env_vars=""
}
setRunLevelStaging() {
environment="staging"
firebase_project="staging-merit-dashboard"
build_tag=""
dashboard_env_vars="DASHBOARD_STAGING=true"
}
productionPrompt() {
while true; do
read -p "Would you like to deploy to Dashboard to production? [Y/N]: " yn
case $yn in
[Yy]* ) setRunLevelProduction; break;;
[Nn]* ) setRunLevelStaging; break;;
* ) echo "Please answer yes or no.";;
esac
done
}
while getopts ":e:k:" opt; do
case $opt in
e) environment="$OPTARG"
;;
k) deploy_token="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
setDesktopParams;
if [ "$environment" != "staging" ] && [ "$environment" != "production" ]; then
print_in_red "No environment passed in with -e. Prompting for input.\n"
productionPrompt;
else
if [ "$environment" == "production" ]; then
setRunLevelProduction;
else
setRunLevelStaging;
fi
fi
print_in_yellow "Building Dashboard for $environment-environment now \n"
pushd $build_file_path
if [ ! -z "$dashboard_env_vars" ]; then
print_in_yellow "Running export $dashboard_env_vars \n"
export ${dashboard_env_vars}
fi
print_in_yellow "Running npm run build$build_tag \n"
npm run build$build_tag
popd
pushd $deploy_file_path
if [[ $deploy_token = *[!\ ]* ]]; then
print_in_yellow "Deploying using token firebase auth.\n"
print_in_yellow "Using firebase project: $firebase_project \n"
firebase use $firebase_project --token $deploy_token
print_in_green "Deploying to firebase now! \n"
firebase deploy --token $deploy_token
else
print_in_yellow "Deploying using general firebase auth.\n"
print_in_yellow "Using firebase project: $firebase_project \n"
firebase use $firebase_project
print_in_green "Deploying to firebase now! \n"
firebase deploy
fi