Class: Ufo::TasksRegister

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AwsServices

#ecr, #ecs, #elb, #region

Constructor Details

#initialize(template_definition_path, options = {}) ⇒ TasksRegister

Returns a new instance of TasksRegister.



18
19
20
21
# File 'lib/ufo/tasks_register.rb', line 18

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

Class Method Details

.register(task_name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ufo/tasks_register.rb', line 8

def self.register(task_name, options={})
  project_root = options[:project_root] || '.'
  Dir.glob("#{project_root}/ufo/output/*").each do |path|
    if task_name == :all or path.include?(task_name)
      task_register = TasksRegister.new(path, options)
      task_register.register
    end
  end
end

Instance Method Details

#fix_log_configuation_option(data) ⇒ Object

LogConfiguration requires a string with dashes as the keys docs.aws.amazon.com/sdkforruby/api/Aws/ECS/Client.html



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ufo/tasks_register.rb', line 39

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

#registerObject

aws ecs register-task-definition –cli-input-json file://ufo/output/hi-web-prod.json



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ufo/tasks_register.rb', line 24

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