-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdeploy.sh
executable file
·151 lines (130 loc) · 5.03 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
usage() {
echo "Usage: $0 [--create-gcloud-installation] [--skip-cors]" 1>&2;
exit 1;
}
# =========================
# Read CLI Arguments.
# =========================
do_install_gcloud=false
do_skip_cors=false
in_docker=false
for var in "$@"
do
if [[ "$var" == "--create-gcloud-installation" ]]; then
do_install_gcloud=true
elif [[ "$var" == "--skip-cors" ]]; then
do_skip_cors=true
elif [[ "$var" == "--docker" ]]; then
in_docker=true
else
usage
exit 1
fi
done
echo "=========================="
echo "Installing dependencies..."
echo "=========================="
npm ci || { echo "Installing dependencies failed!" ; exit 1; }
echo " "
echo "=================================="
echo "Installing the Google Cloud SDK..."
echo "=================================="
gcloud_command="gcloud"
gsutil_command="gsutil"
gcloud_installed=true
# If we want to create our own installation of GCloud, then
# we just ignore whether it has already been installed.
if [ "$do_install_gcloud" = true ]; then
gcloud_installed=false
fi
if ! command -v "$gcloud_command" &> /dev/null; then
gcloud_installed=false
fi
if ! command -v "$gsutil_command" &> /dev/null; then
gcloud_installed=false
fi
if [ "$gcloud_installed" = true ]; then
echo " "
echo "Detected an existing external GCloud installation to use instead of installing."
echo "If this is not desired, then you may pass the \"--create-gcloud-installation\""
echo "option to this script."
else
# Detect a previous installation of GCloud.
gcloud_command=".GoogleCloud/google-cloud-sdk/bin/gcloud"
gsutil_command=".GoogleCloud/google-cloud-sdk/bin/gsutil"
gcloud_installed=true
# If we want to clean the installation of GCloud, then
# we just ignore whether it has already been installed.
if ! command -v "$gcloud_command" &> /dev/null; then
gcloud_installed=false
fi
if ! command -v "$gsutil_command" &> /dev/null; then
gcloud_installed=false
fi
if [ "$gcloud_installed" = true ]; then
echo " "
echo "Detected a previous GCloud installation to use instead of installing."
echo "If this is not desired, then you may delete the \".GoogleCloud\""
echo "directory to re-install GCloud."
else
rm -rf .GoogleCloud || { echo "Unable to remove old .GoogleCloud installation!" ; exit 1; }
mkdir .GoogleCloud || { echo "Unable to create .GoogleCloud directory to install Google Cloud into!" ; exit 1; }
curl https://sdk.cloud.google.com > .GoogleCloud/install.sh || { echo "Unable to download Google Cloud install script!" ; exit 1; }
bash .GoogleCloud/install.sh --disable-prompts --install-dir=.GoogleCloud || { echo "Unable to install Google Cloud!" ; exit 1; }
fi
fi
echo " "
echo "========================================================="
echo "Connecting to Firebase, you may be prompted to sign in..."
echo "========================================================="
if [ "$in_docker" = true ]; then
npx firebase login --no-localhost || { echo "Signing you into Firebase failed!" ; exit 1; }
else
npx firebase login || { echo "Signing you into Firebase failed!" ; exit 1; }
fi
echo " "
echo "================================================================="
echo "Please select the Firebase project you would like to deploy to..."
echo "================================================================="
echo " "
echo "When prompted for an alias, enter 'main'."
echo " "
npx firebase use --add || { echo "Connecting to your Firebase project failed!" ; exit 1; }
echo " "
echo "==========================="
echo "Building the application..."
echo "==========================="
npm run build || { echo "Building the application failed!" ; exit 1; }
echo " "
echo "========================================"
echo "Deploying the application to Firebase..."
echo "========================================"
npx firebase deploy || { echo "Deploying to Firebase failed!" ; exit 1; }
if [ ! "$do_skip_cors" = true ]; then
echo " "
echo "==================================="
echo "Authenticating with Google Cloud..."
echo "==================================="
"$gcloud_command" auth login || { echo "Authenticating Google Cloud failed!" ; exit 1; }
echo " "
echo "============================"
echo "Initialising Google Cloud..."
echo "============================"
"$gcloud_command" init --skip-diagnostics || { echo "Initialising Google Cloud failed!" ; exit 1; }
echo " "
echo "==============================================="
echo "Setting up the CORS settings for the website..."
echo "==============================================="
echo " "
echo "Please enter the URL of your project as a .appspot.com domain (e.g. misinformation-game.appspot.com):"
read -r URL || exit 1
"$gsutil_command" cors set src/config/cors.json "gs://$URL" || { echo "Uploading CORS settings failed!" ; exit 1; }
fi
echo " "
echo "======================"
echo "Successfully Deployed!"
echo "======================"
echo " "
echo "You should now be able to access your game at your project .web.app domain! (e.g. misinformation-game.web.app)"
echo " "