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