class AwsCftTools::Runbooks::Deploy

Deploy - manage CloudFormation stack deployment

@example

% aws-cft deploy -e QA               # deploy all templates to the QA environment
% aws-cft deploy -e Staging -n -v    # narrate the templates that would be used for Staging
% aws-cft deploy -e Production -c -v # narrate the changes that would go into Production

Public Instance Methods

run() click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 35
def run
  run_reports

  detail 'Updating template parameters...'
  update_parameters

  process_templates(options[:jobs] || 1)
end

Private Instance Methods

deployed_templates() click to toggle source

the set of templates corresponding to deployed CloudFormation stacks

# File lib/aws_cft_tools/runbooks/deploy.rb, line 110
def deployed_templates
  @deployed_templates ||= templates_in_folder_order.select do |template|
    deployed_stack_names.include?(template.name)
  end
end
exec_template(params) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 83
def exec_template(params) # template:, type:
  checking { exec_template_check(**params) }
  doing { exec_template_for_real(**params) }
end
exec_template_check(template:, type:) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 88
def exec_template_check(template:, type:)
  narrate_changes(client.send(:"changes_on_stack_#{type}", template, changeset_set))
rescue Aws::CloudFormation::Errors::ValidationError => error
  puts "Error checking #{template.filename}: #{error.message}"
end
exec_template_for_real(template:, type:) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 94
def exec_template_for_real(template:, type:)
  client.send(:"#{type}_stack", template)
rescue Aws::CloudFormation::Errors::ValidationError => error
  raise AwsCftTools::CloudFormationError, "Error processing #{template.filename}: #{error}"
end
new_templates() click to toggle source

the set of templates with no corresponding deployed CloudFormation stack

# File lib/aws_cft_tools/runbooks/deploy.rb, line 119
def new_templates
  @new_templates ||= templates_in_folder_order - deployed_templates
end
process_slice(templates) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 50
def process_slice(templates)
  jobs = options[:jobs]
  if jobs && jobs > 1
    process_slice_threaded(templates)
  else
    templates.each(&method(:process_template))
  end
end
process_slice_threaded(templates) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 59
def process_slice_threaded(templates)
  original_stdout = $stdout
  $stdout = ThreadedOutput.new(original_stdout)
  template_list = templates.map(&:name).join(', ')
  debug("Creating threads for #{template_list}")
  threads = create_threads(templates, &method(:process_template))
  debug("Waiting on threads for #{template_list}")
  threads.map(&:join)
ensure
  $stdout = original_stdout
end
process_template(template) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 71
def process_template(template)
  ThreadedOutput.prefix = template_name = template.name
  debug("Processing #{template_name}")
  is_update = deployed_templates.include?(template)
  operation("#{is_update ? 'Updating' : 'Creating'}: #{template_name}") do
    exec_template(template: template, type: is_update ? :update : :create)
  end
ensure
  $stdout.flush
  debug("Finished processing #{template_name}")
end
process_templates(slice_size) click to toggle source
# File lib/aws_cft_tools/runbooks/deploy.rb, line 46
def process_templates(slice_size)
  templates_in_folder_order.each_slice(slice_size, &method(:process_slice))
end
update_parameters() click to toggle source

update_parameters - notate templates with region and image id as appropriate

# File lib/aws_cft_tools/runbooks/deploy.rb, line 103
def update_parameters
  templates.each { |template| update_template_with_image_id(template) }
end