github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/libnetwork/machines (about)

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