Adds a basic Linux Vagrant setup, stolen from Nomad.
This commit is contained in:
parent
533ec86a40
commit
35a27ac7ef
|
@ -0,0 +1,66 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
#
|
||||
|
||||
LINUX_BASE_BOX = "bento/ubuntu-16.04"
|
||||
|
||||
Vagrant.configure(2) do |config|
|
||||
config.vm.define "linux", autostart: true, primary: true do |vmCfg|
|
||||
vmCfg.vm.box = LINUX_BASE_BOX
|
||||
vmCfg.vm.hostname = "linux"
|
||||
vmCfg = configureProviders vmCfg,
|
||||
cpus: suggestedCPUCores()
|
||||
|
||||
vmCfg = configureLinuxProvisioners(vmCfg)
|
||||
|
||||
vmCfg.vm.synced_folder '.',
|
||||
'/opt/gopath/src/github.com/hashicorp/consul'
|
||||
|
||||
vmCfg.vm.network "forwarded_port", guest: 8500, host: 8500, auto_correct: true
|
||||
end
|
||||
end
|
||||
|
||||
def configureLinuxProvisioners(vmCfg)
|
||||
vmCfg.vm.provision "shell",
|
||||
privileged: true,
|
||||
inline: 'rm -f /home/vagrant/linux.iso'
|
||||
|
||||
vmCfg.vm.provision "shell",
|
||||
privileged: true,
|
||||
path: './scripts/vagrant-linux-priv-go.sh'
|
||||
|
||||
return vmCfg
|
||||
end
|
||||
|
||||
def configureProviders(vmCfg, cpus: "2", memory: "2048")
|
||||
vmCfg.vm.provider "virtualbox" do |v|
|
||||
v.memory = memory
|
||||
v.cpus = cpus
|
||||
end
|
||||
|
||||
["vmware_fusion", "vmware_workstation"].each do |p|
|
||||
vmCfg.vm.provider p do |v|
|
||||
v.enable_vmrun_ip_lookup = false
|
||||
v.vmx["memsize"] = memory
|
||||
v.vmx["numvcpus"] = cpus
|
||||
end
|
||||
end
|
||||
|
||||
vmCfg.vm.provider "virtualbox" do |v|
|
||||
v.memory = memory
|
||||
v.cpus = cpus
|
||||
end
|
||||
|
||||
return vmCfg
|
||||
end
|
||||
|
||||
def suggestedCPUCores()
|
||||
case RbConfig::CONFIG['host_os']
|
||||
when /darwin/
|
||||
Integer(`sysctl -n hw.ncpu`) / 2
|
||||
when /linux/
|
||||
Integer(`cat /proc/cpuinfo | grep processor | wc -l`) / 2
|
||||
else
|
||||
2
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function install_go() {
|
||||
local go_version=1.9.1
|
||||
local download=
|
||||
|
||||
download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz"
|
||||
|
||||
if [ -d /usr/local/go ] ; then
|
||||
return
|
||||
fi
|
||||
|
||||
wget -q -O /tmp/go.tar.gz ${download}
|
||||
|
||||
tar -C /tmp -xf /tmp/go.tar.gz
|
||||
sudo mv /tmp/go /usr/local
|
||||
sudo chown -R root:root /usr/local/go
|
||||
}
|
||||
|
||||
install_go
|
||||
|
||||
# Ensure that the GOPATH tree is owned by vagrant:vagrant
|
||||
mkdir -p /opt/gopath
|
||||
chown -R vagrant:vagrant /opt/gopath
|
||||
|
||||
# Ensure Go is on PATH
|
||||
if [ ! -e /usr/bin/go ] ; then
|
||||
ln -s /usr/local/go/bin/go /usr/bin/go
|
||||
fi
|
||||
if [ ! -e /usr/bin/gofmt ] ; then
|
||||
ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
|
||||
fi
|
||||
|
||||
|
||||
# Ensure new sessions know about GOPATH
|
||||
if [ ! -f /etc/profile.d/gopath.sh ] ; then
|
||||
cat <<EOT > /etc/profile.d/gopath.sh
|
||||
export GOPATH="/opt/gopath"
|
||||
export PATH="/opt/gopath/bin:\$PATH"
|
||||
EOT
|
||||
chmod 755 /etc/profile.d/gopath.sh
|
||||
fi
|
Loading…
Reference in New Issue