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