-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
198 lines (148 loc) · 4.65 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
197
198
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
begin
load 'include/helper.rb'
rescue
LoadError
end
begin
#
vagrant_check_requirements()
#
vconfig = vagrant_get_config()
#
aliases = vagrant_get_aliases(vconfig)
#
random_ip = generate_random_ip()
#
box_hostname = vconfig['config']['box_hostname'].split('.')[0]
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#
config.vagrant.host = :detect
#
config.vm.box_check_update = false
config.vm.box = vconfig['config']['box_type']
config.vm.box_url = vconfig['config']['box_url']
# Hostname
config.vm.hostname = box_hostname
# SSH config
config.ssh.forward_agent = true
config.ssh.insert_key = false
# Fix NFS permission issues
config.nfs.map_uid = Process.uid
config.nfs.map_gid = Process.gid
# IP
config.vm.network :private_network, ip: random_ip
# Plugin: Hostsupdater
config.hostsupdater.remove_on_suspend = true
config.hostsupdater.aliases = aliases
# Virtualbox
config.vm.provider 'virtualbox' do |vb|
# Name
vb.name = box_hostname
# GUI
vb.gui = vconfig['config']['box_gui']
# RAM and CPU
if vconfig['config']['box_ram_cpu'] == 'auto'
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i / 4
memory = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif host =~ /linux/
cpus = `nproc`.to_i / 4
memory = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
else
cpus = vconfig['config']['box_cpu']
memory = vconfig['config']['box_ram']
end
else
cpus = vconfig['config']['box_cpu']
memory = vconfig['config']['box_ram']
end
vb.memory = memory
vb.cpus = cpus
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
vb.customize ['modifyvm', :id, '--ioapic', 'on']
vb.customize ['modifyvm', :id, '--chipset', 'ich9']
vb.customize ['modifyvm', :id, '--accelerate3d', 'off']
end
# Synced folders
vconfig['config']['vagrant_synced_folders'].each do |key, value|
src = File.expand_path(value.fetch('source'))
target = value.fetch('target')
if (value.fetch('type') == 'nfs')
mount_options = value.fetch('mount_options')
mount_options.push ('clientaddr=' + random_ip)
config.vm.synced_folder src,
target,
create: true,
type: "nfs",
mount_options: mount_options
elsif (value.fetch('type') == 'rsync')
config.vm.synced_folder src,
target,
type: "rsync",
rsync__auto: true,
rsync__args: [
"--verbose",
"--rsync-path='sudo rsync'",
"--archive",
"--delete",
"-z"
],
rsync__exclude: [
".git/",
"vagrant/"
]
end
end
if vconfig['config']['rmdbs']['use-mysql-persistent-storage']
config.persistent_storage.enabled = true
config.persistent_storage.use_lvm = false
config.persistent_storage.location = '.vagrant/storage/mysql-hdd.vdi'
config.persistent_storage.size = 5000
config.persistent_storage.mountname = 'mysql'
config.persistent_storage.filesystem = 'ext4'
config.persistent_storage.mountpoint = '/var/lib/mysql'
end
# Provisioning
config.vm.provision :chef_solo do |chef|
#
chef.environment = 'vagrant'
#
chef.json = vconfig
#
if vconfig['config']['vagrant_debugging']
chef.arguments = '-l debug -Fdoc'
chef.log_level = :debug
end
#
chef.environments_path = 'chef-repo/environments'
chef.cookbooks_path = [
'chef-repo/cookbooks',
'chef-repo/site-cookbooks'
]
chef.roles_path = 'chef-repo/roles'
#
if vconfig['config']['solr']['solr_install']
chef.add_role('web-solr')
end
#
if vconfig['config']['varnish_install']
chef.add_role('web-varnish')
end
#
if vconfig['config']['memcached_install']
chef.add_role('web-memcached')
end
#
chef.add_role('project')
end
# restart VM
config.vm.provision :reload
# set post_up_message
config.vm.post_up_message = get_vagrant_post_up_message(aliases)
end