Sha256: a74c6c67e52dc2ddfb33cbfbe293e0b5ae476f4e817f39f43cb1d116a449a7ec

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

# Use to automatically create the CloudWatch group.
# For some reason creating ECS does do this by default.
module Ufo
  class LogGroup
    include AwsService

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

    def create
      puts "Ensuring log group for #{@task_definition.colorize(:green)} task definition exists"
      return if @options[:noop]

      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

    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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ufo-4.1.10 lib/ufo/log_group.rb
ufo-4.1.9 lib/ufo/log_group.rb
ufo-4.1.8 lib/ufo/log_group.rb
ufo-4.1.7 lib/ufo/log_group.rb
ufo-4.1.6 lib/ufo/log_group.rb
ufo-4.1.5 lib/ufo/log_group.rb
ufo-4.1.4 lib/ufo/log_group.rb
ufo-4.1.2 lib/ufo/log_group.rb
ufo-4.1.1 lib/ufo/log_group.rb
ufo-4.1.0 lib/ufo/log_group.rb
ufo-4.0.3 lib/ufo/log_group.rb
ufo-4.0.2 lib/ufo/log_group.rb
ufo-4.0.1 lib/ufo/log_group.rb
ufo-4.0.0 lib/ufo/log_group.rb