Aurelien Larcher
2020-06-05 2998688b7742083e0ab4367dfc3d29dcc1c0c61f
commit | author | age
66650d 1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3 #
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"). You may
6 # only use this file in accordance with the terms of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2016 Adam Stevko. All rights reserved.
75c553 15 # Copyright 2017 Michal Nowak
66650d 16 #
17
18 Vagrant.configure("2") do |config|
19   # Every Vagrant development environment requires a box. You can search for
20   # boxes at https://atlas.hashicorp.com/search.
21   config.vm.box = "openindiana/hipster"
22
23   # Disable automatic box update checking. If you disable this, then
24   # boxes will only be checked for updates when the user runs
25   # `vagrant box outdated`. This is not recommended.
26   config.vm.box_check_update = true
27
28   # Unless OpenIndiana is better supported in vagrant, we have to use this
75c553 29   # workaround. The problem with vagrant is that it creates folder as root:root,
MN 30   # but rsync connects as vagrant and thus fails to write.
66650d 31   config.vm.synced_folder ".", "/vagrant", type: "rsync",
75c553 32     rsync__args: ["--verbose", "--archive", "--compress", "--copy-links"],
66650d 33     rsync__rsync_path: "pfexec rsync", owner: "vagrant", group: "vagrant"
34
35   # Autoconfigure resources for development VM. The snippet is taken from
36   # https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck.
37   # We allocate 1/4 of available system memory and CPU core count of the host
38   # to the VM, so performance does not suck.
39   config.vm.provider "virtualbox" do |v|
40     host = RbConfig::CONFIG['host_os']
41
75c553 42     # Get memory size and CPU cores amount
66650d 43     if host =~ /darwin/
75c553 44       # sysctl returns Bytes
MN 45       mem = `sysctl -n hw.memsize`.to_i
46       cpus = `sysctl -n hw.ncpu`.to_i
66650d 47     elsif host =~ /linux/
75c553 48       # meminfo shows size in kB; convert to Bytes
MN 49       mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.to_i * 1024
50       cpus = `getconf _NPROCESSORS_ONLN`.to_i
66650d 51     elsif host =~ /mswin|mingw|cygwin/
52       # Windows code via https://github.com/rdsubhas/vagrant-faster
75c553 53       mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i
MN 54       cpus = `echo %NUMBER_OF_PROCESSORS%`.to_i
66650d 55     end
56
75c553 57     # Give VM 1/4 system memory as well as CPU core count
MN 58     mem /= 1024 ** 2 * 4
59     cpus /= 4
66650d 60
61     v.customize ["modifyvm", :id, "--memory", mem]
62     v.customize ["modifyvm", :id, "--cpus", cpus]
f6ec4f 63     v.customize ["storagectl", :id, "--name", "SATA Controller", "--hostiocache", "on"]
MN 64     # Enable following line, if oi-userland directory is on non-rotational
65     # drive (e.g. SSD). (This could be automated, but with all those storage
66     # technologies (LVM, partitions, ...) on all three operationg systems,
67     # it's actually error prone to detect it automatically.) macOS has it
68     # enabled by default as recent Macs have SSD anyway.
69     if host =~ /darwin/
70       v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
71     else
72       #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
73     end
74     # Should we ever support `--discard` option, we need to switch to VDI
75     # virtual disk format first.
76     #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--discard", "on"]
66650d 77   end
78
79   # Once vagrant is able to chown files on OpenIndiana, chown line should be
80   # removed from this part.
81   config.vm.provision "shell", inline: <<-SHELL
82     pfexec chown -R vagrant:vagrant /vagrant
83     pfexec pkg install build-essential
84
85     cd /vagrant && gmake setup
75c553 86     echo "VM is ready, happy contributing!"
66650d 87   SHELL
88 end