forked from spinnaker/spinnaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstallSpinnaker.sh
executable file
·421 lines (351 loc) · 11.8 KB
/
InstallSpinnaker.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/bin/bash
REPOSITORY_URL="https://dl.bintray.com/spinnaker/debians"
## This script install pre-requisites for Spinnaker
# To you put this file in the root of a web server
# curl -L https://foo.com/InstallSpinnaker.sh| sudo bash
# We can only currently support limited releases
# First guess what sort of operating system
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
DISTRO=$DISTRIB_ID
elif [ -f /etc/debian_version ]; then
DISTRO=Debian
# XXX or Ubuntu
elif [ -f /etc/redhat-release ]; then
if grep -iq cent /etc/redhat-release; then
DISTRO="CentOS"
elif grep -iq red /etc/redhat-release; then
DISTRO="RedHat"
fi
else
DISTRO=$(uname -s)
fi
# If not Ubuntu 14.xx.x or higher
if [ "$DISTRO" = "Ubuntu" ]; then
if [ "${DISTRIB_RELEASE%%.*}" -ne 14 ]; then
echo "Not a supported version of Ubuntu"
echo "Version is $DISTRIB_RELEASE we require 14.04 or higher"
exit 1
fi
else
echo "Not a supported operating system"
echo "Recommend you use Ubuntu 14.04 or higher"
exit 1
fi
function print_usage() {
cat <<EOF
usage: $0 [--cloud_provider <aws|google|none|both>]
[--aws_region <region>] [--google_region <region>]
[--quiet] [--dependencies_only]
[--repository <debian repository url>]
If run with no arguments you will be prompted for cloud provider and region
--cloud_provider <arg> currently supported are google, amazon and none
if "none" is specified you will need to edit
/etc/default/spinnaker manually
--aws_region <arg> default region for aws
--google_region <arg> default region for google
--google_zone <arg> default zone for google
--quiet sets cloud provider to "none", you will need to
edit /etc/default/spinnaker manually
cannot be used with --cloud_provider
--repository <url> Obtain Spinnaker packages from the <url>
rather than the default repository, which is
$REPOSITORY_URL
--dependencies_only Do not install any Spinnaker services.
Only install the dependencies. This is intended
for development scenarios only
EOF
}
function echo_status() {
if [ "x$QUIET" != "xtrue" ]; then
echo "$@"
fi
}
function process_args() {
while [[ $# > 0 ]]
do
local key="$1"
shift
case $key in
--cloud_provider)
CLOUD_PROVIDER="$1"
shift
;;
--aws_region)
AWS_REGION="$1"
shift
;;
--google_region)
GOOGLE_REGION="$1"
shift
;;
--google_zone)
GOOGLE_ZONE="$1"
shift
;;
--repository)
REPOSITORY_URL="$1"
shift
;;
--dependencies_only)
CLOUD_PROVIDER="none"
DEPENDENCIES_ONLY=true
;;
--quiet|-q)
QUIET="true"
CLOUD_PROVIDER="none"
AWS_REGION="none"
GOOGLE_REGION="none"
GOOGLE_ZONE="none"
shift
;;
--help|-help|-h)
print_usage
exit 13
;;
*)
echo "ERROR: Unknown argument '$key'"
exit -1
esac
done
}
function set_aws_region() {
if [ "x$AWS_REGION" == "x" ]; then
if [ "x$DEFAULT_AWS_REGION" == "x" ]; then
DEFAULT_AWS_REGION="us-west-2"
fi
read -e -p "Specify default aws region: " -i "$DEFAULT_AWS_REGION" AWS_REGION
AWS_REGION=`echo $AWS_REGION | tr '[:upper:]' '[:lower:]'`
fi
}
function set_google_region() {
if [ "x$GOOGLE_REGION" == "x" ]; then
if [ "x$DEFAULT_GOOGLE_REGION" == "x" ]; then
DEFAULT_GOOGLE_REGION="us-central1"
fi
read -e -p "Specify default google region: " -i "$DEFAULT_GOOGLE_REGION" GOOGLE_REGION
GOOGLE_REGION=`echo $GOOGLE_REGION | tr '[:upper:]' '[:lower:]'`
fi
}
function set_google_zone() {
if [ "x$GOOGLE_ZONE" == "x" ]; then
if [ "x$DEFAULT_GOOGLE_ZONE" == "x" ]; then
DEFAULT_GOOGLE_ZONE="us-central1-f"
fi
read -e -p "Specify default google zone: " -i "$DEFAULT_GOOGLE_ZONE" GOOGLE_ZONE
GOOGLE_ZONE=`echo $GOOGLE_ZONE | tr '[:upper:]' '[:lower:]'`
fi
}
GOOGLE_METADATA_URL="http://metadata.google.internal/computeMetadata/v1"
function get_google_metadata_value() {
local path="$1"
local value=$(curl -s -f -H "Metadata-Flavor: Google" \
$GOOGLE_METADATA_URL/$path)
if [[ $? -eq 0 ]]; then
echo "$value"
else
echo ""
fi
}
AWS_METADATA_URL="http://169.254.169.254/latest/meta-data"
function get_aws_metadata_value() {
local path="$1"
local value=$(curl -s -f $AWS_METADATA_URL/$path)
if [[ $? -eq 0 ]]; then
echo "$value"
else
echo ""
fi
}
function write_default_value() {
local name="$1"
local value="$2"
if egrep "^$name=" /etc/default/spinnaker > /dev/null; then
sudo sed -i.bak "s/^$name=.*/$name=$value/" /etc/default/spinnaker
else
sudo bash -c "echo $name=$value >> /etc/default/spinnaker"
fi
}
function set_google_defaults_from_environ() {
local project_id=$(get_google_metadata_value "project/project-id")
local qualified_zone=$(get_google_metadata_value "instance/zone")
local zone=$(basename $qualified_zone)
local region=${zone%-*}
DEFAULT_CLOUD_PROVIDER="google"
GOOGLE_PROJECT_ID=$project_id
DEFAULT_GOOGLE_REGION="$region"
DEFAULT_GOOGLE_ZONE="$zone"
}
function set_aws_defaults_from_environ() {
local zone=$(get_aws_metadata_value "/placement/availability-zone")
local region=${zone%?}
local mac_addr=$(get_aws_metadata_value "/network/interfaces/macs/")
local vpc_id=$(get_aws_metadata_value "/network/interfaces/macs/${mac_addr}vpc-id")
local subnet_id=$(get_aws_metadata_value "/network/interfaces/macs/${mac_addr}subnet-id")
DEFAULT_CLOUD_PROVIDER="aws"
DEFAULT_AWS_REGION="$region"
AWS_VPC_ID="$vpc_id"
AWS_SUBNET_ID="$subnet_id"
}
function set_defaults_from_environ() {
local on_platform=""
local google_project_id=$(get_google_metadata_value "/project/project-id")
if [[ -n "$google_project_id" ]]; then
on_platform="google"
set_google_defaults_from_environ
fi
local aws_az=$(get_aws_metadata_value "/placement/availability-zone")
if [[ -n "$aws_az" ]]; then
on_platform="aws"
set_aws_defaults_from_environ
fi
if [[ "$on_platform" != "" ]]; then
echo "Determined that you are running on $on_platform infrastructure."
else
echo "No providers are enabled by default."
fi
}
set_defaults_from_environ
process_args "$@"
if [ "x$CLOUD_PROVIDER" == "x" ]; then
read -e -p "Specify a cloud provider (aws|google|none|both): " -i "$DEFAULT_CLOUD_PROVIDER" CLOUD_PROVIDER
CLOUD_PROVIDER=`echo $CLOUD_PROVIDER | tr '[:upper:]' '[:lower:]'`
fi
case $CLOUD_PROVIDER in
a|aws|amazon)
CLOUD_PROVIDER="amazon"
set_aws_region
;;
g|gce|google)
CLOUD_PROVIDER="google"
set_google_region
set_google_zone
;;
n|no|none)
CLOUD_PROVIDER="none"
;;
both|all)
CLOUD_PROVIDER="both"
set_aws_region
set_google_region
set_google_zone
;;
*)
echo "ERROR: invalid cloud provider '$CLOUD_PROVIDER'"
print_usage
exit -1
esac
## PPAs ##
# Add PPAs for software that is not necessarily in sync with Ubuntu releases
# Redis
# https://launchpad.net/~chris-lea/+archive/ubuntu/redis-server
sudo add-apt-repository -y ppa:chris-lea/redis-server
# Cassandra
# http://docs.datastax.com/en/cassandra/2.1/cassandra/install/installDeb_t.html
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
echo "deb http://debian.datastax.com/community/ stable main" | sudo tee /etc/apt/sources.list.d/datastax.list > /dev/null
# Java 8
# https://launchpad.net/~openjdk-r/+archive/ubuntu/ppa
sudo add-apt-repository -y ppa:openjdk-r/ppa
# https://launchpad.net/~openjdk-r/+archive/ubuntu/ppa
# add-apt-repository -y ppa:webupd8team/java
# echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
# Spinnaker
# DL Repo goes here
REPOSITORY_HOST=$(echo $REPOSITORY_URL | cut -d/ -f3)
if [ "$REPOSITORY_HOST" == "dl.bintray.com" ]; then
REPOSITORY_ORG=$(echo $REPOSITORY_URL | cut -d/ -f4)
curl "https://bintray.com/user/downloadSubjectPublicKey?username=$REPOSITORY_ORG" | sudo apt-key add -
fi
echo "deb $REPOSITORY_URL trusty spinnaker" | sudo tee /etc/apt/sources.list.d/spinnaker-dev.list > /dev/null
## Install software
# "service cassandra status" is currently broken in Ubuntu grep in the script is grepping for things that do not exist
# Cassandra 2.x can ship with RPC disabeld to enable run "nodetool enablethrift"
sudo apt-get update
## Java
# apt-get install -y oracle-java8-installer
sudo apt-get install -y openjdk-8-jdk
## Cassandra
sudo apt-get install -y --force-yes cassandra=2.1.11 cassandra-tools=2.1.11
sudo apt-mark hold cassandra cassandra-tools
# Let cassandra start
if ! nc -z localhost 7199; then
echo_status "Waiting for Cassandra to start..."
while ! nc -z localhost 7199; do
sleep 1
done
echo_status "Cassandra is ready."
fi
while ! $(nodetool enablethrift >& /dev/null); do
sleep 1
echo_status "Retrying..."
done
# apt-get install dsc21
## Packer
sudo apt-get install -y unzip
wget https://releases.hashicorp.com/packer/0.8.6/packer_0.8.6_linux_amd64.zip
sudo unzip -q packer_0.8.6_linux_amd64.zip -d /usr/bin
rm -f packer_0.8.6_linux_amd64.zip
if [[ "x$DEPENDENCIES_ONLY" != "x" ]]; then
exit 0
fi
## Spinnaker
sudo apt-get install -y --force-yes --allow-unauthenticated spinnaker
if [[ "${CLOUD_PROVIDER,,}" == "amazon" || "${CLOUD_PROVIDER,,}" == "google" || "${CLOUD_PROVIDER,,}" == "both" ]]; then
case $CLOUD_PROVIDER in
amazon)
write_default_value "SPINNAKER_AWS_ENABLED" "true"
write_default_value "SPINNAKER_AWS_DEFAULT_REGION" $AWS_REGION
write_default_value "SPINNAKER_GOOGLE_ENABLED" "false"
write_default_value "AWS_VPC_ID" $AWS_VPC_ID
write_default_value "AWS_SUBNET_ID" $AWS_SUBNET_ID
;;
google)
write_default_value "SPINNAKER_GOOGLE_ENABLED" "true"
write_default_value "SPINNAKER_GOOGLE_DEFAULT_REGION" $GOOGLE_REGION
write_default_value "SPINNAKER_GOOGLE_DEFAULT_ZONE" $GOOGLE_ZONE
write_default_value "SPINNAKER_AWS_ENABLED" "false"
;;
both)
write_default_value "SPINNAKER_AWS_ENABLED" "true"
write_default_value "SPINNAKER_AWS_DEFAULT_REGION" $AWS_REGION
write_default_value "SPINNAKER_GOOGLE_ENABLED" "true"
write_default_value "SPINNAKER_GOOGLE_DEFAULT_REGION" $GOOGLE_REGION
write_default_value "SPINNAKER_GOOGLE_DEFAULT_ZONE" $GOOGLE_ZONE
write_default_value "AWS_VPC_ID" $AWS_VPC_ID
write_default_value "AWS_SUBNET_ID" $AWS_SUBNET_ID
;;
esac
else
echo "Not enabling a cloud provider"
fi
if [ "x$GOOGLE_PROJECT_ID" != "x" ]; then
write_default_value "SPINNAKER_GOOGLE_PROJECT_ID" $GOOGLE_PROJECT_ID
fi
## Remove
if [ -z `getent group spinnaker` ]; then
sudo groupadd spinnaker
fi
if [ -z `getent passwd spinnaker` ]; then
sudo useradd --gid spinnaker -m --home-dir /home/spinnaker spinnaker
fi
if [ ! -d /home/spinnaker ]; then
sudo mkdir -p /home/spinnaker/.aws
sudo chown -R spinnaker:spinnaker /home/spinnaker
fi
##
sudo start spinnaker
cat <<EOF
To stop all spinnaker subsystems:
sudo stop spinnaker
To start all spinnaker subsystems:
sudo start spinnaker
To configure the available cloud providers:
Edit: /etc/default/spinnaker
And/Or: /opt/spinnaker/config/spinnaker-local.yml
Next, ensure that the regions configured in deck are up-to-date:
sudo /opt/spinnaker/bin/reconfigure_spinnaker.sh
Lastly, restart clouddriver and rosco with:
sudo service clouddriver restart
sudo service rosco restart
EOF