This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
forked from Chassis/Chassis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
247 lines (205 loc) · 7.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# -*- mode: ruby -*-
# vi: set ft=ruby :
# See https://github.com/hashicorp/vagrant/issues/8878 and https://github.com/Chassis/Chassis/issues/771
# This is also needed to assist in provisioning Chassis on Windows 10.
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
# Check that submodules have been loaded
if not File.exist?(File.join(File.dirname(__FILE__), "puppet", "modules", "apt", ".git"))
puts "NOTICE: Submodules not found, updating for you"
if not system("git submodule update --init", :chdir => File.dirname(__FILE__))
puts "WARNING: Submodules may be missing, and could not automatically\ndownload them for you."
end
# Extra new line, please!
puts
end
require_relative "puppet/chassis.rb"
CONF = Chassis.config
# Install extensions defined in config file
Chassis.install_extensions(CONF)
# Add extra extension modules
base_path = Pathname.new( File.dirname( __FILE__ ) )
module_paths = [ base_path.to_s + "/puppet/modules" ]
module_paths.concat Dir.glob( base_path.to_s + "/extensions/*/modules" )
# Convert to relative from Vagrantfile
module_paths = Chassis.make_relative(base_path, module_paths)
# Add global extensions, if they exist
global_ext_path = File.join(Dir.home, ".chassis", "extensions")
use_global_ext = Dir.exist?(global_ext_path) && ! Dir.empty?(global_ext_path)
if use_global_ext
global_ext_modules = Dir.glob(global_ext_path + "/*/modules")
global_ext_modules.delete_if { |path|
ext_name = path.split("/")[-2]
# Search for the ext_name in the regular extensions
module_paths.include?("extensions/" + ext_name + "/modules")
}
global_ext_modules = Chassis.make_relative(global_ext_path, global_ext_modules)
end
Vagrant.configure("2") do |config|
# Set the machine name not default.
if CONF['machine_name'] != 'default'
config.vm.define CONF['machine_name']
end
config.trigger.before [ :provision, :up, :halt ] do |trigger|
deprecated_extensions = ''
if CONF["version"] >= 3 && ! CONF["extensions"].nil?
# Warn about old extensions.
CONF["extensions"].each do |extension|
if extension.include? "-"
new_extension = extension.gsub(/-/, '_')
deprecated_extensions << "Please change #{extension} to #{new_extension} in your yaml configuration file.\n"
end
end
trigger.warn = "#{deprecated_extensions}"
end
end
# Show a warning that non-*.local domains will not automatically resolve.
config.trigger.after [ :provision, :up ] do |trigger|
if ! CONF['hosts'][0].include?('.local')
trigger.info = "\n\e[33mWARNING: The hosts URL does not contain .local.\nYou will need to edit your hosts file for this URL to resolve.\e[0m"
end
end
# Set up synced folders.
synced_folders = CONF["synced_folders"].clone
synced_folders["."] = "/vagrant"
if use_global_ext
synced_folders[global_ext_path] = "/vagrant/extensions/_global"
end
# Set up potential providers.
config.vm.provider "virtualbox" do |vb|
# Use linked clones to preserve disk space.
vb.linked_clone = true if Vagrant::VERSION =~ /^1.8/
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
# Customisations from config.local.yaml
if CONF['virtualbox']
vb.memory = CONF['virtualbox']['memory'] if CONF['virtualbox']['memory']
vb.cpus = CONF['virtualbox']['cpus'] if CONF['virtualbox']['cpus']
end
# Set the machine name for the VirtualBox GUI.
if CONF['machine_name'] != 'default'
vb.name = CONF['machine_name']
end
# Pass synced folders to guest
full_synced = {}
synced_folders.each do |from, to|
full_from = File.realpath from, base_path.to_s
full_synced[ to ] = full_from
end
vb.customize [ "guestproperty", "set", :id, "/Chassis/synced_folders", JSON.dump( full_synced ) ]
# Ensure the VM has network access, see https://stackoverflow.com/a/18457420. This is another workaround for Windows.
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
if CONF['_mode'] == "normal"
# Allow insecure boxes for Windows
config.vm.box_download_insecure = true
# Use the Chassis box we've built with the default config.
config.vm.box = "chassis/chassis"
config.vm.box_version = ">= 5.0, < 6.0"
elsif CONF['_mode'] == "custom"
config.vm.box = CONF['box']
else
# We <3 Ubuntu LTS
config.vm.box = "bento/ubuntu-22.04"
end
# The Parallels Provider uses a different naming scheme.
config.vm.provider :parallels do |_v, override|
# Vagrant currently runs under Rosetta on M1 devices. As a result,
# this seems to be the most reliable way to detect whether or not we're
# running under ARM64.
if Etc.uname[:version].include? 'ARM64'
override.vm.box = 'mpasternak/focal64-arm'
end
end
# Enable SSH forwarding
config.ssh.forward_agent = true
# Disable updating of Virtual Box Guest Additions for faster provisioning.
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
# Add port forwarding for Vagrant Share
config.vm.network "forwarded_port", guest: 80, host: 8000, auto_correct: true
# Having access would be nice.
if CONF['ip'] == "dhcp"
config.vm.network :private_network, type: "dhcp"
else
config.vm.network :private_network, ip: CONF['ip']
end
config.vm.hostname = CONF['hosts'][0]
# Before any other provisioning, ensure that we're up-to-date
preprovision_args = [
CONF['apt_mirror'].to_s,
CONF['database']['has_custom_prefix'] ? "" : "check_prefix"
]
config.vm.provision :shell, :path => "puppet/preprovision.sh", :args => preprovision_args
# Provision our setup with Puppet
config.vm.provision :shell do |shell|
shell.inline = "puppet apply $@"
shell.keep_color = true
shell.args = []
# Set up the module paths
module_paths.map! { |rel_path| "/vagrant/" + rel_path }
# Set up the global extension paths
if ( global_ext_modules )
global_ext_modules.map! { |rel_path| "/vagrant/extensions/_global/" + rel_path }
extensions = module_paths + global_ext_modules
else
extensions = module_paths
end
shell.args.push("--basemodulepath /vagrant/puppet/modules:" + extensions.join( ':' ).inspect)
# Set up the full environment
shell.args.push("--confdir /vagrant/puppet")
# Set the actual manifest to provision with
shell.args.push("/vagrant/puppet/manifests")
# Uncomment this line to turn debugging on:
# shell.args.push("--verbose --debug")
# Ensure Puppet doesn't escape our arguments
shell.args = shell.args.join(" ")
end
# Help the user out the first time they provision
config.vm.provision :shell do |shell|
if CONF['_mode'] == "base"
shell.path = "puppet/preparebox.sh"
else
shell.path = "puppet/postprovision.sh"
end
shell.args = [
# 0 = hostname
CONF['hosts'][0],
# 1 = username
CONF['admin']['user'],
# 2 = password
CONF['admin']['password']
]
end
# Export necessary constants to the VM
config.vm.provision "set_constants",
type: :shell,
path: "puppet/export-constants.sh",
run: "always"
# Ensure that WordPress can install/update plugins, themes and core
mount_opts = CONF['nfs'] ? [] : ["dmode=777","fmode=777"]
synced_folders.each do |from, to|
config.vm.synced_folder from, to, :mount_options => mount_opts, :nfs => CONF['nfs'], :group => 'www-data', :owner => 'vagrant'
# Automatically use bindfs if we can.
if CONF['nfs'] && Vagrant.has_plugin?("vagrant-bindfs")
config.bindfs.bind_folder to, to
end
end
config.vm.provider :parallels do |_v, override|
mount_opts = CONF['nfs'] ? [] : ["share"]
synced_folders.each do |from, to|
override.vm.synced_folder from, to, :mount_options => mount_opts, :nfs => CONF['nfs'], :group => 'www-data', :owner => 'vagrant'
end
end
# Change directories to /vagrant and use the correct shell.
if CONF['extensions'] and (CONF['extensions'].include? "fish" or CONF['extensions'].include? "chassis/fish")
config.ssh.extra_args = ["-t", "cd /vagrant; fish -l"]
else
config.ssh.extra_args = ["-t", "cd /vagrant; bash -l"]
end
# Success?
end