-
Notifications
You must be signed in to change notification settings - Fork 12
/
viur-gcloud-setup.sh
executable file
·133 lines (117 loc) · 4.19 KB
/
viur-gcloud-setup.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
#!/bin/bash
project=$1
if [ -z "$project" ]
then
echo "Usage: $0 PROJECT_ID"
exit 1
fi
# Check if user is authorized with gcloud
echo "Check if user is authorized with gcloud..."
gcloud auth print-access-token >/dev/null 2>&1
if [ $? -ne 0 ]
then
# app does not seem to exist, will prompt for creation
echo "##############################################################"
echo "# Please authenticate your Google user with gcloud SDK to #"
echo "# execute administrative commands. #"
echo "# In this step, a separate browser window opens to #"
echo "# authenticate. #"
echo "# This step is only required once on this computer. #"
echo "##############################################################"
echo "Are you ready? [Y/n]"
read Y
if [[ ! ( "$Y" = "y" || "$Y" = "Y" || -z "$Y" ) ]]
then
echo "User aborted."
exit 1
fi
gcloud auth login --no-browser
if [ $? -ne 0 ]
then
exit 1
fi
fi
# Check if app already exists
gcloud app describe --project=$project >/dev/null 2>&1
if [ $? -ne 0 ]
then
# app does not seem to exist, will prompt for creation
echo "##############################################################"
echo "# Please check and confirm that your project is created and #"
echo "# connected with a billing account in Google Cloud console. #"
echo "# Otherwise, some of the following calls may fail. #"
echo "##############################################################"
echo "Continue? [Y/n]"
read Y
if [[ ! ( "$Y" = "y" || "$Y" = "Y" || -z "$Y" ) ]]
then
echo "User aborted."
exit 1
fi
set -ex # enable exit on error
# Create the app engine app
gcloud app create --project=$project --region=europe-west3
else
set -ex # enable exit on error
fi
# Activate APIs and Services
for service in \
datastore.googleapis.com \
firestore.googleapis.com \
iamcredentials.googleapis.com \
cloudbuild.googleapis.com \
cloudtasks.googleapis.com \
cloudscheduler.googleapis.com \
secretmanager.googleapis.com
do
gcloud services enable --project=$project $service
done
# Configure Google Cloud Storage
gsutil uniformbucketlevelaccess set on gs://$project.appspot.com/
# Deployment of cron, queue and index settings
pushd deploy
for yaml in cron.yaml queue.yaml index.yaml
do
gcloud app deploy -q --project=$project $yaml >/dev/null 2>&1
done
set +ex # disable error exit and debug
# Check if app engine default credentials are set
echo "Check if app engine default credentials are set..."
gcloud auth application-default print-access-token >/dev/null 2>&1
if [ $? -ne 0 ]
then
# app does not seem to exist, will prompt for creation
echo "##############################################################"
echo "# Please authenticate your Google user with gcloud SDK now #"
echo "# to set the application default user. This step is required #"
echo "# to run ViUR applications locally without further #"
echo "# credentials that must be supplied from a file. #"
echo "# This step is only required once on this computer. #"
echo "##############################################################"
echo "Are you ready? [Y/n]"
read Y
if [[ ! ( "$Y" = "y" || "$Y" = "Y" || -z "$Y" ) ]]
then
echo "User aborted."
exit 1
fi
gcloud auth application-default login
if [ $? -ne 0 ]
then
exit 1
fi
fi
echo
echo "##############################################################"
echo "# All done! #"
echo "# You should now be able to run your project locally with #"
echo "# #"
echo "# viur run #"
echo "# #"
echo "# At first run, it might happen that some functions are #"
echo "# causing error 500 because indexes are not immediately #"
echo "# served. Therefore, maybe wait a few minutes. #"
echo "# #"
echo "# Have a nice day. #"
echo "##############################################################"
echo