Class: ECSHelper::TaskDefinitionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_helper/task_definition_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper, service) ⇒ TaskDefinitionHelper

Returns a new instance of TaskDefinitionHelper.



5
6
7
8
# File 'lib/ecs_helper/task_definition_helper.rb', line 5

def initialize(helper, service)
  @helper = helper
  @service = service
end

Instance Attribute Details

#helperObject

Returns the value of attribute helper.



4
5
6
# File 'lib/ecs_helper/task_definition_helper.rb', line 4

def helper
  @helper
end

#new_task_definition_hashObject

Returns the value of attribute new_task_definition_hash.



4
5
6
# File 'lib/ecs_helper/task_definition_helper.rb', line 4

def new_task_definition_hash
  @new_task_definition_hash
end

#repositories=(value) ⇒ Object

Sets the attribute repositories

Parameters:

  • value

    the value to set the attribute repositories to.



4
5
6
# File 'lib/ecs_helper/task_definition_helper.rb', line 4

def repositories=(value)
  @repositories = value
end

#serviceObject

Returns the value of attribute service.



4
5
6
# File 'lib/ecs_helper/task_definition_helper.rb', line 4

def service
  @service
end

#service_task_definitionObject

Returns the value of attribute service_task_definition.



4
5
6
# File 'lib/ecs_helper/task_definition_helper.rb', line 4

def service_task_definition
  @service_task_definition
end

Instance Method Details

#container_definition_to_ecr(cd) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/ecs_helper/task_definition_helper.rb', line 43

def container_definition_to_ecr(cd)
  repo = repo_for(cd)
  is_ecr = cd.image.include?(ecr_base)
  image = repo && version_image(repo)
  should_update = is_ecr && repo && image
  [repo, is_ecr, image, should_update]
end

#container_definitionsObject



14
15
16
# File 'lib/ecs_helper/task_definition_helper.rb', line 14

def container_definitions
  service_task_definition.container_definitions
end

#new_container_definitionsObject



51
52
53
54
55
56
57
# File 'lib/ecs_helper/task_definition_helper.rb', line 51

def new_container_definitions
  container_definitions.map do |cd|
    repo, is_ecr, image, should_be_updated =  container_definition_to_ecr(cd)
    cd.image = "#{repo.repository_uri}:#{version}" if should_be_updated
    cd.to_hash
  end
end

#pretty_container_definitionsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ecs_helper/task_definition_helper.rb', line 18

def pretty_container_definitions
  container_definitions.map do |cd|
    repo, is_ecr, image, should_be_updated =  container_definition_to_ecr(cd)
    [
      cd.name,
      cd.image,
      is_ecr ? "ECR image" : "Not a ECR image",
      repo ? "Repo #{repo.repository_name}" : "Repo not found",
      image ? "Image version #{version}" : "Image version #{version} not found",
      should_be_updated ? "Will be updated" : "Not applicable"
    ].join(' | ')
  end.join("\n")
end

#register_task_definition(hash) ⇒ Object



32
33
34
# File 'lib/ecs_helper/task_definition_helper.rb', line 32

def register_task_definition(hash)
  helper.client.register_task_definition(hash)
end