Class: ContainerShip::TaskDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/container_ship/task_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster_name, type, name, environment, build_number) ⇒ TaskDefinition

Returns a new instance of TaskDefinition.



7
8
9
10
11
12
13
# File 'lib/container_ship/task_definition.rb', line 7

def initialize(cluster_name, type, name, environment, build_number)
  @cluster_name = cluster_name
  @type = type
  @name = name
  @environment = environment
  @build_number = build_number
end

Instance Attribute Details

#build_numberObject (readonly)

Returns the value of attribute build_number.



5
6
7
# File 'lib/container_ship/task_definition.rb', line 5

def build_number
  @build_number
end

#cluster_nameObject (readonly)

Returns the value of attribute cluster_name.



5
6
7
# File 'lib/container_ship/task_definition.rb', line 5

def cluster_name
  @cluster_name
end

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'lib/container_ship/task_definition.rb', line 5

def environment
  @environment
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/container_ship/task_definition.rb', line 5

def name
  @name
end

Instance Method Details

#full_cluster_nameObject



27
28
29
# File 'lib/container_ship/task_definition.rb', line 27

def full_cluster_name
  "#{@cluster_name}-#{@environment}"
end

#full_nameObject



31
32
33
# File 'lib/container_ship/task_definition.rb', line 31

def full_name
  "#{@cluster_name}-#{@name}-#{@environment}"
end

#image_nameObject



35
36
37
# File 'lib/container_ship/task_definition.rb', line 35

def image_name
  ENV.fetch('ECR_REPOSITORY') + full_cluster_name
end

#log_group_nameObject



39
40
41
42
43
# File 'lib/container_ship/task_definition.rb', line 39

def log_group_name
  return nil unless main_container_definition.dig(:log_configuration, :log_driver).to_s == 'awslogs'

  main_container_definition.dig(:log_configuration, :options, :'awslogs-group')
end

#log_stream_name(task_arn) ⇒ Object



45
46
47
48
49
50
# File 'lib/container_ship/task_definition.rb', line 45

def log_stream_name(task_arn)
  return nil unless main_container_definition.dig(:log_configuration, :log_driver).to_s == 'awslogs'

  prefix = main_container_definition.dig(:log_configuration, :options, :'awslogs-stream-prefix')
  "#{prefix}/#{full_name}/#{task_arn.split('/').last}"
end

#run_task_optionsObject



52
53
54
55
56
57
58
# File 'lib/container_ship/task_definition.rb', line 52

def run_task_options
  @run_task_options ||= if File.exist?(run_task_options_path)
                          JSON.parse(File.read(run_task_options_path), symbolize_names: true)
                        else
                          {}
                        end
end

#to_hObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/container_ship/task_definition.rb', line 15

def to_h
  task_definition_hash
    .merge(
      family: full_name,
      container_definitions: task_definition_hash[:container_definitions].map do |d|
        next d unless d[:essential]

        d.merge(name: full_name, image: "#{image_name}:#{@build_number}")
      end
    )
end