Class: PackerCommands

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-packer-plugin/support/packer_commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, engine, file_list, env_vars, mode) ⇒ PackerCommands

Returns a new instance of PackerCommands.



3
4
5
6
7
8
9
# File 'lib/vagrant-packer-plugin/support/packer_commands.rb', line 3

def initialize(params, engine, file_list, env_vars, mode)
	@params = params
	@engine = engine
	@file_list = file_list
	@env_vars = env_vars
	@mode = mode
end

Instance Method Details

#execute!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-packer-plugin/support/packer_commands.rb', line 11

def execute!
	  validate
     commands_final = []
     @file_list.each { |file| commands_final << @engine.get_json(@params.work_dir, file.split('/')[-1], file) }

     command_sh = @env_vars
     commands_final.each do |commands|
       commands.each do |command|
         puts "[packer-#{@mode}] #{command[0]}"
         puts "[packer-#{@mode}] DEBUG: #{command[1]}"
         command_sh += command[1] + "\n"
       end
     end
     command_file = "/tmp/#{@mode}-commands.sh"
     File.open(command_file, 'w') { |file| file.write(command_sh) }
     FileUtils.chmod(0755, command_file);
     stdout, stderr, status = Open3.capture3(command_file)
     puts "[packer-#{@mode}] RET: #{status}, ERR: #{stderr}, OUT: #{stdout}"
end