This repository has been archived by the owner on Jul 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
115 lines (83 loc) · 4.69 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require_relative "scripts/ruby/configuration/model.rb"
require_relative "scripts/ruby/configuration/factory.rb"
require_relative "scripts/ruby/configuration/repository.rb"
require_relative "scripts/ruby/helpers/collections.rb"
require_relative "scripts/ruby/helpers/logger.rb"
defaultsFilePath = "./configs/vagrant/config.defaults.json"
overridesFilePath = "./configs/vagrant/config.json"
# Build Merged Configuration Repository
configRepo = ConfigurationFactory::BuildConfigRepo(defaultsFilePath, overridesFilePath)
# Log Configuration collection to the console
# configRepo.LogConfigurations()
Vagrant.configure(configRepo.ForVagrant['version']) do |v_config|
v_config.ssh.insert_key = configRepo.GetValue("vagrant/ssh/enable_custom")
# Configuration Loop for each server defined in Merged Configuration
configRepo.ForServers.each do |svr_inst|
if svr_inst["enabled"]
hostName = svr_inst["name"]
# Begin configuring the virtual machine Definition
v_config.vm.define hostName do |svr_def|
# Begin configuring the virtual machine's box image definition
svr_def.vm.hostname = hostName
svr_def.vm.box = configRepo.GetValueFrom(svr_inst, "vm/image/name")
svr_def.vm.box_check_update = configRepo.GetValueFrom(svr_inst, "vm/image/check_for_update")
# End configuring the virtual machine's box image definition
# Begin configuring the virtual machine's network definition
svr_def.vm.network configRepo.GetValueFrom(svr_inst, "vm/hardware/nic/_type"),
ip: configRepo.GetValueFrom(svr_inst, "vm/hardware/nic/ip")
# Begin configuring the virtual machine's port forward definitions
configRepo.GetValueFrom(svr_inst, "vm/hardware/nic/port_fwds").each do |pf_inst|
svr_def.vm.network :forwarded_port,
id: configRepo.GetValueFrom(pf_inst, "name"),
auto_correct: configRepo.GetValueFrom(pf_inst, "auto_correct"),
guest: configRepo.GetValueFrom(pf_inst, "ports/guest"),
host: configRepo.GetValueFrom(pf_inst, "ports/host")
end # End forwarded_ports.each
# End configuring the virtual machine's port forward definitions
# End configuring the virtual machine's network definition
# Begin configuring the virtual machine's virtualBox provider
svr_def.vm.provider :virtualbox do |vb_def|
vb_def.name = hostName
vb_def.cpus = configRepo.GetValueFrom(svr_inst, "vm/hardware/cpu_count")
vb_def.memory = configRepo.GetValueFrom(svr_inst, "vm/hardware/ram_total")
# Important to fix an issue with ubuntu 16.x's SSH connection
vb_def.customize ["modifyvm", :id, "--cableconnected1", "on"]
end # End vb_def
# End configuring the virtual machine's virtualBox provider
# Begin configuring the virtual machine Folder Syncs
configRepo.GetValueFrom(svr_inst, "fs_syncs").each do |fs_inst|
svr_def.vm.synced_folder configRepo.GetValueFrom(fs_inst, "paths/host"),
configRepo.GetValueFrom(fs_inst, "paths/guest"),
disabled: !configRepo.GetValueFrom(fs_inst, "enabled")
end # fs_inst.each
# End configuring the virtual machine's folder syncs
# Begin configuring the virtual machine's provisioner scripts
configRepo.GetValueFrom(svr_inst, "scripts").each do |scr_inst|
svr_def.vm.provision configRepo.GetValueFrom(scr_inst, "_type") do |script_definition|
script_definition.name = configRepo.GetValueFrom(scr_inst, "name")
script_definition.path = configRepo.GetValueFrom(scr_inst, "path")
script_definition.args = []
# Begin building the script definition's array of arguments
configRepo.GetValueFrom(scr_inst, "args").each do |arg_inst|
script_definition.args.push(configRepo.GetScriptArgument(arg_inst))
end # End arg_inst.each
# End building the script definition's array of arguments
end # End script_definition
end # End scr_inst.each
# Begin configuring the virtual machine for docker & docker-compose
if configRepo.GetValueFrom(svr_inst, "docker/enabled")
svr_def.vm.provision :docker
svr_def.vm.provision :docker_compose,
run: configRepo.GetValueFrom(svr_inst, "docker/run"),
yml: configRepo.GetValueFrom(svr_inst, "docker/compose_file")
end # End if docker is enabled
# End configuring the virtual machine for docker & docker-compose
# End configuring the virtual machine provisioner scripts
end # End svr_def
# End configuring the virtual machine definition
end # End if srv_inst is enabled
end # End svr_inst.each
# End the configuration loop for each server defined in the merged configuration
end # End v_config