Class: Ufo::LogGroup

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

Instance Method Summary collapse

Methods included from AwsServices

#cloudwatchlogs, #ecr, #ecs, #elb

Constructor Details

#initialize(task_definition, options) ⇒ LogGroup

Returns a new instance of LogGroup.



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

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

Instance Method Details

#createObject



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

def create
  puts "Ensuring log group for #{@task_definition} exists"
  return if @options[:noop]
  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"]
    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



25
26
27
28
29
# File 'lib/ufo/log_group.rb', line 25

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



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

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