-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vagrantfile
192 lines (166 loc) · 6.35 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrantfile using cdk-comp/vagrant-easyengine
# Check out https://github.com/cdk-comp/vagrant-easyengine-install to learn more about cdk-comp/vagrant-easyengine
#
# Author: Dima Minka
# URL: https://cdk.co.il
#
# File Version: 1.2.2
require 'yaml'
# Load the settings file
settings = YAML.load_file(File.join(File.dirname(__FILE__), "vagrant-conf.yml"))
# Detect host OS for different folder share configuration
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
Vagrant.configure("2") do |config|
config.vm.box = settings["vm_box"] ||= "cdk-comp/vagrant-easyengine"
config.vm.provider settings["provider"] ||= "virtualbox"
[
{ :name => "vagrant-hostmanager", :version => ">= 1.8.9" },
{ :name => "vagrant-vbguest", :version => ">= 0.16.0" },
{ :name => "vagrant-cachier", :version => ">= 1.2.1"}
].each do |plugin|
Vagrant::Plugin::Manager.instance.installed_specs.any? do |s|
req = Gem::Requirement.new([plugin[:version]])
if (not req.satisfied_by?(s.version)) && plugin[:name] == s.name
raise "#{plugin[:name]} #{plugin[:version]} is required. Please run `vagrant plugin install #{plugin[:name]}`"
end
end
end
if OS.windows?
if !Vagrant.has_plugin?('vagrant-winnfsd')
puts "The vagrant-winnfsd plugin is required. Please install it with \"vagrant plugin install vagrant-winnfsd\""
end
end
config.cache.scope = :box
# Vagrant hardware settings
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"]
vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "2"]
end
config.vm.provider "parallels" do |v|
v.memory = settings["memory"] ||= "2048"
v.cpus = settings["cpus"] ||= "2"
end
# vagrant-hostmanager config (https://github.com/smdahlen/vagrant-hostmanager)
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.vm.define "project" do |node|
node.vm.hostname = settings['hostname'] ||= 'vagrant-easyengine'
node.vm.network :private_network, ip: settings['ip'] ||= '192.168.100.100'
node.hostmanager.aliases = [settings['aliases']]
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 443, host: 443
end
# Configure The Public Key For SSH Access
if settings.include? 'authorize'
if File.exists? File.expand_path(settings["authorize"])
config.vm.provision "shell" do |s|
s.inline = "echo $1 | grep -xq \"$1\" /home/vagrant/.ssh/authorized_keys || echo \"\n$1\" | tee -a /home/vagrant/.ssh/authorized_keys"
s.args = [File.read(File.expand_path(settings["authorize"]))]
end
end
end
# Copy The SSH Private Keys To The Box
if settings.include? 'keys'
if settings["keys"].to_s.length == 0
puts "Check your vagrant-conf.yml file, you have no private key(s) specified."
exit
end
settings["keys"].each do |key|
if File.exists? File.expand_path(key)
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = "echo \"$1\" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2"
s.args = [File.read(File.expand_path(key)), key.split('/').last]
end
else
puts "Check your vagrant-conf.yml file, the path to your private key does not exist."
exit
end
end
end
# Disabling the default /vagrant share
config.vm.synced_folder '.', '/vagrant', disabled: true
# Register All Of The Configured Shared Folders
if settings.include? 'folders'
settings["folders"].each do |folder|
if File.exists? File.expand_path(folder["map"])
# Use vagrant-winnfsd if available https://github.com/flurinduerst/WPDistillery/issues/78
if Vagrant.has_plugin? 'vagrant-winnfsd'
config.vm.synced_folder folder["map"], folder["to"],
nfs: true,
mount_options: [
'nfsvers=3',
'vers=3',
'actimeo=1',
'rsize=8192',
'wsize=8192',
'timeo=14'
]
else
config.vm.synced_folder folder["map"], folder["to"], owner: "www-data", group: "www-data", disabled: false, create: true
end
end
end
end
config.ssh.forward_agent = true
# Configure The email
if settings["vagrant_email"].to_s.length == 0
puts "Check your vagrant-conf.yml file, you have no vagrant_email specified."
exit
else
config.vm.provision "shell" do |s|
s.inline = "echo $1$2 | grep -xq \"$1$2\" /home/vagrant/.bash_profile || echo \"\n$1$2\" | tee -a /home/vagrant/.bash_profile"
s.args = ['export vagrant_email=', settings["vagrant_email"]]
end
end
# Configure The user
if settings["vagrant_user"].to_s.length == 0
puts "Check your vagrant-conf.yml file, you have no vagrant_user specified."
exit
else
config.vm.provision "shell" do |s|
s.inline = "echo $1$2 | grep -xq \"$1$2\" /home/vagrant/.bash_profile || echo \"\n$1$2\" | tee -a /home/vagrant/.bash_profile"
s.args = ['export vagrant_user=', settings["vagrant_user"]]
end
end
# WPDistillery Windows Support
if Vagrant::Util::Platform.windows?
config.vm.provision "shell",
inline: "echo \"Converting Files for Windows\" && sudo apt-get install -y dos2unix && cd /var/www/ && dos2unix wpdistillery/config.yml && dos2unix wpdistillery/provision.sh && dos2unix wpdistillery/wpdistillery.sh",
run: "always", privileged: false
end
if settings["vm_box"] == "cdk-comp/vagrant-easyengine"
# Basic provison for new box
config.vm.provision "shell", path: "provision/provision.sh"
# Run app create with custom configuration
if settings["app_installer"] == true
if settings.include? 'aliases'
config.vm.provision "file", source: "provision/vagrant_up.sh", destination: "vagrant_up.sh", run: "always"
settings["aliases"].each do |host|
config.vm.provision "shell", run: "always" do |s|
s.inline = "sudo bash vagrant_up.sh $1"
s.args = host
end
end
end
end
end
end