-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·116 lines (85 loc) · 2.89 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·116 lines (85 loc) · 2.89 KB
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
#!/usr/bin/env bash
PROJECT_ID="mcc-2016-g13-p2"
GCLOUD_ZONE="europe-west1-c"
echo 'Building Android application and deploying the backend service as a Google Container Engine cluster...'
echo 'NOTE: THIS WILL TAKE A WHILE!'
sleep 5
./build_apk.sh
sleep 10
echo 'Starting backend deployment...'
echo 'Installing dependencies...'
CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
apt-get update && apt-get -y install google-cloud-sdk kubectl docker.io make
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'Dependencies installed successfully.'
else
(>&2 echo 'ERROR: Dependencies could not be installed.')
exit $RESULT
fi
echo 'Building docker container...'
docker build -t eu.gcr.io/$PROJECT_ID/backend:v1 ./server
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'Docker container set up successfully.'
else
(>&2 echo 'ERROR: Docker container could not be built.')
exit $RESULT
fi
echo 'Authenticating to Google Cloud and pushing Docker container...'
gcloud auth activate-service-account tt-822@mcc-2016-g13-p2.iam.gserviceaccount.com --key-file=./server/key/mcc-2016-g13-p2-94921abc7259.json
gcloud config set compute/zone $GCLOUD_ZONE
gcloud config set project $PROJECT_ID
gcloud docker -- push eu.gcr.io/$PROJECT_ID/backend:v1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'Docker container pushed successfully.'
else
(>&2 echo 'ERROR: Docker container could not be pushed to Google Cloud.')
exit $RESULT
fi
echo 'Setting up cluster...'
gcloud container clusters create backend
gcloud config set container/use_client_certificate True
gcloud container clusters get-credentials backend
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'Initial cluster setup successful.'
else
(>&2 echo 'ERROR: Initial cluster setup failed.')
exit $RESULT
fi
echo 'Setting up MongoDB replica set...'
make -C server/cluster/sidecar/ add-replica
echo 'Waiting 90 seconds for DB container 1 to initialize...'
sleep 90
make -C server/cluster/sidecar/ add-replica
echo 'Waiting 90 seconds for DB container 2 to initialize...'
sleep 90
make -C server/cluster/sidecar/ add-replica
echo 'Waiting 90 seconds for DB container 3 to initialize...'
sleep 90
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'MongoDB replica set created successfully.'
else
(>&2 echo 'ERROR: MongoDB replica set creation failed.')
exit $RESULT
fi
echo 'Setting up backend application cluster...'
kubectl create -f server/cluster/backend.yaml
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo 'Cluster set up successfully.'
else
(>&2 echo 'ERROR: Cluster could not be set up.')
exit $RESULT
fi
echo 'Waiting 2 minutes for cluster to initialize...'
sleep 120
gcloud container clusters list
kubectl get pods
kubectl get services
echo 'Done.'