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
|
# File 'lib/vagrant-qienv/action.rb', line 38
def initialize(app, env)
@app = app
@env = env
environment = @env[:env]
return if !File.exist?(project_home.join(".qi.yml"))
require_relative "config/config_provider.rb"
require_relative "config/config_provision.rb"
require_relative "config/config_network.rb"
require_relative "config/config_folders.rb"
qi_file = File.expand_path (project_home.join(".qi.yml"))
qi_definition = YAML.load(File.read(qi_file))
FileUtils.mkdir(vagrant_home) if !File.exist?(vagrant_home)
FileUtils.mkdir(vagrant_home.join('provision-ci')) if !File.exist?(vagrant_home.join('provision-ci'))
FileUtils.cp_r(gem_path.join('envs'), vagrant_home.join('provision-ci/envs')) if !File.exist?(vagrant_home.join('provision-ci/envs'))
FileUtils.cp_r(gem_path.join('provisioning'), vagrant_home.join('provision-ci/provisioning')) if !File.exist?(vagrant_home.join('provision-ci/provisioning'))
vagrant_env = qi_definition["env_runtime"] || "default"
environment_file = File.expand_path(vagrant_home.to_s + "/provision-ci/envs", File.dirname(__FILE__)) +
File::SEPARATOR + vagrant_env
if File.exists?(environment_file + ".json")
environment_ci = JSON.parse(File.read(environment_file + ".json"))
elsif File.exists?(environment_file + ".yml")
environment_ci = YAML.load(File.read(environment_file + ".yml"))
else
raise "Environment_ci config file not found, see envs directory\n #{environment_file}"
end
build_hosts_list(environment_ci["vms"])
vagrantfile_proc = Proc.new do
Vagrant.configure(2) do |config|
environment_ci["vms"].each do |vm_id, vm_config|
config.vm.define vm_id, autostart: vm_config["autostart"] do |instance|
config_provider(instance, vm_config, environment_ci["global"])
config_provision(instance, vm_config, vm_id, qi_definition["apps"], vagrant_home.join('provision-ci').to_s)
config_network(instance, vm_config)
config_folders(instance, vm_id, qi_definition["apps"], vagrant_home.join('provision-ci').to_s)
end
end
end
end
environment.instance_variable_set(:@root_path, project_home)
environment.instance_variable_set(:@local_data_path, vagrant_home)
config_loader = environment.config_loader
config_loader.set(:cienv, vagrantfile_proc.call)
environment.instance_variable_set(:@vagrantfile, Vagrant::Vagrantfile.new(config_loader, [:cienv, :home, :root]))
end
|