-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_app.sh
executable file
·83 lines (71 loc) · 2.49 KB
/
install_app.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
#!/usr/bin/env bash
set -e
if [[ -z $PROJECT_PREFIX ]]; then
PROJECT_NAME=vincent-$(date +%s)
else
PROJECT_NAME=${PROJECT_PREFIX}-$(date +%s)
fi
if [[ -z $REGION ]]; then
REGION=us-west2
fi
QUEUES=("post-created" "post-notify" "ack-connection" "request-connection" "comment-created")
gcloud components update --quiet
# create project
echo "Creating Project ${PROJECT_NAME}..."
gcloud projects create ${PROJECT_NAME} --name="Social Media" --quiet
gcloud config set project ${PROJECT_NAME}
# check to see if gcloud beta component is installed
beta_installed=$(gcloud components list 2>&1|grep "gcloud Beta Commands")
if [[ -z $beta_installed ]]; then
echo
echo "Installing beta components..."
gcloud components install beta
fi
# need to link billing account to project in order to
# be able to enable cloudbuild and cloudtasks
# billing account setup
echo
echo "Linking billing account to project..."
gcloud services enable cloudbilling.googleapis.com
BILLING_ACCOUNT=$(gcloud beta billing accounts list --format=config 2>&1|grep "name = "|cut -d' ' -f3|cut -d'/' -f2)
gcloud beta billing projects link ${PROJECT_NAME} --billing-account=$BILLING_ACCOUNT
# install services
echo
echo "Enabling cloudbuild and cloudtasks services..."
gcloud services enable cloudbuild.googleapis.com
gcloud services enable cloudtasks.googleapis.com
echo
echo "Creating app..."
gcloud app create --region=$REGION --quiet
# wait for service account to be created
echo
echo "Waiting for service account to be created..."
service_account_created=$(gcloud iam service-accounts list|grep "${PROJECT_NAME}@appspot.gserviceaccount.com")
while [[ -z $service_account_created ]]
do
service_account_created=$(gcloud iam service-accounts list|grep "${PROJECT_NAME}@appspot.gserviceaccount.com")
done
echo
echo "Creating and downloading service account credentials..."
gcloud iam service-accounts keys create service-account-creds.json --iam-account=${PROJECT_NAME}@appspot.gserviceaccount.com
echo
echo "Creating task queues..."
for queue in "${QUEUES[@]}"
do gcloud tasks queues create $queue
done
echo
echo "Creating datastore indexes..."
gcloud datastore indexes create index.yaml --quiet
#echo "waiting to ensure app is completely created"
#sleep 20
echo
echo "Deploying app..."
function keep_trying {
echo
echo "App deploy failed. Sleeping for 60 seconds then trying again"
sleep 60
gcloud app deploy --quiet
}
trap keep_trying ERR
gcloud app deploy --quiet
echo "Deployed to ${PROJECT_NAME}. Visit https://${PROJECT_NAME}.wl.r.appspot.com"