machines 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #/bin/sh
  2. set -e
  3. usage()
  4. {
  5. cat << EOF
  6. NAME:
  7. machines - Create Test Environments for Docker Networking
  8. VERSION:
  9. 0.1
  10. USAGE:
  11. $0 <command> [command_options] [arguments...]
  12. COMMANDS:
  13. help
  14. Help and usage
  15. up <kv-store> <scale>
  16. Create environment with given KV store
  17. zookeeper | etcd | consul (default)
  18. Create N nodes, default = 2
  19. destroy
  20. Destroy Environment
  21. EOF
  22. }
  23. step() {
  24. printf "\033[0;36m-----> $@\033[0m\n"
  25. }
  26. up()
  27. {
  28. step "Creating KV Store Machine"
  29. docker-machine create \
  30. -d virtualbox \
  31. mh-kv
  32. step "KV Store is $1"
  33. step "Starting KV Container"
  34. case "$1" in
  35. etcd)
  36. cluster_store="cluster-store=etcd://$(docker-machine ip mh-kv):2379"
  37. docker $(docker-machine config mh-kv) run -d \
  38. -p "2379:2379" \
  39. -h "etcd" \
  40. --name "etcd" \
  41. quay.io/coreos/etcd:v2.2.1 \
  42. --listen-client-urls="http://0.0.0.0:2379" \
  43. --advertise-client-urls="http://$(docker-machine ip mh-kv):2379"
  44. ;;
  45. zookeeper)
  46. cluster_store="cluster-store=zk://$(docker-machine ip mh-kv):2181"
  47. docker $(docker-machine config mh-kv) run -d \
  48. -p "2181:2181" \
  49. -h "zookeeper" \
  50. --name "zookeeper" \
  51. tianon/zookeeper
  52. ;;
  53. *)
  54. cluster_store="cluster-store=consul://$(docker-machine ip mh-kv):8500"
  55. docker $(docker-machine config mh-kv) run -d \
  56. -p "8500:8500" \
  57. -h "consul" \
  58. --name "consul" \
  59. progrium/consul -server -bootstrap-expect 1
  60. ;;
  61. esac
  62. machines=$2
  63. if [ -z machines ]; then
  64. machines=2
  65. fi
  66. step "Creating $machines Machines"
  67. for i in $(seq $machines); do
  68. step "Creating machine $i"
  69. docker-machine create \
  70. -d virtualbox \
  71. --engine-opt="cluster-advertise=eth1:2376" \
  72. --engine-opt="$cluster_store" \
  73. mh-$i
  74. done
  75. }
  76. destroy()
  77. {
  78. for x in $(docker-machine ls | grep mh- | awk '{ print $1 }'); do
  79. docker-machine rm $x
  80. done
  81. }
  82. case "$1" in
  83. up)
  84. shift
  85. up $@
  86. ;;
  87. destroy)
  88. destroy $@
  89. ;;
  90. help)
  91. usage
  92. ;;
  93. *)
  94. usage
  95. ;;
  96. esac