This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
init_project.sh
executable file
·50 lines (41 loc) · 1.96 KB
/
init_project.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
#!/bin/bash
if [[ -z "${PROJ_ID}" ]]; then
echo "Error: \$PROJ_ID environment variable is undefined"
echo " To locate your project ID, see https://support.google.com/cloud/answer/6158840?hl=en"
echo " To set it, run \"export PROJ_ID=my-proj-id\""
exit 1
elif [[ ! -f WORKSPACE ]]; then
echo "Error: Must be run from upvote root directory"
exit 1
elif [[ -z $(which gcloud) ]]; then
echo "Error: gcloud not found on PATH"
echo " To install the Cloud SDK, see https://cloud.google.com/sdk/downloads"
exit 1
elif [[ -z $(which bazel) ]]; then
echo "Error: bazel build tool not found on PATH"
echo " To install Bazel, see https://docs.bazel.build/versions/master/install.html"
exit 1
fi
printf 'Initializing Upvote for GCP project: "%s"\n' "${PROJ_ID}"
set -xe
gcloud config set project "${PROJ_ID}"
echo Enabling App Engine...
if [[ "$(gcloud app describe --format='value(id)' 2> /dev/null)" != "${PROJ_ID}" ]]; then
gcloud app create
fi
echo Enabling APIs used by Upvote...
gcloud services enable cloudkms.googleapis.com
gcloud services enable bigquery-json.googleapis.com
echo Creating encryption keys used to store Upvote API secrets...
gcloud kms keyrings create ring --location=global
gcloud kms keys create virustotal --purpose=encryption --keyring=ring --location=global
echo Granting necessary permissions to App Engine...
SERVICE_ACCOUNT=$(gcloud iam service-accounts list --filter="App Engine app default service account" --format="value(email)")
gcloud projects add-iam-policy-binding "${PROJ_ID}" --member serviceAccount:"${SERVICE_ACCOUNT}" --role roles/cloudkms.cryptoKeyEncrypterDecrypter
echo Configuring App Engine...
./manage_crons.py disable_all
echo Deploying temporary default version to App Engine...
# NOTE: This is expected to fail but continue processing.
bazel run upvote/gae:monolith_binary.deploy -- "${PROJ_ID}" app.yaml 2> /dev/null || echo
echo Deploying to App Engine...
bazel run upvote/gae:monolith_binary.deploy -- "${PROJ_ID}" app.yaml