AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::RailsProvisioner::Views::FargateStack

Inherits:
Aws::RailsProvisioner::View
  • Object
show all
Defined in:
lib/aws-rails-provisioner/views/fargate_stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FargateStack

Fargate Stack Generation

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :source_path (String)

    relative path from `aws-rails-provisioner.yml` to the directory containing Rails Application source

  • :db_cluster (Hash)

    @see DBCluster

  • :fargate (Hash)

    configurations for fargate service. @see Fargate

  • :scaling (Hash)

    configurations for scaling setting for Fargate service @see Scaling



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 24

def initialize(options = {})
  # code gen only
  @service_name = options[:service_name]
  @path_prefix = options[:path_prefix]
  @stack_prefix = options[:stack_prefix]
  @profile = options[:profile]

  dir = File.dirname(File.expand_path(options[:file_path]))
  @source_path = File.join(dir, options[:source_path])
  @rds_config = options[:db_cluster] || {}
  @fargate_config = options[:fargate] || {}
  @scaling_config = options[:scaling] || {}
end

Instance Attribute Details

#source_pathString (readonly)

Returns:

  • (String)


42
43
44
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 42

def source_path
  @source_path
end

#stack_prefixString (readonly)

Returns:

  • (String)


39
40
41
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 39

def stack_prefix
  @stack_prefix
end

Instance Method Details

#db_clusterObject



73
74
75
76
77
78
79
80
81
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 73

def db_cluster
  if @rds_config && !@rds_config.empty?
    unless @rds_config[:username]
      @rds_config[:username] = "#{stack_prefix}DBAdminUser"
    end
    @rds_config[:profile] = @profile if @profile
    Aws::RailsProvisioner::DBCluster.new(@rds_config)
  end
end

#fargateObject



83
84
85
86
87
88
89
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 83

def fargate
  if @rds_config && !@rds_config.empty?
    @fargate_config[:has_db] = true
  end
  @fargate_config[:service_name] = @stack_prefix
  Aws::RailsProvisioner::Fargate.new(@fargate_config)
end

#packagesObject



68
69
70
71
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 68

def packages
  keys = services.map {|svc| svc[:value] }
  Aws::RailsProvisioner::Utils.to_pkgs(keys)
end

#scalingObject



91
92
93
94
95
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 91

def scaling
  if @scaling_config && !@scaling_config.empty?
    Aws::RailsProvisioner::Scaling.new(@scaling_config)
  end
end

#servicesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/aws-rails-provisioner/views/fargate_stack.rb', line 44

def services
  base = [
    { abbr: 'ec2', value: 'ec2' },
    { abbr: 'ecs', value: 'ecs' },
    { abbr: 'ecs_patterns', value: 'ecs-patterns' },
    { abbr: 'ecr_assets', value: 'ecr-assets' },
    { abbr: 'rds', value: 'rds' }
  ]
  if @fargate_config && @fargate_config[:certificate]
    base << { abbr: 'certificatemanager', value: 'certificatemanager' }
  end
  if @scaling_config &&
    (@scaling_config[:on_metric] || @scaling_config[:on_custom_metric])
    base << { abbr: 'cloudwatch', value: 'cloudwatch' }
  end
  if @rds_config && !@rds_config.empty?
    base << { abbr: 'secretsmanager', value: 'secretsmanager' }
    if @rds_config[:kms_key_arn]
      base << { abbr: 'kms', value: 'kms'}
    end
  end
  base
end