github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/contrib/digitalocean/provision-do-cluster.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Usage: ./provision-do-cluster.sh <REGION_ID> <SSH_ID> <SIZE>
     4  #
     5  
     6  set -e
     7  
     8  listcontains() {
     9    for i in $1; do
    10      [[ $i = $2 ]] && return 0
    11    done
    12    return 1
    13  }
    14  
    15  THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
    16  CONTRIB_DIR=$(dirname $THIS_DIR)
    17  
    18  REGION_SLUG=$1
    19  SSH_ID=$2
    20  SIZE=$3
    21  PREFIX=$4
    22  
    23  if [ -z "$PREFIX" ]; then
    24    PREFIX="deis"
    25  fi
    26  
    27  source $CONTRIB_DIR/utils.sh
    28  
    29  if [ -z "$3" ]; then
    30    echo_red 'Usage: provision-do-cluster.sh <REGION_SLUG> <SSH_ID> <SIZE> [PREFIX]'
    31    exit 1
    32  fi
    33  
    34  # check for DO tools in $PATH
    35  if ! which docl > /dev/null; then
    36    echo_red 'Please install the docl gem and ensure it is in your $PATH.'
    37    exit 1
    38  fi
    39  
    40  if [ -z "$DEIS_NUM_INSTANCES" ]; then
    41      DEIS_NUM_INSTANCES=3
    42  fi
    43  
    44  regions_without_private_networking_or_metadata="nyc1 nyc2 ams1"
    45  if listcontains "$regions_without_private_networking_or_metadata" "$REGION_SLUG";
    46  then
    47      echo_red "Invalid region. Please supply a region with private networking & metadata support."
    48      echo_red "Valid regions are (use the name in brackets):"
    49      docl regions --private_networking --metadata
    50      exit 1
    51  fi
    52  
    53  # check that the CoreOS user-data file is valid
    54  $CONTRIB_DIR/util/check-user-data.sh
    55  
    56  # TODO: Make it follow a specific ID once circumstances allow us to do so.
    57  BASE_IMAGE_ID='coreos-stable'
    58  
    59  if [ -z "$BASE_IMAGE_ID" ]; then
    60  	echo_red "DigitalOcean Image not found..."
    61  	exit 1
    62  fi
    63  
    64  # launch the Deis cluster on DigitalOcean
    65  i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \
    66      NAME="$PREFIX-$i"
    67      echo_yellow "Provisioning ${NAME}..."
    68      docl create $NAME $BASE_IMAGE_ID $SIZE $REGION_SLUG --key=$SSH_ID --private-networking --user-data=$CONTRIB_DIR/coreos/user-data --wait
    69      ((i = i + 1)) ; \
    70  done
    71  
    72  echo_green "Your Deis cluster has successfully deployed to DigitalOcean."
    73  echo_green "Please continue to follow the instructions in the README."