github.com/taylorchu/nomad@v0.5.3-rc1.0.20170407200202-db11e7dd7b55/Vagrantfile (about)

     1  # -*- mode: ruby -*-
     2  # vi: set ft=ruby :
     3  
     4  # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
     5  VAGRANTFILE_API_VERSION = "2"
     6  
     7  DEFAULT_CPU_COUNT = 2
     8  $script = <<SCRIPT
     9  GO_VERSION="1.8"
    10  
    11  export DEBIAN_FRONTEND=noninteractive
    12  
    13  sudo dpkg --add-architecture i386
    14  sudo apt-get update
    15  
    16  # Install base dependencies
    17  sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential curl git-core mercurial bzr \
    18       libpcre3-dev pkg-config zip default-jre qemu silversearcher-ag \
    19       jq htop vim unzip tree                             \
    20       liblxc1 lxc-dev lxc-templates                      \
    21       gcc-5-aarch64-linux-gnu binutils-aarch64-linux-gnu \
    22       libc6-dev-i386 linux-libc-dev:i386                 \
    23       gcc-5-arm-linux-gnueabihf gcc-5-multilib-arm-linux-gnueabihf binutils-arm-linux-gnueabihf
    24  
    25  # Setup go, for development of Nomad
    26  SRCROOT="/opt/go"
    27  SRCPATH="/opt/gopath"
    28  
    29  # Get the ARCH
    30  ARCH=`uname -m | sed 's|i686|386|' | sed 's|x86_64|amd64|'`
    31  
    32  # Install Go
    33  if [[ $(go version) == "go version go${GO_VERSION} linux/${ARCH}" ]]; then
    34      echo "Go ${GO_VERSION} ${ARCH} already installed; Skipping"
    35  else
    36      cd /tmp
    37      wget -q https://storage.googleapis.com/golang/go${GO_VERSION}.linux-${ARCH}.tar.gz
    38      tar -xf go${GO_VERSION}.linux-${ARCH}.tar.gz
    39      sudo rm -rf $SRCROOT/go
    40      sudo mv go $SRCROOT
    41      sudo chmod 775 $SRCROOT
    42      sudo chown vagrant:vagrant $SRCROOT
    43  fi
    44  
    45  # Setup the GOPATH; even though the shared folder spec gives the working
    46  # directory the right user/group, we need to set it properly on the
    47  # parent path to allow subsequent "go get" commands to work.
    48  sudo mkdir -p $SRCPATH
    49  sudo chown -R vagrant:vagrant $SRCPATH 2>/dev/null || true
    50  # ^^ silencing errors here because we expect this to fail for the shared folder
    51  
    52  cat <<EOF >/tmp/gopath.sh
    53  export GOPATH="$SRCPATH"
    54  export GOROOT="$SRCROOT"
    55  export PATH="$SRCROOT/bin:$SRCPATH/bin:\$PATH"
    56  EOF
    57  sudo mv /tmp/gopath.sh /etc/profile.d/gopath.sh
    58  sudo chmod 0755 /etc/profile.d/gopath.sh
    59  source /etc/profile.d/gopath.sh
    60  
    61  # Install Docker
    62  if [[ -f /etc/apt/sources.list.d/docker.list ]]; then
    63      echo "Docker repository already installed; Skipping"
    64  else
    65      echo deb https://apt.dockerproject.org/repo ubuntu-`lsb_release -c | awk '{print $2}'` main | sudo tee /etc/apt/sources.list.d/docker.list
    66      sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    67      sudo apt-get update
    68  fi
    69  sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker-engine
    70  
    71  # Restart docker to make sure we get the latest version of the daemon if there is an upgrade
    72  sudo service docker restart
    73  
    74  # Make sure we can actually use docker as the vagrant user
    75  sudo usermod -aG docker vagrant
    76  
    77  # Setup Nomad for development
    78  cd /opt/gopath/src/github.com/hashicorp/nomad && make bootstrap
    79  
    80  # Install rkt, consul and vault
    81  bash scripts/install_rkt.sh
    82  bash scripts/install_rkt_vagrant.sh
    83  bash scripts/install_consul.sh
    84  bash scripts/install_vault.sh
    85  
    86  # Set hostname's IP to made advertisement Just Work
    87  sudo sed -i -e "s/.*nomad.*/$(ip route get 1 | awk '{print $NF;exit}') $(hostname)/" /etc/hosts
    88  
    89  # CD into the nomad working directory when we login to the VM
    90  grep "cd /opt/gopath/src/github.com/hashicorp/nomad" ~/.profile || echo "cd /opt/gopath/src/github.com/hashicorp/nomad" >> ~/.profile
    91  SCRIPT
    92  
    93  def configureVM(vmCfg, vmParams={
    94                    numCPUs: DEFAULT_CPU_COUNT,
    95                  }
    96                 )
    97    # When updating make sure to use a box that supports VMWare and VirtualBox
    98    vmCfg.vm.box = "bento/ubuntu-16.04" # 16.04 LTS
    99  
   100    vmCfg.vm.provision "shell", inline: $script, privileged: false
   101    vmCfg.vm.synced_folder '.', '/opt/gopath/src/github.com/hashicorp/nomad'
   102  
   103    # We're going to compile go and run a concurrent system, so give ourselves
   104    # some extra resources. Nomad will have trouble working correctly with <2
   105    # CPUs so we should use at least that many.
   106    cpus = vmParams.fetch(:numCPUs, DEFAULT_CPU_COUNT)
   107    memory = 2048
   108  
   109    vmCfg.vm.provider "parallels" do |p, o|
   110      p.memory = memory
   111      p.cpus = cpus
   112    end
   113  
   114    vmCfg.vm.provider "virtualbox" do |v|
   115      v.memory = memory
   116      v.cpus = cpus
   117    end
   118  
   119    ["vmware_fusion", "vmware_workstation"].each do |p|
   120      vmCfg.vm.provider p do |v|
   121        v.enable_vmrun_ip_lookup = false
   122        v.gui = false
   123        v.memory = memory
   124        v.cpus = cpus
   125      end
   126    end
   127    return vmCfg
   128  end
   129  
   130  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   131    1.upto(3) do |n|
   132      vmName = "nomad-server%02d" % [n]
   133      isFirstBox = (n == 1)
   134  
   135      numCPUs = DEFAULT_CPU_COUNT
   136      if isFirstBox and Object::RUBY_PLATFORM =~ /darwin/i
   137        # Override the max CPUs for the first VM
   138        numCPUs = [numCPUs, (`/usr/sbin/sysctl -n hw.ncpu`.to_i - 1)].max
   139      end
   140  
   141      config.vm.define vmName, autostart: isFirstBox, primary: isFirstBox do |vmCfg|
   142        vmCfg.vm.hostname = vmName
   143        vmCfg = configureVM(vmCfg, {:numCPUs => numCPUs})
   144      end
   145    end
   146  
   147    1.upto(3) do |n|
   148      vmName = "nomad-client%02d" % [n]
   149      config.vm.define vmName, autostart: false, primary: false do |vmCfg|
   150        vmCfg.vm.hostname = vmName
   151        vmCfg = configureVM(vmCfg)
   152      end
   153    end
   154  end