class Pfm::Command::Base

def build_setup

def build_setup
  Packer::Binary.configure do |config|
    config.version = SETTINGS['PACKER_VERSION']
    config.download_path = "/tmp/#{SecureRandom.uuid}"
  end
  @build_config = Idlc::Build::Config.new(SETTINGS['AWS_REGION'])
  @workspace.add(build_base_dir)
  build_dir = "#{@workspace.tmp_dir}/#{build_base_dir}".freeze
  msg("Using build template: Build::#{@params.first}::#{@config[:build_template]}::#{@config[:build_metadata]}")
  # Include build metadata
  @build_metadata = Idlc::Build::Metadata.new(@params.first, @config[:build_metadata])
  # load the rest of the metadata
  @build_metadata.load
  # load version from command line if specified
  @build_metadata.attributes['version'] = Idlc::Build::Metadata::MetadataAttribute.new(@config[:build_version], true) unless @config[:build_version].nil?
  # check metadata requirements
  @build_metadata.requirements_satisfied?
  msg("Template Version: #{@build_metadata.attributes['version'].value}")
  @build_metadata.attributes.each do |key, att|
    # load metadata file as packer user vars
    @build_config.add_build_var_v2(key, att.value)
  end
  # Copy over the base template and auxillary files for Packer
  tpl = Idlc::Build::Template.new(
    @build_metadata.attributes,
    "#{build_dir}/build.json"
  )
  tpl.write
  # copy auxiliary files
  system("cp -a #{templates_dir}/files #{build_dir}")
  Dir.chdir(build_dir)
end