Class: EcsDeployer::ScheduledTask::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_deployer/scheduled_task/target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, id, aws_options = {}) ⇒ Target

Returns a new instance of Target.

Parameters:

  • cluster (String)
  • id (String)
  • aws_options (Hash) (defaults to: {})

Raises:



11
12
13
14
15
16
17
18
19
20
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 11

def initialize(cluster, id, aws_options = {})
  ecs = Aws::ECS::Client.new(aws_options)
  clusters = ecs.describe_clusters(clusters: [cluster]).clusters
  raise ClusterNotFoundError, "Cluster does not eixst. [#{cluster}]" if clusters.count.zero?

  @id = id
  @arn = clusters[0].cluster_arn
  @task_count = 1
  @container_overrides = []
end

Instance Attribute Details

#cloudwatch_event_role_arnObject

Returns the value of attribute cloudwatch_event_role_arn.



5
6
7
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5

def cloudwatch_event_role_arn
  @cloudwatch_event_role_arn
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 4

def id
  @id
end

#task_countObject

Returns the value of attribute task_count.



5
6
7
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5

def task_count
  @task_count
end

#task_definition_arnObject

Returns the value of attribute task_definition_arn.



5
6
7
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5

def task_definition_arn
  @task_definition_arn
end

#task_role_arnObject

Returns the value of attribute task_role_arn.



5
6
7
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5

def task_role_arn
  @task_role_arn
end

Instance Method Details

#override_container(name, command = nil, environments = {}) ⇒ Object

Parameters:

  • name (String)
  • command (Array) (defaults to: nil)
  • environments (Hash) (defaults to: {})


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 25

def override_container(name, command = nil, environments = {})
  override_environments = []
  environments.each do |environment|
    environment.each do |env_name, env_value|
      override_environments << {
        name: env_name,
        value: env_value
      }
    end
  end

  container_override = {
    name: name,
    command: command
  }
  container_override[:environment] = override_environments if override_environments.count > 0

  @container_overrides << container_override
end

#to_hashHash

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 46

def to_hash
  {
    id: @id,
    arn: @arn,
    role_arn: @cloudwatch_event_role_arn,
    ecs_parameters: {
      task_definition_arn: @task_definition_arn,
      task_count: @task_count
    },
    input: {
      taskRoleArn: @task_role_arn,
      containerOverrides: @container_overrides
    }.to_json.to_s
  }
end