Class: PackerExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/executor.rb

Overview

executes packer commands against template object

Instance Method Summary collapse

Constructor Details

#initialize(template, builders) ⇒ PackerExecutor

Returns a new instance of PackerExecutor.



21
22
23
24
25
26
# File 'lib/executor.rb', line 21

def initialize(template, builders)
  @template = template
  @file_path = template.path
  @template_builders = template.builders
  @specified_builders = builders
end

Instance Method Details

#buildObject



47
48
49
50
51
52
# File 'lib/executor.rb', line 47

def build
  puts "Building #{File.basename(@file_path, '.json')}:".to_green
  IO.popen("packer build #{build_options} #{@file_path}") do |cmd|
    cmd.each { |line| puts line }
  end
end

#build_optionsObject

specify the builders if any were passed



43
44
45
# File 'lib/executor.rb', line 43

def build_options
  "-only=#{@specified_builders.join(',')}" unless @specified_builders.empty?
end

#listObject

print out the builders for this template



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/executor.rb', line 29

def list
  puts File.basename(@file_path, '.json') + ':'

  builders = @template.builders_hash
  if builders.empty?
    puts '- No builders found'.indent.to_red
  else
    builders.each_pair do |name, type|
      puts "- #{name} (type: #{type})".indent
    end
  end
end