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