github.com/emate/nomad@v0.8.2-wo-binpacking/demo/vagrant/Vagrantfile (about)

     1  # -*- mode: ruby -*-
     2  # vi: set ft=ruby :
     3  
     4  $script = <<SCRIPT
     5  # Update apt and get dependencies
     6  sudo apt-get update
     7  sudo DEBIAN_FRONTEND=noninteractive apt-get install -y unzip curl vim \
     8      apt-transport-https \
     9      ca-certificates \
    10      software-properties-common
    11  
    12  # Download Nomad
    13  NOMAD_VERSION=0.8.1
    14  
    15  echo "Fetching Nomad..."
    16  cd /tmp/
    17  curl -sSL https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o nomad.zip
    18  
    19  echo "Fetching Consul..."
    20  CONSUL_VERSION=1.0.7
    21  curl -sSL https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip > consul.zip
    22  
    23  echo "Installing Nomad..."
    24  unzip nomad.zip
    25  sudo install nomad /usr/bin/nomad
    26  
    27  sudo mkdir -p /etc/nomad.d
    28  sudo chmod a+w /etc/nomad.d
    29  
    30  # Set hostname's IP to made advertisement Just Work
    31  #sudo sed -i -e "s/.*nomad.*/$(ip route get 1 | awk '{print $NF;exit}') nomad/" /etc/hosts
    32  
    33  echo "Installing Docker..."
    34  if [[ -f /etc/apt/sources.list.d/docker.list ]]; then
    35      echo "Docker repository already installed; Skipping"
    36  else
    37      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    38      sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    39      sudo apt-get update
    40  fi
    41  sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce
    42  
    43  # Restart docker to make sure we get the latest version of the daemon if there is an upgrade
    44  sudo service docker restart
    45  
    46  # Make sure we can actually use docker as the vagrant user
    47  sudo usermod -aG docker vagrant
    48  
    49  echo "Installing Consul..."
    50  unzip /tmp/consul.zip
    51  sudo install consul /usr/bin/consul
    52  (
    53  cat <<-EOF
    54  	[Unit]
    55  	Description=consul agent
    56  	Requires=network-online.target
    57  	After=network-online.target
    58  	
    59  	[Service]
    60  	Restart=on-failure
    61  	ExecStart=/usr/bin/consul agent -dev
    62  	ExecReload=/bin/kill -HUP $MAINPID
    63  	
    64  	[Install]
    65  	WantedBy=multi-user.target
    66  EOF
    67  ) | sudo tee /etc/systemd/system/consul.service
    68  sudo systemctl enable consul.service
    69  sudo systemctl start consul
    70  
    71  for bin in cfssl cfssl-certinfo cfssljson
    72  do
    73  	echo "Installing $bin..."
    74  	curl -sSL https://pkg.cfssl.org/R1.2/${bin}_linux-amd64 > /tmp/${bin}
    75  	sudo install /tmp/${bin} /usr/local/bin/${bin}
    76  done
    77  
    78  echo "Installing autocomplete..."
    79  nomad -autocomplete-install
    80  
    81  SCRIPT
    82  
    83  Vagrant.configure(2) do |config|
    84    config.vm.box = "bento/ubuntu-16.04" # 16.04 LTS
    85    config.vm.hostname = "nomad"
    86    config.vm.provision "shell", inline: $script, privileged: false
    87    config.vm.provision "docker" # Just install it
    88    
    89    # Expose the nomad api and ui to the host
    90    config.vm.network "forwarded_port", guest: 4646, host: 4646, auto_correct: true
    91  
    92    # Increase memory for Parallels Desktop
    93    config.vm.provider "parallels" do |p, o|
    94      p.memory = "1024"
    95    end
    96  
    97    # Increase memory for Virtualbox
    98    config.vm.provider "virtualbox" do |vb|
    99          vb.memory = "1024"
   100    end
   101  
   102    # Increase memory for VMware
   103    ["vmware_fusion", "vmware_workstation"].each do |p|
   104      config.vm.provider p do |v|
   105        v.vmx["memsize"] = "1024"
   106      end
   107    end
   108  end