github.com/bigcommerce/nomad@v0.9.3-bc/terraform/shared/scripts/setup.sh (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  # Disable interactive apt prompts
     6  export DEBIAN_FRONTEND=noninteractive
     7  
     8  cd /ops
     9  
    10  CONFIGDIR=/ops/shared/config
    11  
    12  CONSULVERSION=1.4.3
    13  CONSULDOWNLOAD=https://releases.hashicorp.com/consul/${CONSULVERSION}/consul_${CONSULVERSION}_linux_amd64.zip
    14  CONSULCONFIGDIR=/etc/consul.d
    15  CONSULDIR=/opt/consul
    16  
    17  VAULTVERSION=1.0.3
    18  VAULTDOWNLOAD=https://releases.hashicorp.com/vault/${VAULTVERSION}/vault_${VAULTVERSION}_linux_amd64.zip
    19  VAULTCONFIGDIR=/etc/vault.d
    20  VAULTDIR=/opt/vault
    21  
    22  NOMADVERSION=0.9.0
    23  NOMADDOWNLOAD=https://releases.hashicorp.com/nomad/${NOMADVERSION}/nomad_${NOMADVERSION}_linux_amd64.zip
    24  NOMADCONFIGDIR=/etc/nomad.d
    25  NOMADDIR=/opt/nomad
    26  
    27  CONSULTEMPLATEVERSION=0.20.0
    28  CONSULTEMPLATEDOWNLOAD=https://releases.hashicorp.com/consul-template/${CONSULTEMPLATEVERSION}/consul-template_${CONSULTEMPLATEVERSION}_linux_amd64.zip
    29  CONSULTEMPLATECONFIGDIR=/etc/consul-template.d
    30  CONSULTEMPLATEDIR=/opt/consul-template
    31  
    32  HADOOP_VERSION=2.7.6
    33  
    34  # Dependencies
    35  sudo apt-get install -y software-properties-common
    36  sudo apt-get update
    37  sudo apt-get install -y unzip tree redis-tools jq curl tmux
    38  
    39  # Numpy (for Spark)
    40  sudo apt-get install -y python-setuptools
    41  sudo easy_install pip
    42  sudo pip install numpy
    43  
    44  # Disable the firewall
    45  
    46  sudo ufw disable || echo "ufw not installed"
    47  
    48  # Consul
    49  
    50  curl -L $CONSULDOWNLOAD > consul.zip
    51  
    52  ## Install
    53  sudo unzip consul.zip -d /usr/local/bin
    54  sudo chmod 0755 /usr/local/bin/consul
    55  sudo chown root:root /usr/local/bin/consul
    56  
    57  ## Configure
    58  sudo mkdir -p $CONSULCONFIGDIR
    59  sudo chmod 755 $CONSULCONFIGDIR
    60  sudo mkdir -p $CONSULDIR
    61  sudo chmod 755 $CONSULDIR
    62  
    63  # Vault
    64  
    65  curl -L $VAULTDOWNLOAD > vault.zip
    66  
    67  ## Install
    68  sudo unzip vault.zip -d /usr/local/bin
    69  sudo chmod 0755 /usr/local/bin/vault
    70  sudo chown root:root /usr/local/bin/vault
    71  
    72  ## Configure
    73  sudo mkdir -p $VAULTCONFIGDIR
    74  sudo chmod 755 $VAULTCONFIGDIR
    75  sudo mkdir -p $VAULTDIR
    76  sudo chmod 755 $VAULTDIR
    77  
    78  # Nomad
    79  
    80  curl -L $NOMADDOWNLOAD > nomad.zip
    81  
    82  ## Install
    83  sudo unzip nomad.zip -d /usr/local/bin
    84  sudo chmod 0755 /usr/local/bin/nomad
    85  sudo chown root:root /usr/local/bin/nomad
    86  
    87  ## Configure
    88  sudo mkdir -p $NOMADCONFIGDIR
    89  sudo chmod 755 $NOMADCONFIGDIR
    90  sudo mkdir -p $NOMADDIR
    91  sudo chmod 755 $NOMADDIR
    92  
    93  # Consul Template 
    94  
    95  curl -L $CONSULTEMPLATEDOWNLOAD > consul-template.zip
    96  
    97  ## Install
    98  sudo unzip consul-template.zip -d /usr/local/bin
    99  sudo chmod 0755 /usr/local/bin/consul-template
   100  sudo chown root:root /usr/local/bin/consul-template
   101  
   102  ## Configure
   103  sudo mkdir -p $CONSULTEMPLATECONFIGDIR
   104  sudo chmod 755 $CONSULTEMPLATECONFIGDIR
   105  sudo mkdir -p $CONSULTEMPLATEDIR
   106  sudo chmod 755 $CONSULTEMPLATEDIR
   107  
   108  # Docker
   109  distro=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
   110  sudo apt-get install -y apt-transport-https ca-certificates gnupg2 
   111  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
   112  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/${distro} $(lsb_release -cs) stable"
   113  sudo apt-get update
   114  sudo apt-get install -y docker-ce
   115  
   116  if [[ ! -z ${INSTALL_NVIDIA_DOCKER+x} ]]; then 
   117    # Install official NVIDIA driver package
   118    sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
   119    sudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
   120    sudo apt-get update && sudo apt-get install -y --no-install-recommends linux-headers-generic dkms cuda-drivers
   121  
   122    # Install nvidia-docker and nvidia-docker-plugin
   123    # from: https://github.com/NVIDIA/nvidia-docker#ubuntu-140416041804-debian-jessiestretch
   124    wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb
   125    sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb
   126    curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
   127    distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
   128    curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
   129      sudo tee /etc/apt/sources.list.d/nvidia-docker.list
   130  
   131    sudo apt-get update
   132    sudo apt-get install -y nvidia-docker2
   133  fi
   134  
   135  # rkt
   136  VERSION=1.29.0
   137  DOWNLOAD=https://github.com/rkt/rkt/releases/download/v${VERSION}/rkt-v${VERSION}.tar.gz
   138  
   139  function install_rkt() {
   140  	wget -q -O /tmp/rkt.tar.gz "${DOWNLOAD}"
   141  	tar -C /tmp -xvf /tmp/rkt.tar.gz
   142  	sudo mv /tmp/rkt-v${VERSION}/rkt /usr/local/bin
   143  	sudo mv /tmp/rkt-v${VERSION}/*.aci /usr/local/bin
   144  }
   145  
   146  function configure_rkt_networking() {
   147  	sudo mkdir -p /etc/rkt/net.d
   148      sudo bash -c 'cat << EOT > /etc/rkt/net.d/99-network.conf
   149  {
   150    "name": "default",
   151    "type": "ptp",
   152    "ipMasq": false,
   153    "ipam": {
   154      "type": "host-local",
   155      "subnet": "172.16.28.0/24",
   156      "routes": [
   157        {
   158          "dst": "0.0.0.0/0"
   159        }
   160      ]
   161    }
   162  }
   163  EOT'
   164  }
   165  
   166  install_rkt
   167  configure_rkt_networking
   168  
   169  # Java
   170  sudo add-apt-repository -y ppa:openjdk-r/ppa
   171  sudo apt-get update 
   172  sudo apt-get install -y openjdk-8-jdk
   173  JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
   174  
   175  # Spark
   176  sudo wget -P /ops/examples/spark https://nomad-spark.s3.amazonaws.com/spark-2.2.0-bin-nomad-0.7.0.tgz
   177  sudo tar -xf /ops/examples/spark/spark-2.2.0-bin-nomad-0.7.0.tgz --directory /ops/examples/spark
   178  sudo mv /ops/examples/spark/spark-2.2.0-bin-nomad-0.7.0 /usr/local/bin/spark
   179  sudo chown -R root:root /usr/local/bin/spark
   180  
   181  # Hadoop (to enable the HDFS CLI)
   182  wget -O - http://apache.mirror.iphh.net/hadoop/common/hadoop-${HADOOP_VERSION}/hadoop-${HADOOP_VERSION}.tar.gz | sudo tar xz -C /usr/local/