Class: Builderator::Interface::Packer

Inherits:
Builderator::Interface show all
Defined in:
lib/builderator/interface/packer.rb

Overview

Generate packer.json

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Builderator::Interface

berkshelf, #bundled?, #clean, command, #directory, from_gem, packer, #source, template, vagrant, #which, #write

Constructor Details

#initialize(*_) ⇒ Packer



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
# File 'lib/builderator/interface/packer.rb', line 19

def initialize(*_)
  super

  @packerfile ||= {
    :builders => [],
    :provisioners => []
  }.tap do |json|
    Config.profile.current.packer.build.each do |_, build|
      build_hash = build.to_hash.tap do |b|
        b[:tags] = Config.profile.current.tags
      end

      ## Support is missing for several regions in some versions of Packer
      # Moving this functionality into a task until we can confirm that Packer
      # has full support again.
      build_hash.delete(:ami_regions)

      json[:builders] << build_hash
    end

    ## Initialize the staging directory
    json[:provisioners] << {
      :type => 'shell',
      :inline => "sudo mkdir -p #{Config.chef.staging_directory}/cache && "\
                 "sudo chown $(whoami) -R #{Config.chef.staging_directory}"
    }
  end

  _artifact_provisioners
  _chef_provisioner
end

Instance Attribute Details

#packerfileObject (readonly)

Returns the value of attribute packerfile.



17
18
19
# File 'lib/builderator/interface/packer.rb', line 17

def packerfile
  @packerfile
end

Instance Method Details

#renderObject



51
52
53
# File 'lib/builderator/interface/packer.rb', line 51

def render
  JSON.pretty_generate(packerfile)
end