This repository was archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathrun.bash
More file actions
executable file
·820 lines (750 loc) · 26.6 KB
/
run.bash
File metadata and controls
executable file
·820 lines (750 loc) · 26.6 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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#!/bin/bash -ue
# Copyright 2017 tsuru-now authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -eu
release=""
codename=""
host_ip=""
private_ip=""
host_name=""
set_interface=""
is_debug=""
docker_node=""
set_interface=""
install_func=install_all
pool="theonepool"
mongohost="127.0.0.1"
mongoport="27017"
dockerhost="127.0.0.1"
dockerport="2375"
registryhost=""
registryport="5000"
adminuser="[email protected]"
adminpassword="admin123"
install_tsuru_source=0
tsuru_package_source="stable"
hook_url=https://raw.githubusercontent.com/tsuru/tsuru/master/misc/git-hooks/pre-receive
hook_name=pre-receive
git_envs=(A=B)
ext_repository=""
export DEBIAN_FRONTEND=noninteractive
declare -A DISTMAP=(
[wheezy]=wheezy-backports
[precise]=precise
[saucy]=saucy
[trusty]=trusty
[utopic]=utopic
)
TSURU_CONF=$(cat <<EOF
listen: "0.0.0.0:8080"
host: http://{{{HOST_IP}}}:8080
debug: true
admin-team: admin
database:
url: {{{MONGO_HOST}}}:{{{MONGO_PORT}}}
name: tsurudb
git:
unit-repo: /home/application/current
api-server: http://127.0.0.1:8000
auth:
user-registration: true
scheme: native
routers:
hipache:
type: hipache
domain: {{{HOST_NAME}}}
redis-server: 127.0.0.1:6379
repo-manager: gandalf
provisioner: docker
queue:
mongo-url: {{{MONGO_HOST}}}:{{{MONGO_PORT}}}
mongo-database: tsuru_queue
pubsub:
redis-host: 127.0.0.1
redis-port: 6379
docker:
bs:
image: tsuru/bs:v1
reporter-interval: 10
socket: /var/run/docker.sock
collection: docker_containers
port-allocator: tsuru
registry: {{{REGISTRY_HOST}}}:$registryport
repository-namespace: tsuru
router: hipache
deploy-cmd: /var/lib/tsuru/deploy
cluster:
storage: mongodb
mongo-url: {{{MONGO_HOST}}}:{{{MONGO_PORT}}}
mongo-database: dockercluster
run-cmd:
bin: /var/lib/tsuru/start
port: "8888"
ssh:
add-key-cmd: /var/lib/tsuru/add-key
user: ubuntu
EOF
)
function error {
echo "$@" 1>&2
}
function running_port {
local appname=$1
running_addr "${appname}" | sed "s/.*://"
}
function running_addr {
local appname=$1
for _ in {1..30}; do
sleep 0.5
local addr=$(sudo netstat -tnlp | grep "${appname}" | tr -s " " | cut -d' ' -f 4 | sort | head -n1)
if [[ $addr != "" ]]; then
echo "${addr}"
break
fi
echo "Waiting for ${appname}..." 1>&2
done
}
function installed_version {
local cmdid=${1-}
local minversion=${2-}
local version=${3-}
local max_version=$(echo -e "${minversion}min\n$version" | sort -V | tail -n 1)
local install_var=$(eval echo $`echo '{force_install_'`${cmdid}`echo '-}'`)
if [[ $install_var != "1" && $max_version != "${minversion}min" ]]; then
echo "${max_version}"
fi
}
function get_inet_addr() {
# Return IP address based on ifconfig's output
/sbin/ifconfig | grep -A1 $1 2> /dev/null | grep "inet addr" | tail -n1 | \
sed "s/[^:]*:\([0-9.]*\).*/\1/"
}
function public_ip {
# Try to take the public IP using AWS EC2's metadata API:
local ip=$(curl -s -L -m2 -f http://169.254.169.254/latest/meta-data/public-ipv4 || true)
# Try to use DigitalOcean's metadata API as fallback:
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(curl -s -L -m2 -f http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address || true)
fi
# Try via ifconfig
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(get_inet_addr eth)
fi
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(get_inet_addr ens)
fi
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(get_inet_addr venet0)
fi
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(get_inet_addr wlan)
fi
# Try to access an external API to discover public IP
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(curl -s -L -m2 'https://api.ipify.org' || true)
fi
# Damn, it!
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
error "Couldn't find a suitable public IP. Try using --host-ip option."
exit 1
fi
echo "${ip}"
}
function local_ip {
# Try to take the public IP using AWS EC2's metadata API:
local ip=$(curl -s -L -m2 -f http://169.254.169.254/latest/meta-data/local-ipv4 || true)
# Try to use DigitalOcean's metadata API as fallback:
if [[ "$ip" == "" || "$ip" == "not found" ]]; then
ip=$(curl -s -L -m2 -f http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address || true)
fi
if [[ "$ip" == "not found" ]]; then
ip=""
fi
echo "${ip}"
}
function set_host {
if [[ "$host_ip" && "$set_interface" ]]; then
sudo ifconfig lo:0 $host_ip netmask 255.255.255.255 up
fi
if [[ $host_ip == "" ]]; then
host_ip=$(public_ip)
fi
if [[ $host_ip == "127.0.0.1" ]]; then
echo "Couldn't find suitable host_ip, please run with --host-ip <external ip>"
exit 1
fi
echo "Chosen host ip: $host_ip. You can override with --host-ip <external ip>"
if [[ $host_name == "" ]]; then
host_name="$host_ip.nip.io"
fi
echo "$host_ip $host_name" | sudo tee -a /etc/hosts
echo "Chosen host name: $host_name. You can override with --host-name <hostname>"
}
function set_local_host {
if [[ $private_ip == "" ]]; then
private_ip=$(local_ip)
fi
if [[ $private_ip == "" ]]; then
private_ip=$(public_ip)
fi
if [[ $private_ip == "127.0.0.1" ]]; then
echo "Couldn't find suitable local_ip, please run with --host-ip <external ip>"
exit 1
fi
}
function check_support {
which apt-get > /dev/null
if [ $? -ne 0 ]; then
error "Error: apt-get should be available on the system"
exit 1
fi
distid=$(lsb_release -is)
release=$(lsb_release -rs)
codename=$(lsb_release -cs)
if [[ $distid == "Debian" && $(echo $release | awk '{printf("%d", $1)}') -lt 8 ]]; then
error "Error: This script requires Debian release >= 8"
fi
echo "Detect ${distid} ${release} (${codename}), supported system"
}
function install_basic_deps {
local tsuru_package_source=$1
echo "Updating apt-get and installing basic dependencies (this could take a while)..."
if [[ $distid == "Ubuntu" ]]; then
sudo perl -i -pe 's/^# *(.+)(trusty|trusty-updates|trusty-security) multiverse$/$1$2 multiverse/gi' /etc/apt/sources.list
fi
sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r) -qqy
sudo apt-get install jq screen curl mercurial git bzr \
software-properties-common apt-transport-https -y
if [[ $ext_repository ]]; then
curl -sS ${ext_repository}/public.key | sudo apt-key add -
echo "deb ${ext_repository} ${DISTMAP[$codename]} main contrib" | sudo tee /etc/apt/sources.list.d/tsuru-deb.list
echo "deb-src ${ext_repository} ${DISTMAP[$codename]} main contrib" | sudo tee -a /etc/apt/sources.list.d/tsuru-deb.list
else
curl -s https://packagecloud.io/install/repositories/tsuru/${tsuru_package_source}/script.deb.sh | sudo bash
fi
sudo apt-get update
}
function install_docker {
if [[ ${registryhost} == "" ]]; then
registryhost=${dockerhost}
fi
local version=$(docker -v | awk -F '[ ,]+' '{ print $3 }')
local iversion=$(installed_version docker 0.20.0 "${version}")
if [[ $iversion != "" ]]; then
echo "Skipping docker installation, version installed: $iversion"
else
echo "Installing docker..."
curl -sSL https://get.docker.com/ | sudo sh
fi
if [[ `which systemctl` != "" ]] && [[ `systemctl is-system-running` != "offline" ]]; then
sudo -E sh -c "mkdir -p /etc/systemd/system/docker.service.d"
sudo -E sh -c "echo '[Service]\nExecStart=\nExecStart=/usr/bin/dockerd \$DOCKER_OPTS -H tcp://127.0.0.1:${dockerport} -H unix:///var/run/docker.sock --insecure-registry=${registryhost}:${registryport}' > /etc/systemd/system/docker.service.d/tsuru.conf"
sudo systemctl daemon-reload
else
local opts=$(bash -c 'source /etc/default/docker && echo $DOCKER_OPTS')
if [[ ! $opts =~ :// ]]; then
echo "Changing /etc/default/docker to listen on tcp://127.0.0.1:${dockerport}..."
echo "DOCKER_OPTS=\"\$DOCKER_OPTS -H tcp://127.0.0.1:${dockerport} -H unix:///var/run/docker.sock --insecure-registry=${registryhost}:${registryport}\"" | sudo tee -a /etc/default/docker > /dev/null
fi
fi
sudo service docker stop 1>&2 2>/dev/null || true
sudo service docker start
sleep 5
dockerport=$(running_port docker)
if [[ $dockerport == "" ]]; then
echo "Error: Couldn't find docker port, please check /var/log/upstart/docker.log for more information"
echo "/var/log/upstart/docker.log contents:"
cat /var/log/upstart/docker.log
exit 1
fi
echo "docker found running at $dockerhost:$dockerport"
local home_host=$(bash -ic 'source ~/.bashrc && echo $DOCKER_HOST')
if [[ $home_host != "tcp://$dockerhost:$dockerport" ]]; then
echo "Adding DOCKER_HOST to ~/.bashrc"
echo -e "export DOCKER_HOST=tcp://$dockerhost:$dockerport" | tee -a ~/.bashrc > /dev/null
fi
export DOCKER_HOST=tcp://$dockerhost:$dockerport
docker_node="$docker_node $dockerhost:$dockerport"
}
function install_docker_registry {
echo "Installing docker-registry..."
sudo mkdir -p /var/lib/registry
docker rm -f registry || true
docker run -d -p ${registryport}:${registryport} -e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry -v /var/lib/registry:/var/lib/registry --restart=always --name registry registry:2
}
function install_mongo {
docker rm -f mongodb || true
docker run -d -p 27017:27017 --net=host --restart=always --name mongodb mongo
}
function install_redis {
docker rm -f redis || true
docker run -d -p 6379:6379 --restart=always --name redis redis
}
function install_planb {
docker rm -f tsuru_planb || true
docker run -d --net=host --restart=always --name tsuru_planb tsuru/planb:v1 --listen ":80"
}
function install_gandalf {
sudo apt-get install gandalf-server -y
local hook_dir=/home/git/bare-template/hooks
sudo mkdir -p $hook_dir
sudo curl -sSL ${hook_url} -o ${hook_dir}/${hook_name}
sudo chmod +x ${hook_dir}/${hook_name}
sudo chown -R git:git /home/git/bare-template
sudo sed "s/^\(host: \).*$/\1${host_name}/" /etc/gandalf.conf -i
sudo sed "s/^#\(\s*template: \).*$/\1\/home\/git\/bare-template/" /etc/gandalf.conf -i
sudo service gandalf-server stop 1>&2 2>/dev/null || true
sudo service gandalf-server start
sleep 5
local gandalfaddr=$(running_addr gandalf)
if [[ $gandalfaddr == "" ]]; then
echo "Error: Couldn't find gandalf addr, please check /var/log/upstart/gandalf-server.log for more information"
echo "/var/log/upstart/gandalf-server.log contents:"
cat /var/log/upstart/gandalf-server.log
exit 1
fi
echo "gandalf found running at $gandalfaddr"
}
function install_go {
local version=$(go version 2>/dev/null | sed -e 's/go version[^0-9]*\([0-9.]*\).*/\1/')
local iversion=$(installed_version go 1.1.0 "${version}")
if [[ $iversion != "" ]]; then
echo "Skipping go installation, version installed: $iversion"
else
echo "Installing go..."
sudo apt-add-repository ppa:gophers/archive -y
sudo apt-get update
sudo apt-get install golang-1.8 -y
echo -e "export PATH=$PATH:/usr/lib/go-1.8/bin" | tee -a ~/.bashrc > /dev/null
export PATH=$PATH:/usr/lib/go-1.8/bin
fi
if [[ ${GOPATH-} == "" ]]; then
export GOPATH=$HOME/go
fi
mkdir -p $GOPATH
local bash_gopath=$(bash -ic 'unset GOPATH; source ~/.bashrc && echo $GOPATH')
if [[ $bash_gopath != $GOPATH ]]; then
echo "Adding GOPATH=$GOPATH to ~/.bashrc"
echo -e "export GOPATH=$GOPATH" | tee -a ~/.bashrc > /dev/null
fi
}
function install_test_deps {
echo "Installing test dependencies..."
sudo apt-get -y install xmlsec1 libsasl2-dev
}
function config_tsuru_pre {
sudo mkdir -p /etc/tsuru
echo "$TSURU_CONF" | sudo tee /etc/tsuru/tsuru.conf > /dev/null
sudo sed -i.old -e "s/{{{HOST_IP}}}/${host_ip}/g" /etc/tsuru/tsuru.conf
sudo sed -i.old -e "s/{{{PRIVATE_IP}}}/${dockerhost}/g" /etc/tsuru/tsuru.conf
sudo sed -i.old -e "s/{{{REGISTRY_HOST}}}/${registryhost}/g" /etc/tsuru/tsuru.conf
sudo sed -i.old -e "s/{{{HOST_NAME}}}/${host_name}/g" /etc/tsuru/tsuru.conf
sudo sed -i.old -e "s/{{{MONGO_HOST}}}/${mongohost}/g" /etc/tsuru/tsuru.conf
sudo sed -i.old -e "s/{{{MONGO_PORT}}}/${mongoport}/g" /etc/tsuru/tsuru.conf
if [[ -e /etc/default/tsuru-server ]]; then
sudo sed -i.old -e 's/=no/=yes/' /etc/default/tsuru-server
fi
}
function config_tsuru_post {
tsuru target-remove default
tsuru target-add default "${private_ip}:8080" || true
tsuru target-set default
}
function create_initial_user {
echo "Creating initial admin user..."
yes $adminpassword | tsurud root-user-create $adminuser || true
yes $adminpassword | tsuru login $adminuser
tsuru team-create admin || true
}
function enable_initial_user {
mkdir -p ~/.ssh
if ! grep -Pzo "Host ${private_ip}\s+StrictHostKeyChecking no" ~/.ssh/config >/dev/null; then
echo -e "Host ${private_ip}\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
fi
if ! grep -Pzo "Host ${private_ip}\s+StrictHostKeyChecking no" ~/.ssh/config >/dev/null; then
echo -e "Host ${private_ip}\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
fi
if [[ ! -e ~/.ssh/id_rsa ]]; then
yes | ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa > /dev/null
fi
tsuru key-add -f rsa ~/.ssh/id_rsa.pub || true
}
function add_default_roles {
tsuru role-add team-create global || true
tsuru role-permission-add team-create role.update team.create || true
tsuru role-add team-member team || true
tsuru role-permission-add team-member app service-instance team || true
tsuru role-default-add --team-create team-member || true
tsuru role-default-add --user-create team-create || true
}
function add_as_docker_node {
echo "Adding docker node to pool..."
tsuru pool-add $pool -p -d 2>/dev/null || tsuru pool-add $pool 2>/dev/null || true
amount=0
for node in $docker_node; do
tsuru node-add --register address="http://${node}" pool=$pool 2>/dev/null || true
amount=$((amount+1))
done
set +e
status=1
while [ $status != 0 ]; do
tsuru node-list | grep "| http://" | grep ready | wc -l | grep -q "${amount}$"
status=$?
done
set -e
}
function install_platform {
echo "Installing platform container..."
local has_plat=$((tsuru platform-list | grep "${1}"$) || true)
if [[ ${has_plat} == "" ]]; then
tsuru platform-add ${1} -i "tsuru/${1}"
fi
}
function install_dashboard {
echo "Installing tsuru-dashboard..."
tsuru app-create tsuru-dashboard python -o $pool -t admin || true
pushd ~/
if [[ ! -d ~/tsuru-dashboard ]]; then
git clone https://github.com/tsuru/tsuru-dashboard
fi
pushd tsuru-dashboard
git remote add tsuru "git@${private_ip}:tsuru-dashboard.git" || true
git reset --hard
git clean -dfx
git pull
git push tsuru master
popd
popd
}
function install_tsuru_pkg {
echo "Installing Tsuru from deb package..."
sudo apt-get install tsuru-server tsuru-client -y
sudo service tsurud stop >/dev/null 2>&1 || true
config_tsuru_pre
sudo service tsurud start
sleep 5
}
function install_tsuru_client {
echo "Installing Tsuru client from deb package..."
sudo apt-get install tsuru-client -qqy
}
function install_tsuru_src {
echo "Installing Tsuru from source (this could take some minutes)..."
if [[ -e ${GOPATH}/src/github.com/tsuru/tsuru ]]; then
pushd "${GOPATH}/src/github.com/tsuru/tsuru"
git reset --hard && git clean -dfx && git pull
popd
else
mkdir -p "${GOPATH}/src/github.com/tsuru/tsuru"
pushd "${GOPATH}/src/github.com/tsuru/tsuru"
git clone https://github.com/tsuru/tsuru .
popd
fi
go get github.com/tsuru/tsuru/cmd/tsurud
go get github.com/tsuru/tsuru-client/tsuru
sudo cp $(echo "${GOPATH}" | awk -F ':' '{print $1}')/bin/{tsurud,tsuru} /usr/local/bin
screen -X -S api quit || true
screen -S api -d -m tsurud api --config=/etc/tsuru/tsuru.conf
local tsurudaddr=$(running_addr tsurud)
if [[ $tsurudaddr == "" ]]; then
echo "Error: Couldn't find tsurud addr, please check /var/log/syslog for more information"
exit 1
fi
echo "tsurud api found running at $tsurudaddr"
}
function config_git_key {
local tsuru_token=$(bash -ic 'source ~git/.bash_profile && echo $TSURU_TOKEN')
if [[ $tsuru_token == "" ]]; then
echo "Adding tsurud token to ~git/.bash_profile"
local token=$(tsurud token || tsr token)
echo "export TSURU_TOKEN=$token" | sudo tee -a ~git/.bash_profile > /dev/null
fi
local tsuru_host=$(bash -ic 'source ~git/.bash_profile && echo $TSURU_HOST')
if [[ $tsuru_host != "$private_ip:8080" ]]; then
echo "Adding tsurud host to ~git/.bash_profile"
echo "export TSURU_HOST=$private_ip:8080" | sudo tee -a ~git/.bash_profile > /dev/null
fi
sudo chown -R git:git ~git/.bash_profile
}
function add_git_envs {
if [[ "${#git_envs[@]}" -gt 1 ]]; then
echo "Serializing provided env vars to ~git/.bash_profile"
echo export ${git_envs[@]:1} | sudo tee -a ~git/.bash_profile > /dev/null
fi
}
function banner_ansii {
echo -e ' \x1B[38;2;37;184;108mo. \x1B[0m'
echo -e ' _ \x1B[38;2;37;184;108m:8o. .:: \x1B[0m'
echo -e ' | |_ ___ _ _ _ __ _ _ \x1B[38;2;37;184;108m.888o .o: . \x1B[0m'
echo -e ' | __/ __| | | | \047__| | | | \x1B[38;2;37;184;108mO888O: .oO: \x1B[0m'
echo -e ' | |_\__ \ |_| | | | |_| | \x1B[38;2;37;184;108mO88888O. :O8O. \x1B[0m'
echo -e ' \__|___/\__,_|_| \__,_| \x1B[38;2;37;184;108mO8888888OoOo \x1B[0m'
echo -e ' \x1B[38;2;37;184;108m.O88888888o: \x1B[0m'
}
function install_all {
check_support
install_basic_deps ${tsuru_package_source-"stable"}
set_local_host
set_host
install_docker
if [[ "${registryhost}" == "${dockerhost}" ]]; then
install_docker_registry
fi
install_redis
install_mongo
install_planb
install_gandalf
if [[ ${install_tsuru_source-} == "1" ]]; then
config_tsuru_pre
install_go
install_tsuru_src
install_test_deps
else
install_tsuru_pkg
fi
config_tsuru_post
config_git_key
add_git_envs
create_initial_user
enable_initial_user
add_default_roles
add_as_docker_node
install_platform python
install_platform static
if [[ ${without_dashboard-} != "1" ]]; then
install_dashboard
fi
echo '######################## DONE! ########################'
echo
banner_ansii
echo
echo "Some information about your tsuru installation:"
echo
echo "Admin user: ${adminuser}"
echo "Admin password: ${adminpassword} (PLEASE CHANGE RUNNING: tsuru change-password)"
echo "Target address: http://$host_ip:8080"
if [[ ${without_dashboard-} != "1" ]]; then
local cont_id=$(docker ps | grep tsuru-dashboard | cut -d ' ' -f 1)
local dashboard_port=$(docker inspect $cont_id | grep HostPort | head -n1 | sed "s/[^0-9]//g")
echo "Dashboard address: http://$host_ip:$dashboard_port"
echo
echo "You should run \`source ~/.bashrc\` on your current terminal."
echo
echo "Installed apps:"
sleep 1
tsuru app-list
fi
}
function install_server {
check_support
install_basic_deps ${tsuru_package_source-"stable"}
set_local_host
set_host
install_docker
if [[ "${registryhost}" == "${dockerhost}" ]]; then
install_docker_registry
fi
install_redis
install_mongo
install_planb
install_gandalf
install_tsuru_pkg
config_tsuru_post
config_git_key
add_git_envs
create_initial_user
enable_initial_user
add_default_roles
add_as_docker_node
install_platform python
echo '######################## DONE! ########################'
echo
banner_ansii
echo
echo "Some information about your tsuru installation:"
echo
echo "Admin user: ${adminuser}"
echo "Admin password: ${adminpassword} (PLEASE CHANGE RUNNING: tsuru change-password)"
echo "Target address: $host_ip:8080"
}
function install_client {
check_support
install_basic_deps ${tsuru_package_source-"stable"}
set_local_host
set_host
install_tsuru_client
config_tsuru_post
enable_initial_user
add_default_roles
if [[ ${without_dashboard-} != "1" ]]; then
install_dashboard
fi
echo '######################## DONE! ########################'
echo
banner_ansii
echo
echo "Some information about your tsuru installation:"
echo
echo "Admin user: ${adminuser}"
echo "Admin password: ${adminpassword} (PLEASE CHANGE RUNNING: tsuru change-password)"
echo "Target address: $host_ip:8080"
if [[ ${without_dashboard-} != "1" ]]; then
local cont_id=$(docker ps | grep tsuru-dashboard | cut -d ' ' -f 1)
local dashboard_port=$(docker inspect $cont_id | grep HostPort | head -n1 | sed "s/[^0-9]//g")
echo "Dashboard address: $host_ip:$dashboard_port"
echo
echo "You should run \`source ~/.bashrc\` on your current terminal."
echo
echo "Installed apps:"
sleep 1
tsuru app-list
echo "Make sure that both ports 8080/tcp and 80/tcp are accessible remotely."
fi
}
function install_dockerfarm {
check_support
install_basic_deps ${tsuru_package_source-"stable"}
set_local_host
set_host
dockerhost=$(local_ip)
if [[ $dockerhost == "" ]]; then
dockerhost=$(public_ip)
fi
install_docker
install_tsuru_client
config_tsuru_post
enable_initial_user
add_default_roles
add_as_docker_node
}
function install_exportvars {
declare -p
}
function show_help {
PROGRAM_NAME=$(basename $0)
echo -e "Usage: $PROGRAM_NAME [options]
Options:
-n, --host-name [name] Set the VM's hostname
-i, --host-ip [name] Set the VM's IP
-pi, --private-ip [name] Set the VM's private IP
-c, --tsuru-from-source Install tsuru from master source code (default: stable packages)
-p, --tsuru-pkg-stable Install tsuru from stable packages
-N, --tsuru-pkg-nightly Install tsuru from nightly build packages (default: stable packages)
-f, --force-install [pkg] Force installation of named package
-g, --gopath [path] prepend new path to env var GOPATH
-u, --hook-url [url] Git hook URL
-o, --hook-name [name] Git hook name
-e, --env [key] [value] Set environment variable for git user in the VM
-r, --ext-repository [repo] Set the external repository URL produced by tsuru/tsuru-deb
-d, --docker-only Only install docker (default: docker, dashboard)
-w, --without-dashboard Install without dashboard (default: with dashboard)
-I, --set-interface The IP provided by --host-ip is not really allocated to this VM,
use ifconfig to set up an interface so it can be reached
-D, --docker-node [node1] [node2] ...
Add extra docker nodes to tsuru server for building clusters
-t, --template [name] Install template, name options:
- all: install all packages (default)
- dockerfarm: install docker only
- server: install mongo, planb, gandalf, archiver, tsuru-server
and their dependencies
- client: install tsuru-client and their dependencies
-v, --verbose Print debug messages
-P, --docker-pool [name] Add docker to destination pool of tsuru (default: theonepool)
-R, --registryhost Set the docker registry IP
-sd, --systemd Set systemd as init system
-h, --help This help screen
"
}
while [ "${1-}" != "" ]; do
case $1 in
"-v" | "--verbose")
set -x
is_debug=1
;;
"-P" | "--docker-pool")
shift
pool=$1
;;
"-I" | "--set-interface")
set_interface="y"
;;
"-D" | "--docker-node")
while [ "${2-}" != "" ]; do
shift
[[ ${1:0:1} != "-" ]] || break
docker_node="$docker_node $1"
done
;;
"-t" | "--template")
shift
install_func=install_$1
;;
"-n" | "--host-name")
shift
host_name=$1
;;
"-i" | "--host-ip")
shift
host_ip=$1
;;
"-pi" | "--private-ip")
shift
private_ip=$1
;;
"-c" | "--tsuru-from-source")
install_tsuru_source=1
;;
"-p" | "--tsuru-pkg-stable")
tsuru_package_source="stable"
install_tsuru_pkg=1
;;
"-f" | "--force-install")
shift
declare "force_install_$1=1"
;;
"-g" | "--gopath")
shift
mkdir -p $1
if [[ -v GOPATH ]]; then
export GOPATH=$1:$GOPATH
else
export GOPATH=$1
fi
;;
"-u" | "--hook-url")
shift
hook_url=$1
;;
"-o" | "--hook-name")
shift
hook_name=$1
;;
"-e" | "--env")
shift
git_envs=("${git_envs[@]}" "$1=\"$2\"")
shift
;;
"-r" | "--ext-repository")
shift
ext_repository=$1
;;
"-d" | "--docker-only")
install_func=install_docker
;;
"-w" | "--without-dashboard")
without_dashboard=1
;;
"-R" | "--registryhost")
shift
registryhost=$1
;;
* | "-h" | "--help")
show_help
exit
;;
esac
shift
done
$install_func