Class: EcsDeployer::Task::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_deployer/task/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(aws_options = {}) ⇒ EcsDeployer::Task::Client

Parameters:

  • aws_options (Hash) (defaults to: {})


10
11
12
13
# File 'lib/ecs_deployer/task/client.rb', line 10

def initialize(aws_options = {})
  @ecs = Aws::ECS::Client.new(aws_options)
  @cipher = EcsDeployer::Util::Cipher.new(aws_options)
end

Instance Method Details

#register(path, replace_variables = {}) ⇒ Aws::ECS::Types::TaskDefinition

Parameters:

  • path (String)
  • replace_variables (Hash) (defaults to: {})

Returns:

  • (Aws::ECS::Types::TaskDefinition)

Raises:

  • (IOError)


18
19
20
21
22
# File 'lib/ecs_deployer/task/client.rb', line 18

def register(path, replace_variables = {})
  raise IOError, "File does not exist. [#{path}]" unless File.exist?(path)

  register_hash(YAML.load(File.read(path)), replace_variables)
end

#register_clone(cluster, service) ⇒ String

Parameters:

  • cluster (String)
  • service (String)

Returns:

  • (String)

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ecs_deployer/task/client.rb', line 40

def register_clone(cluster, service)
  result = @ecs.describe_services(
    cluster: cluster,
    services: [service]
  )

  result[:services].each do |svc|
    next unless svc[:service_name] == service

    result = @ecs.describe_task_definition(
      task_definition: svc[:task_definition]
    )

    task_definition = result[:task_definition].to_hash

    delete_keys = [:task_definition_arn, :revision, :status, :requires_attributes, :compatibilities]
    delete_keys.each do |delete_key|
      task_definition.delete(delete_key)
    end

    return register_hash(task_definition)
  end

  raise ServiceNotFoundError, "'#{service}' service is not found."
end

#register_hash(task_definition, replace_variables = {}) ⇒ Aws::ECS::Types::TaskDefinition

Parameters:

  • task_definition (Hash)
  • replace_variables (Hash) (defaults to: {})

Returns:

  • (Aws::ECS::Types::TaskDefinition)


27
28
29
30
31
32
33
34
35
# File 'lib/ecs_deployer/task/client.rb', line 27

def register_hash(task_definition, replace_variables = {})
  task_definition = Oj.load(Oj.dump(task_definition), symbol_keys: true)

  replace_parameter_variables!(task_definition, replace_variables)
  decrypt_environment_variables!(task_definition)

  result = @ecs.register_task_definition(task_definition)
  result[:task_definition]
end