class Singel::PackerExecutor

executes packer commands against template object

Public Class Methods

new(template, builders) click to toggle source
   # File lib/singel/executor.rb
22 def initialize(template, builders)
23   @template = template
24   @file_path = template.path
25   @template_builders = template.builders
26   @specified_builders = builders
27 end

Public Instance Methods

build() click to toggle source
   # File lib/singel/executor.rb
43 def build
44   puts "Building #{File.basename(@file_path, '.json')}:".to_green
45   stream_cmd("packer build #{build_options} #{@file_path}")
46 end
build_options() click to toggle source

specify the builders if any were passed

   # File lib/singel/executor.rb
49 def build_options
50   "-only=#{@specified_builders.join(',')}" unless @specified_builders.empty?
51 end
exit_error() click to toggle source

throw and error message and exit with and error status

   # File lib/singel/executor.rb
69 def exit_error
70   puts "An error occured during the packer run.\nSee the above output for more details.".to_red
71   exit!
72 end
list() click to toggle source

print out the builders for this template

   # File lib/singel/executor.rb
30 def list
31   puts File.basename(@file_path, '.json') + ':'
32 
33   builders = @template.builders_hash
34   if builders.empty?
35     puts '- No builders found'.indent.to_red
36   else
37     builders.each_pair do |name, type|
38       puts "- #{name} (type: #{type})".indent
39     end
40   end
41 end
stream_cmd(command) click to toggle source
   # File lib/singel/executor.rb
53 def stream_cmd(command)
54   PTY.spawn(command) do |r, _w, pid|
55     begin
56       r.each { |line| print line; }
57     rescue Errno::EIO # rubocop: disable Lint/HandleExceptions
58       # this is an expected behavior when an app is done sending output
59     ensure
60       Process.wait(pid)
61     end
62   end
63   exit_error unless $CHILD_STATUS.zero?
64 rescue PTY::ChildExited
65   exit_error unless $CHILD_STATUS.zero?
66 end