-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
196 lines (179 loc) · 6.96 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# -*- mode: ruby -*-
# vim: ts=2 sw=2 et ft=ruby :
system("./bin/config.sh >/dev/null")
Vagrant.require_version ">= 2.1.0"
$script_export_packages = <<SCRIPT
# sync any guest packages to host (vboxsf)
rsync -avzh --delete /var/cache/portage/packages/* /vagrant/packages/
# clean guest packages
rm -rf /var/cache/portage/packages/*
# let it settle
sync && sleep 30
SCRIPT
$script_clean_kernel = <<SCRIPT
# clean stale kernel files
mount /boot || true
eclean-kernel -l
eclean-kernel -n 1
ego boot update
# clean kernel sources
cd /usr/src/linux
make distclean
# copy latest kernel config
cp -f /usr/src/kernel.config /usr/src/linux/.config
# prepare for module compiles
make olddefconfig
make modules_prepare
SCRIPT
$script_remove_kernel = <<SCRIPT
emerge --unmerge debian-sources
# clean stale kernel files
mount /boot || true
eclean-kernel -l
eclean-kernel -n 1
ego boot update
SCRIPT
$script_cleanup = <<SCRIPT
# debug: list running services
rc-status
# stop services
/etc/init.d/mysql stop || true
/etc/init.d/xdm stop || true
/etc/init.d/xdm-setup stop || true
/etc/init.d/elogind stop || true
/etc/init.d/gpm stop || true
/etc/init.d/rsyslog stop || true
/etc/init.d/dbus -D stop || true
/etc/init.d/haveged stop || true
/etc/init.d/udev stop || true
/etc/init.d/vixie-cron stop || true
/etc/init.d/dhcpcd stop || true
/etc/init.d/local stop || true
/etc/init.d/acpid stop || true
# let it settle
sync && sleep 15
# run cleanup script (from funtoo-base box)
/usr/local/sbin/foo-cleanup
# delete some logfiles
logfiles=( emerge emerge-fetch genkernel )
for i in "${logfiles[@]}"; do
rm -f /var/log/$i.log
done
rm -f /var/log/portage/elog/*.log
# let it settle
sync && sleep 15
# debug: list running services
rc-status
# clean shell history
set +o history
rm -f /home/vagrant/.bash_history
rm -f /root/.bash_history
sync && sleep 5
# zerofree /boot
mount -v -n -o remount,ro /dev/sda1
zerofree /dev/sda1 && echo "zerofree: success on /dev/sda1 (boot)"
# zerofree root fs
mount -v -n -o remount,ro /dev/sda4
zerofree /dev/sda4 && echo "zerofree: success on /dev/sda4 (root)"
# swap
swapoff -v /dev/sda3
bash -c 'dd if=/dev/zero of=/dev/sda3 2>/dev/null' || true
mkswap /dev/sda3
SCRIPT
box_name = ENV["BUILD_BOX_NAME"] || "foobarlab/webdev"
headless = ENV['BUILD_HEADLESS'] || "false"
memory = ENV['BUILD_BOX_MEMORY'] || 2048
cpus = ENV['BUILD_BOX_CPUS'] || 2
Vagrant.configure("2") do |config|
#config.vagrant.sensitive = ["MySecretPassword", ENV["MY_TOKEN"]] # TODO hide sensitive information
config.vm.box_check_update = false
config.vm.box = box_name
#config.vm.box_version = ">0" # TODO version constraint (not building funtoo next)
config.vm.hostname = box_name
config.vm.provider "virtualbox" do |vb|
vb.gui = (headless == "false")
vb.memory = memory
vb.cpus = cpus
# customize VirtualBox settings, see also 'virtualbox.pkr.hcl'
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
vb.customize ["modifyvm", :id, "--audio", "pulse"]
vb.customize ["modifyvm", :id, "--audiocontroller", "hda"]
vb.customize ["modifyvm", :id, "--audioin", "on"]
vb.customize ["modifyvm", :id, "--audioout", "on"]
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.customize ["modifyvm", :id, "--usbxhci", "off"]
vb.customize ["modifyvm", :id, "--rtcuseutc", "on"]
vb.customize ["modifyvm", :id, "--chipset", "ich9"]
vb.customize ["modifyvm", :id, "--vram", "64"]
vb.customize ["modifyvm", :id, "--vrde", "off"]
vb.customize ["modifyvm", :id, "--hpet", "on"]
vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
vb.customize ["modifyvm", :id, "--vtxvpid", "on"]
vb.customize ["modifyvm", :id, "--nested-hw-virt", "on"]
vb.customize ["modifyvm", :id, "--largepages", "on"]
vb.customize ["modifyvm", :id, "--spec-ctrl", "off"]
vb.customize ["modifyvm", :id, "--graphicscontroller", "vmsvga"]
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
# spectre meltdown mitigations, see https://www.virtualbox.org/ticket/17987
#vb.customize ["modifyvm", :id, "--largepages", "off"]
#vb.customize ["modifyvm", :id, "--spec-ctrl", "on"]
#vb.customize ["modifyvm", :id, "--ibpb-on-vm-entry", "on"]
#vb.customize ["modifyvm", :id, "--ibpb-on-vm-exit", "on"]
#vb.customize ["modifyvm", :id, "--l1d-flush-on-sched", "off"]
#vb.customize ["modifyvm", :id, "--l1d-flush-on-vm-entry", "on"]
#vb.customize ["modifyvm", :id, "--nestedpaging", "off"]
# clipboard:
vb.customize ["modifyvm", :id, "--clipboard-mode", "bidirectional"]
end
# force base mac address to be re-generated
#config.vm.base_mac = nil
# fixed mac address for eth0
config.vm.base_mac = "080027344abc"
# adapter 1 (eth0): private network (NAT with forwarding)
config.vm.network "forwarded_port", guest: 8080, host: 8080 # apache
config.vm.network "forwarded_port", guest: 8443, host: 8443 # apache
config.vm.network "forwarded_port", guest: 8000, host: 8000 # lighttpd / dashboard
config.vm.network "forwarded_port", guest: 3306, host: 3306 # mysql
config.vm.network "forwarded_port", guest: 5432, host: 5432 # postgresql
# adapter 2 (eth1): public network (bridged)
config.vm.network "public_network",
type: "dhcp",
mac: "0800276c6237", # fixed, pattern: 080027xxxxxx
use_dhcp_assigned_default_route: true,
bridge: [
"eth0",
"wlan0",
"en0: Wi-Fi (Airport)",
"en1: Wi-Fi (AirPort)"
]
config.ssh.insert_key = false
config.ssh.connect_timeout = 60
config.vm.synced_folder '.', '/vagrant', disabled: false, automount: true
# debug: show network interfaces + ip adresses
config.vm.provision "net_debug", type: "shell", privileged: true, inline: <<-SHELL
echo "Configured network interfaces:"
ip a | grep glo | awk '{print $8 " => " $2}' | cut -f1 -d/
ip a | grep link/ether | awk '{print "MAC => " $2}'
cat /etc/udev/rules.d/70-persistent-net.rules || true
SHELL
# ansible provisioning executed only in finalizing step (finalize.sh)
config.vm.provision "provision_ansible", type: "ansible_local" do |ansible|
ansible.install = false
ansible.verbose = "v"
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/provision.yml"
ansible.config_file = "ansible/ansible.cfg"
ansible.inventory_path = "ansible/environment/#{ENV['BUILD_ENVIRONMENT']}"
ansible.raw_arguments = ["--connection=local"]
ansible.extra_vars = {
mysql_root_password: "#{ENV['BUILD_MYSQL_ROOT_PASSWORD'] || "changeme"}"
}
end
config.vm.provision "export_packages", type: "shell", inline: $script_export_packages, privileged: true
config.vm.provision "clean_kernel", type: "shell", inline: $script_clean_kernel, privileged: true
config.vm.provision "remove_kernel", type: "shell", inline: $script_remove_kernel, privileged: true
config.vm.provision "cleanup", type: "shell", inline: $script_cleanup, privileged: true
# TODO add trigger for disk compaction?
end