Class: Ufo::LogGroup

Inherits:
Object
  • Object
show all
Includes:
AwsService
Defined in:
lib/ufo/log_group.rb

Instance Method Summary collapse

Methods included from AwsService

#cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb

Constructor Details

#initialize(task_definition, options) ⇒ LogGroup

Returns a new instance of LogGroup.



7
8
9
# File 'lib/ufo/log_group.rb', line 7

def initialize(task_definition, options)
  @task_definition, @options = task_definition, options
end

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ufo/log_group.rb', line 11

def create
  puts "Ensuring log group for #{@task_definition.color(:green)} task definition exists"
  return if @options[:noop]
  return if @options[:rollback] # dont need to create log group because previously deployed

  Ufo.check_task_definition!(@task_definition)
  task_def = JSON.load(IO.read(task_def_path))
  task_def["containerDefinitions"].each do |container_def|
    begin
      log_group_name = container_def["logConfiguration"]["options"]["awslogs-group"]
      puts "Log group name: #{log_group_name}"
    rescue NoMethodError
      # silence when the logConfiguration is not specified
    end

    create_log_group(log_group_name) if log_group_name
  end
end

#create_log_group(log_group_name) ⇒ Object



30
31
32
33
34
# File 'lib/ufo/log_group.rb', line 30

def create_log_group(log_group_name)
  resp = cloudwatchlogs.describe_log_groups(log_group_name_prefix: log_group_name)
  exists = resp.log_groups.find { |lg| lg.log_group_name == log_group_name }
  cloudwatchlogs.create_log_group(log_group_name: log_group_name) unless exists
end

#task_def_pathObject



36
37
38
# File 'lib/ufo/log_group.rb', line 36

def task_def_path
  "#{Ufo.root}/.ufo/output/#{@task_definition}.json"
end