Andreas Wacknitz
2021-02-06 219b1e8367ce2d1431b2f7073e782312defde143
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|
9a6576 19     # Every Vagrant development environment requires a box. You can search for
TW 20     # boxes at https://atlas.hashicorp.com/search.
21     config.vm.box = "openindiana/hipster"
66650d 22
9a6576 23     # Disable automatic box update checking. If you disable this, then
TW 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
66650d 27
9a6576 28     # Unless OpenIndiana is better supported in vagrant, we have to use this
TW 29     # workaround. The problem with vagrant is that it creates folder as root:root,
30     # but rsync connects as vagrant and thus fails to write.
31     config.vm.synced_folder ".", "/vagrant", type: "rsync",
32       rsync__args: ["--verbose", "--archive", "-zz", "--copy-links"],
33       rsync__rsync_path: "pfexec rsync", owner: "vagrant", group: "vagrant"
66650d 34
9a6576 35     # Autoconfigure resources for development VM. The snippet is taken from
TW 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.
66650d 39     host = RbConfig::CONFIG['host_os']
40
75c553 41     # Get memory size and CPU cores amount
66650d 42     if host =~ /darwin/
9a6576 43         # sysctl returns Bytes
TW 44         mem = `sysctl -n hw.memsize`.to_i
45         cpus = `sysctl -n hw.ncpu`.to_i
66650d 46     elsif host =~ /linux/
9a6576 47         # meminfo shows size in kB; convert to Bytes
TW 48         mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.to_i * 1024
49         cpus = `getconf _NPROCESSORS_ONLN`.to_i
66650d 50     elsif host =~ /mswin|mingw|cygwin/
9a6576 51         # Windows code via https://github.com/rdsubhas/vagrant-faster
TW 52         mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i
53         cpus = `echo %NUMBER_OF_PROCESSORS%`.to_i
66650d 54     end
55
75c553 56     # Give VM 1/4 system memory as well as CPU core count
MN 57     mem /= 1024 ** 2 * 4
58     cpus /= 4
66650d 59
9a6576 60     config.vm.provider "virtualbox" do |v|
TW 61         v.customize ["modifyvm", :id, "--memory", mem]
62         v.customize ["modifyvm", :id, "--cpus", cpus]
63         v.customize ["storagectl", :id, "--name", "SATA Controller", "--hostiocache", "on"]
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"]
659538 77     config.vm.synced_folder ".", "/vagrant_mounted"
f6ec4f 78     end
66650d 79
9a6576 80     config.vm.provider :libvirt do |libvirt|
TW 81         libvirt.memory = mem
82         libvirt.cpus = cpus
83     end
66650d 84
9a6576 85     # Once vagrant is able to chown files on OpenIndiana, chown line should be
TW 86     # removed from this part.
87     config.vm.provision "shell", inline: <<-SHELL
88         pfexec chown -R vagrant:vagrant /vagrant
89         pfexec pkg install build-essential
90
91         cd /vagrant && gmake setup
92         pfexec pkg set-publisher --non-sticky -g file:///vagrant/i386/repo userland
93         pfexec pkg set-publisher --non-sticky openindiana.org
94         echo "VM is ready, happy contributing!"
95     SHELL
66650d 96 end