class Covalence::PackerStackTasks
Attributes
stack[R]
template_path[R]
Public Class Methods
new(stack)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 8 def initialize(stack) @path = File.expand_path(File.join(Covalence::PACKER, stack.module_path)) @stack = stack @template = "#{@path}/#{stack.packer_template}" end
Public Instance Methods
context_build(*additional_args)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 22 def context_build(*additional_args) Dir.mktmpdir do |tmpdir| populate_workspace(tmpdir) Dir.chdir(tmpdir) do logger.info "In #{tmpdir}:" stack.materialize_cmd_inputs(tmpdir) args = collect_args(stack.args, additional_args, "-var-file=covalence-inputs.json") call_packer_cmd("packer_build", args) end end end
context_inspect(*additional_args)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 38 def context_inspect(*additional_args) Dir.mktmpdir do |tmpdir| populate_workspace(tmpdir) Dir.chdir(tmpdir) do logger.info "In #{tmpdir}:" call_packer_cmd("packer_inspect", []) end end end
context_validate(*additional_args)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 49 def context_validate(*additional_args) Dir.mktmpdir do |tmpdir| populate_workspace(tmpdir) Dir.chdir(tmpdir) do logger.info "In #{tmpdir}:" stack.materialize_cmd_inputs(tmpdir) args = collect_args(stack.args, additional_args, "-var-file=covalence-inputs.json") call_packer_cmd("packer_validate", args) end end end
environment_name()
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 18 def environment_name stack.environment_name end
packer_stack_export()
click to toggle source
:reek: TooManyStatements
# File lib/covalence/core/services/packer_stack_tasks.rb, line 66 def packer_stack_export() packer_stack_export_init(File.expand_path(File.join(Covalence::STACK_EXPORT,'packer',stack.full_name))).each do |stackdir| populate_workspace(stackdir) stack.materialize_cmd_inputs(stackdir) logger.info "Exported to #{stackdir}:" end end
stack_name()
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 14 def stack_name stack.name end
Private Instance Methods
call_packer_cmd(packer_cmd, args)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 88 def call_packer_cmd(packer_cmd, args) if template_is_yaml?(@template) config = YAML.load_file(@template).to_json logger.info "\nGenerated build template:\n\n#{config}" File.open('covalence-packer-template.json','w') {|f| f.write(config)} PackerCli.public_send(packer_cmd.to_sym, 'covalence-packer-template.json', args: args) else PackerCli.public_send(packer_cmd.to_sym, @template, args: args) end end
collect_args(*args)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 104 def collect_args(*args) args.flatten.compact.reject(&:empty?).map(&:strip) end
logger()
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 125 def logger Covalence::LOGGER end
packer_stack_export_init(stackdir, dry_run: false, verbose: true)
click to toggle source
:reek: BooleanParameter
# File lib/covalence/core/services/packer_stack_tasks.rb, line 109 def packer_stack_export_init(stackdir, dry_run: false, verbose: true) if(File.exist?(stackdir)) logger.info "Deleting before export: #{stackdir}" FileUtils.rm_rf(stackdir, { noop: dry_run, verbose: verbose, secure: true, }) end logger.info "Creating stack directory: #{stackdir}" FileUtils.mkdir_p(stackdir, { noop: dry_run, verbose: verbose, }) end
populate_workspace(workspace)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 76 def populate_workspace(workspace) # Copy module to the workspace FileUtils.copy_entry @path, workspace # Copy any dependencies to the workspace @stack.dependencies.each do |dep| logger.info "Copying '#{dep}' dependency to #{workspace}" dep_path = File.expand_path(File.join(Covalence::PACKER, dep)) FileUtils.cp_r dep_path, workspace end end
template_is_yaml?(template)
click to toggle source
# File lib/covalence/core/services/packer_stack_tasks.rb, line 100 def template_is_yaml?(template) %w(.yaml .yml).include?(File.extname(template)) end