Andreas Wacknitz
2024-04-05 06fb6dc41cdafb96239cf8a3d551052267c9463d
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
97eed1 16 # Copyright 2021 David Stes
66650d 17 #
18
19 Vagrant.configure("2") do |config|
9a6576 20     # Every Vagrant development environment requires a box. You can search for
TW 21     # boxes at https://atlas.hashicorp.com/search.
22     config.vm.box = "openindiana/hipster"
66650d 23
9a6576 24     # Disable automatic box update checking. If you disable this, then
TW 25     # boxes will only be checked for updates when the user runs
26     # `vagrant box outdated`. This is not recommended.
27     config.vm.box_check_update = true
66650d 28
9a6576 29     # Unless OpenIndiana is better supported in vagrant, we have to use this
TW 30     # workaround. The problem with vagrant is that it creates folder as root:root,
31     # but rsync connects as vagrant and thus fails to write.
32     config.vm.synced_folder ".", "/vagrant", type: "rsync",
33       rsync__args: ["--verbose", "--archive", "-zz", "--copy-links"],
34       rsync__rsync_path: "pfexec rsync", owner: "vagrant", group: "vagrant"
66650d 35
9a6576 36     # Autoconfigure resources for development VM. The snippet is taken from
TW 37     # https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck.
38     # We allocate 1/4 of available system memory and CPU core count of the host
39     # to the VM, so performance does not suck.
66650d 40     host = RbConfig::CONFIG['host_os']
41
75c553 42     # Get memory size and CPU cores amount
97eed1 43     if host =~ /solaris/
DS 44     mem = `/usr/sbin/prtconf|grep Memory|cut -f3 -d' '`.to_i * 1024 * 1024
45     cpus = `/usr/sbin/psrinfo|wc -l`.to_i
46     elsif host =~ /darwin/
9a6576 47         # sysctl returns Bytes
TW 48         mem = `sysctl -n hw.memsize`.to_i
49         cpus = `sysctl -n hw.ncpu`.to_i
66650d 50     elsif host =~ /linux/
9a6576 51         # meminfo shows size in kB; convert to Bytes
TW 52         mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.to_i * 1024
53         cpus = `getconf _NPROCESSORS_ONLN`.to_i
66650d 54     elsif host =~ /mswin|mingw|cygwin/
9a6576 55         # Windows code via https://github.com/rdsubhas/vagrant-faster
TW 56         mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i
57         cpus = `echo %NUMBER_OF_PROCESSORS%`.to_i
97eed1 58     else
DS 59     puts "Unsupported operating system"
60     exit
66650d 61     end
62
75c553 63     # Give VM 1/4 system memory as well as CPU core count
MN 64     mem /= 1024 ** 2 * 4
65     cpus /= 4
66650d 66
9a6576 67     config.vm.provider "virtualbox" do |v|
TW 68         v.customize ["modifyvm", :id, "--memory", mem]
69         v.customize ["modifyvm", :id, "--cpus", cpus]
97eed1 70
9a6576 71         v.customize ["storagectl", :id, "--name", "SATA Controller", "--hostiocache", "on"]
TW 72         # Enable following line, if oi-userland directory is on non-rotational
73         # drive (e.g. SSD). (This could be automated, but with all those storage
74         # technologies (LVM, partitions, ...) on all three operationg systems,
75         # it's actually error prone to detect it automatically.) macOS has it
76         # enabled by default as recent Macs have SSD anyway.
77         if host =~ /darwin/
78             v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
79         else
80             #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
81         end
82         # Should we ever support `--discard` option, we need to switch to VDI
83         # virtual disk format first.
84         #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--discard", "on"]
659538 85     config.vm.synced_folder ".", "/vagrant_mounted"
f6ec4f 86     end
66650d 87
9a6576 88     config.vm.provider :libvirt do |libvirt|
TW 89         libvirt.memory = mem
90         libvirt.cpus = cpus
91     end
66650d 92
9a6576 93     # Once vagrant is able to chown files on OpenIndiana, chown line should be
TW 94     # removed from this part.
95     config.vm.provision "shell", inline: <<-SHELL
96         pfexec chown -R vagrant:vagrant /vagrant
97         pfexec pkg install build-essential
98
99         cd /vagrant && gmake setup
100         pfexec pkg set-publisher --non-sticky -g file:///vagrant/i386/repo userland
101         pfexec pkg set-publisher --non-sticky openindiana.org
102         echo "VM is ready, happy contributing!"
103     SHELL
66650d 104 end