-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVagrantfile
107 lines (86 loc) · 3.94 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
105
106
107
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
require 'yaml'
# Read settings from the configuration file.
# A non-default configuration file can be specified via CONFIG env variable.
# Each setting can be overridden with an environment variable.
box_config = YAML.load_file(ENV['config'] || 'config.yaml')
# generic
BOX = ENV['BOX'] || box_config['box'] || 'ubuntu/focal64'
PROVIDER = ENV['PROVIDER'] || box_config['virtualbox'] || 'virtualbox'
# VM options
# NOTE: Depending on the provider of choice, some options may be ignored
VM_NAME = ENV['VM_NAME'] || box_config['vm']['name'] || ''
VM_DESC = ENV['VM_DESC'] || box_config['vm']['description'] || ''
VM_HOTPLUG = ENV['VM_HOTPLUG'] || box_config['vm']['hotplug'] || 'on'
VM_CPU = ENV['VM_CPU'] || box_config['vm']['cpu'] || '2'
VM_RAM = ENV['VM_RAM'] || box_config['vm']['ram'] || 1024 * 4
# private network
PNET_ENABLE = ENV['PNET_ENABLE'] || box_config['private_network']['enable'] || 'NO'
PNET_NAME = ENV['PNET_NAME'] || box_config['private_network']['name'] || ''
PNET_IP = ENV['PNET_IP'] || box_config['private_network']['ip'] || ''
# guest system settings
SYS_SWAPPINESS = ENV['SYS_SWAPPINESS'] || box_config['guest_system']['swappiness'] || '1'
Vagrant.require_version '>= 2.2.16'
Vagrant.configure('2') do |config|
config.vm.box = BOX
config.vm.box_check_update = false
# Syncer Folders
if box_config['synced_folders'].kind_of?(Array)
box_config['synced_folders'].each { |current_folder|
config.vm.synced_folder current_folder['host'], current_folder['guest']
}
end
if PNET_ENABLE.downcase == 'yes'
if PNET_IP == ''
config.vm.network 'private_network', name: PNET_NAME, type: 'dhcp'
else
config.vm.network 'private_network', name: PNET_NAME, ip: PNET_IP
end
end
if PROVIDER.downcase == 'virtualbox'
config.vm.provider 'virtualbox' do |vb|
vb.gui = false
vb.customize ["modifyvm", :id, '--audio', 'none']
vb.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
vb.customize ['modifyvm', :id, '--name', VM_NAME]
vb.customize ['modifyvm', :id, '--description', VM_DESC]
vb.customize ['modifyvm', :id, '--memory', VM_RAM]
vb.customize ['modifyvm', :id, '--cpuhotplug', VM_HOTPLUG]
vb.customize ['modifyvm', :id, '--cpus', VM_CPU]
end
else
puts 'ERROR: Unsupported provider: ' + PROVIDER
puts 'ABORT'
exit 1
end
# write some information in the info directory, so that it will
# be easily available form the VM
info_file = File.new('generated/box', 'w')
info_file.puts(BOX)
# Create a the FEATURES file.
# Every time we add an optional feature we'll write a line into it,
# as an uppercase id in snake case
info_file = File.new('generated/FEATURES', 'w')
if File.file?('bootstrap.sh')
config.vm.provision :shell,
path: 'bootstrap.sh',
env: {
'SYS_SWAPPINESS' => SYS_SWAPPINESS
}
end
# end of the FEATURES file
info_file.close
end