Add Vagrant build environment (elastic/elasticsearch#38)

This adds a vagrant configuration under /vagrant. This allows the user to provision a virtual machine with the entire build environment needed for compiling the C++ portion of the code (as well as the Java side, but that can be done easily outside of vagrant).

Original commit: elastic/x-pack-elasticsearch@12754bd80e
This commit is contained in:
Zachary Tong 2016-10-05 10:00:13 -04:00 committed by GitHub
parent 2af02b04e1
commit 19868a97bf
3 changed files with 113 additions and 0 deletions

1
vagrant/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vagrant

83
vagrant/README.md Normal file
View File

@ -0,0 +1,83 @@
## Vagrant build environment
This provides a vagrant box for building the C++ side of Prelert (and the Java side,
although that is easily accomplished outside vagrant).
Provisioning the box will take a fair amount of time, since it needs to download
and compile a number of dependencies.
A pre-provisioned box can be downloaded from: TODO
### Details
- Ubuntu Trusty64 (14.04.5 LTS)
- 25% of host's memory
- 100% host's cores
- Maps prelert source repository to `/home/vagrant/prelert/src`
- Directory is shared with the host, so you can point your IDE to the prelert repo
and build inside vagrant
- Maps prelert build directory to `/home/vagrant/prelert/build`
- Changes into `/home/vagrant/prelert/src` on login
### Usage
```bash
$ cd prelert-legacy
$ cd vagrant
$ vagrant up
# ...
# wait while vagrant provisions
# ...
$ vagrant ssh
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-96-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Tue Oct 4 16:06:31 UTC 2016
System load: 0.0 Processes: 196
Usage of /: 12.0% of 39.34GB Users logged in: 0
Memory usage: 2% IP address for eth0: 10.0.2.15
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
New release '16.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Tue Oct 4 16:06:32 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty-64:~/prelert/src$
```
Once you've logged into the box, you'll be in the prelert source directory. You
can build immediately via:
```bash
vagrant@vagrant-ubuntu-trusty-64:~/prelert/src$ gradle cppmake
# ...
# much building
# ...
```
### Suspending your box
Once you've provisioned a box, you can use `vagrant suspend` to "sleep" the box.
This has the advantage of rebooting quickly when you `vagrant up`, and returns you
to exactly what you were doing. On the downside, it eats more disk space since it
needs to sleep the entire image.
You can alternatively use `vagrant halt`, which gracefully powers down the machine.
Rebooting via `vagrant up` takes longer since you are rebooting the entire OS,
but it saves more disk space.
### Fixing a broken box
If you accidentally kill the provisioning process before it completes, you can
attempt to reprovision it with `vagrant reload --provision`. That will run
the provisioners that did not complete previously.
If your box is still horribly broken, you can destroy it with `vagrant destroy`
and try again with `vagrant up`

29
vagrant/Vagrantfile vendored Normal file
View File

@ -0,0 +1,29 @@
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox" do |v|
host = RbConfig::CONFIG['host_os']
# Give VM 1/4 system memory
linux = RUBY_PLATFORM =~ /linux/
osx = RUBY_PLATFORM =~ /darwin/
windows = (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
if osx
cpus = `sysctl -n hw.ncpu`.to_i
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024
end
if linux
cpus = `nproc`.to_i
mem = `sed -n -e '/^MemTotal/s/^[^0-9]*//p' /proc/meminfo`.to_i / 1024
end
if windows
cpus = `wmic computersystem get numberofprocessors`.split("\n")[2].to_i
mem = `wmic OS get TotalVisibleMemorySize`.split("\n")[2].to_i / 1024
end
mem = mem / 4
v.customize ["modifyvm", :id, "--memory", mem]
v.customize ["modifyvm", :id, "--cpus", cpus]
end
config.vm.provision :shell, path: "provision.sh"
config.vm.synced_folder "../", "/home/vagrant/prelert/src", mount_options: ["dmode=777,fmode=777"]
end