forked from DigitalOnUs/robot-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-swarm.sh
executable file
·60 lines (50 loc) · 1.09 KB
/
create-swarm.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
#!/bin/sh
if [ -z "$1" ]
then
echo "Usage: create-machines.sh [local|aws]"
exit 1
fi
case $1 in
local)
DRIVER=virtualbox
;;
aws)
DRIVER=amazonec2
;;
*)
echo "Unknown option"
exit 1
esac
for MACHINE in master worker-1 worker-2
do
echo "Creating $MACHINE"
if [ "$DRIVER" = "aws" ]
then
docker-machine create \
--driver $DRIVER \
--amazonec2-instance-type "t2.medium" \
$MACHINE
else
docker-machine create \
--driver $DRIVER \
$MACHINE
fi
done
sleep 3
echo " "
echo "Machines created"
echo "Configuring Swarm"
MASTER_IP=$(docker-machine ip master)
# create the swarm master
# connect local docker command to master machine
echo "Creating master"
eval $(docker-machine env master)
JOIN_CMD=$(docker swarm init --advertise-addr "$MASTER_IP" | awk '/^[ \t]+/{print $0}' -)
for MACHINE in $(docker-machine ls -q | fgrep worker)
do
echo "joining from $MACHINE"
eval $(docker-machine env $MACHINE)
$JOIN_CMD
done
echo " "
echo "Swarm is ready"