/
setup_google_cloud_engine.sh
72 lines (63 loc) · 1.97 KB
/
setup_google_cloud_engine.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
#!/bin/sh
#
# Shell Script that allows to automatically provision a Docker Swarm in Google Cloud Engine
#
# - up <NODES> | Provision a node running consul for service-discovery and a number of #<NODES>, where the first node will be the swarm master.
# - down <NODES> | Pauses instances until you have a specific number of #<NODES> in your swarm.
#
set -e
create() {
echo Setting up kv store
docker-machine create \
--driver google \
--google-project $2 \
bifrost-gce-swarm-kvstore && \
docker-machine ssh bifrost-gce-swarm-kvstore $(ps axf | grep dnsmasq | grep -v grep | awk '{print "kill -9 " $1}') && \
docker $(docker-machine config bifrost-gce-swarm-kvstore) run -d --restart=always --net=host progrium/consul --server -bootstrap-expect 1
# get INTERNAL_IP of kvstore instance
kvip=$(gcloud compute instances list bifrost-gce-swarm-kvstore | awk '{print $4}' | sed -n 2p)
# kvip=10.128.0.2
# kvip=$(docker-machine ip bifrost-gce-swarm-kvstore)
echo "KV-Store has been created with IP ${kvip}"
echo "Setting up Swarm-Master"
docker-machine create \
--engine-opt "cluster-store consul://${kvip}:8500" \
--engine-opt "cluster-advertise eth0:2376" \
--driver google \
--google-project $2 \
--swarm \
--swarm-master \
--swarm-discovery consul://${kvip}:8500 \
bifrost-gce-swarm-node-1 &
for ((i=2;i<=$1;i++)); do
echo "Setting up Swarm-Node #${i}"
docker-machine create \
--engine-opt "cluster-store consul://${kvip}:8500" \
--engine-opt "cluster-advertise eth0:2376" \
--driver google \
--google-project $2 \
--swarm \
--swarm-discovery consul://${kvip}:8500 \
bifrost-gce-swarm-node-$i &
done
wait
}
teardown() {
for ((i=$1+1;i>=2;i--)); do
echo "Stopping Swarm-Node #${i}"
docker-machine stop bifrost-gce-swarm-node-$i &
done
wait
}
case $1 in
up)
create $2 $3
;;
down)
teardown $2
;;
*)
echo "I literally can't even..."
exit 1
;;
esac