Sha256: d415fda647708e990fa10825a9e4319997b6b1411022e3149bef68c78c8cbc51

Contents?: true

Size: 1.65 KB

Versions: 11

Compression:

Stored size: 1.65 KB

Contents

require 'plissken' # Hash#to_snake_keys
require 'json'

module Ufo
  class Tasks::Register
    include AwsService

    def self.register(task_name, options={})
      Dir.glob("#{Ufo.root}/.ufo/output/*").each do |path|
        if task_name == :all or path.include?(task_name)
          task_register = Tasks::Register.new(path, options)
          task_register.register
        end
      end
    end

    def initialize(template_definition_path, options={})
      @template_definition_path = template_definition_path
      @options = options
    end

    # aws ecs register-task-definition --cli-input-json file://.ufo/output/hi-web-prod.json
    def register
      data = JSON.parse(IO.read(@template_definition_path), symbolize_names: true)
      data = data.to_snake_keys
      data = fix_log_configuation_option(data)
      message = "#{data[:family]} task definition registered."
      if @options[:noop]
        message = "NOOP: #{message}"
      else
        ecs.register_task_definition(data)
      end
      puts message unless @options[:mute]
    end

    # LogConfiguration requires a string with dashes as the keys
    # https://docs.aws.amazon.com/sdkforruby/api/Aws/ECS/Client.html
    def fix_log_configuation_option(data)
      definitions = data[:container_definitions]
      definitions.each do |definition|
        next unless definition[:log_configuration]
        options = definition[:log_configuration][:options]
        options["awslogs-group"] = options.delete(:awslogs_group)
        options["awslogs-region"] = options.delete(:awslogs_region)
        options["awslogs-stream-prefix"] = options.delete(:awslogs_stream_prefix)
      end
      data
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ufo-3.3.2 lib/ufo/tasks/register.rb
ufo-3.3.1 lib/ufo/tasks/register.rb
ufo-3.3.0 lib/ufo/tasks/register.rb
ufo-3.2.2 lib/ufo/tasks/register.rb
ufo-3.2.1 lib/ufo/tasks/register.rb
ufo-3.2.0 lib/ufo/tasks/register.rb
ufo-3.1.2 lib/ufo/tasks/register.rb
ufo-3.1.1 lib/ufo/tasks/register.rb
ufo-3.1.0 lib/ufo/tasks/register.rb
ufo-3.0.1 lib/ufo/tasks/register.rb
ufo-3.0.0 lib/ufo/tasks/register.rb