-
Notifications
You must be signed in to change notification settings - Fork 0
/
vagrant.rb
executable file
·124 lines (103 loc) · 3.78 KB
/
vagrant.rb
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
Vagrant.require_version '>= 1.8.3'
require File.dirname(__FILE__) + "/addons/utils.rb"
require File.dirname(__FILE__) + "/addons/site_picker.rb"
# Init defaults
$config = {
build: true,
build_box: "bento/debian-8.7",
synced_folder_type: "nfs",
memory: 1024,
cpus: 1,
cache: [:apt, :apt_lists, :chef, :composer, :bower, :npm, :gem],
recipes: ["debian::default", "debian::mysql", "debian::localdev"]
}.merge($config || {})
check_plugins($config[:build])
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if $config[:build]
config.vm.box = $config[:build_box]
else
config.vm.box = $config[:box]
config.vm.box_url = $config[:box_url]
end
config.vm.hostname = 'flow-vm'
# Networks
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
config.vm.network "forwarded_port", guest: 443, host: 8443, auto_correct: true
config.vm.network "forwarded_port", guest: 3306, host: 8306, auto_correct: true
# Static network for NFS
if $config[:synced_folder_type] == "nfs"
if Vagrant.has_plugin?("vagrant-auto_network")
config.vm.network "private_network", :auto_network => true
else
config.vm.network "private_network", ip: "192.168.42.10"
end
end
# Provider configuration
config.vm.provider "virtualbox" do |vb|
vb.memory = $config[:memory]
vb.cpus = $config[:cpus]
# Enable linked clone when building box
if $config[:build] and Vagrant::VERSION =~ /^1.8/
vb.linked_clone = true
end
# Enable network tracing
#vb.customize ['modifyvm', :id, '--nictrace1', 'on']
#vb.customize ['modifyvm', :id, '--nictracefile1', 'trace.pcap']
end
# Synced folders
case $config[:synced_folder_type]
when "rsync"
config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: [".git/", ".idea/"]
when "nfs"
config.vm.synced_folder ".", "/vagrant", type: "nfs", nfs_udp: false, mount_options: ["nolock,vers=3,tcp,noatime,actimeo=1"]
when "default"
config.vm.synced_folder ".", "/vagrant", owner: "vagrant", group: "www-data", mount_options: ["dmode=775","fmode=775"]
else
raise "Unknown $config_vm_synced_folder_type #{$config[:synced_folder_type]}"
end
# Setup cache buckets when building box (vagrant-cachier)
if $config[:build]
config.cache.scope = :box
config.cache.synced_folder_opts = {
type: :nfs,
mount_options: ["nolock,vers=3,tcp"]
}
config.cache.auto_detect = false
$config[:cache].each { |cache| config.cache.enable cache }
end
# Sync VirtualBox guest additions (vagrant-vbguest)
config.vbguest.no_remote = true
# Enable ssh agent forwarding
config.ssh.forward_agent = true
# Insert custom ssh keys
config.ssh.insert_key = false
config.ssh.private_key_path = [
File.dirname(__FILE__) + "/keys/private",
"~/.vagrant.d/insecure_private_key"
]
config.vm.provision "file", source: File.dirname(__FILE__) + "/keys/public", destination: "~/.ssh/authorized_keys"
config.vm.provision "shell", inline: <<-EOC
sudo sed -i -e "\\#PasswordAuthentication yes# s#PasswordAuthentication yes#PasswordAuthentication no#g" /etc/ssh/sshd_config
sudo service ssh restart
EOC
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "vagrant/chef/cookbooks"
# chef.roles_path = "../../chef/roles"
# chef.add_role "db"
$config[:recipes].each { |recipe| chef.add_recipe recipe }
chef.json = {}
end
# Provision box
config.vm.provision "shell" do |shell|
shell.path = File.dirname(__FILE__) + "/scripts/provision.sh"
shell.args = site_picker("config")
shell.privileged = false
end
# Forget provisioned site (vagrant-triggers)
config.trigger.before [:destroy] do
site_picker_forget
end
end