Skip to content

Instantly share code, notes, and snippets.

@louisje
Forked from cpuguy83/swarminate.sh
Last active March 18, 2016 10:34
Show Gist options
  • Save louisje/8d07dc8c32299fd4a220 to your computer and use it in GitHub Desktop.
Save louisje/8d07dc8c32299fd4a220 to your computer and use it in GitHub Desktop.
#!/bin/sh
num=3
set -e
if test -n "$SWARM_NUM"; then
num="$SWARM_NUM"
fi
create() {
echo "Setting up k/v store"
docker-machine create -d virtualbox kvstore
sleep 10
docker $(docker-machine config kvstore) run -d -p 8500 --net=host progrium/consul -server -bootstrap-expect 1 -ui-dir /ui
# store the IP address of the kvstore machine
sleep 10
kvip=$(docker-machine ip kvstore)
echo "Creating cluster nodes ..."
swarm_master="--swarm-master"
for i in `seq 0 $num`; do
docker-machine create -d virtualbox \
--engine-insecure-registry "jks.zencircle.com:5000" \
--engine-opt "cluster-store consul://${kvip}:8500" \
--engine-opt "cluster-advertise eth1:2376" \
--swarm ${swarm_master} \
--swarm-discovery "consul://${kvip}:8500" \
"swarm-$i" &
swarm_master=""
done
wait
docker-machine env --swarm "swarm-0"
}
teardown() {
docker-machine rm -y kvstore &
for i in `seq 0 $num`; do
docker-machine rm -y "swarm-$i" &
done
wait
}
case $1 in
"up")
create
;;
"down")
teardown
;;
*)
echo "Usage: $0 < up | down >"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment