Class: Jets::Cfn::Builder::Parent::Genesis

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices, Interface, Util::Logging
Defined in:
lib/jets/cfn/builder/parent/genesis.rb

Instance Method Summary collapse

Methods included from Util::Logging

#log

Methods included from Interface

#add_description, #add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_template_resource, #build, #build?, #config, #template, #text, #write

Methods included from Util::Camelize

#camelize

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Constructor Details

#initialize(options) ⇒ Genesis

Returns a new instance of Genesis.



8
9
10
11
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 8

def initialize(options)
  @options = options
  @template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end

Instance Method Details

#cleanObject



40
41
42
43
44
45
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 40

def clean
  return unless clean?
  templates_path = "#{Jets.build_root}/templates"
  logger.debug "Parent Genesis clean #{templates_path}"
  FileUtils.rm_rf(templates_path)
end

#clean?Boolean

interface method: Finale overrides

Returns:

  • (Boolean)


36
37
38
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 36

def clean?
  @options[:bootstrap]
end

#composeObject

interface method



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 14

def compose
  clean
  add_description("Jets: #{Jets::VERSION}")
  add_resource(Jets::Cfn::Resource::S3::JetsBucket.new)

  # codebuild resources
  config = Jets.bootstrap.config # want bootstrap not deploy config here
  add_resource(Jets::Cfn::Resource::Codebuild::IamRole.new)
  unless config.infra
    add_resource(Jets::Cfn::Resource::Codebuild::Project::Ec2.new)
  end
  if config.infra || config.codebuild.lambda.enable
    add_resource(Jets::Cfn::Resource::Codebuild::Project::Lambda.new)
  end
  if config.codebuild.fleet.enable
    add_resource(Jets::Cfn::Resource::Codebuild::Fleet.new)
  end

  merge_existing_template! if @options[:bootstrap]
end

#existing_templateObject



75
76
77
78
79
80
81
82
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 75

def existing_template
  stack_name = Jets::Names.parent_stack_name
  template_body = cfn.get_template(stack_name: stack_name).template_body
  # TODO: vs Jets::Util::Yamler
  Jets::Cfn::Stack::Yamler.load(template_body)
rescue Aws::CloudFormation::Errors::ValidationError => e
  raise unless /does not exist/.match?(e.message)
end

#merge_existing_template!Object

This is how cfn delta updates are achieved.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 60

def merge_existing_template!
  existing = existing_template
  return unless existing

  # Delete resources managed by the bootstrap genesis stack.
  existing["Resources"].delete_if { |k, v| genesis_resources.include?(k) }
  # Note: In case Outputs are all deleted by something else in the future
  # Finale stack does not delete outputs, it filters them.
  # Genesis resource outputs names should match the genesis resource logic id.
  outputs = existing["Outputs"]
  outputs&.delete_if { |k, v| genesis_resources.include?(k) }

  @template.deep_merge!(existing)
end

#template_pathObject

interface method



48
49
50
# File 'lib/jets/cfn/builder/parent/genesis.rb', line 48

def template_path
  Jets::Names.parent_template_path
end