Class: EcsDeployer::ScheduledTask::Target
- Inherits:
-
Object
- Object
- EcsDeployer::ScheduledTask::Target
- Defined in:
- lib/ecs_deployer/scheduled_task/target.rb
Constant Summary collapse
- TARGET_ROLE =
'ecsEventsRole'.freeze
Instance Attribute Summary collapse
-
#arn ⇒ Object
Returns the value of attribute arn.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#role_arn ⇒ Object
Returns the value of attribute role_arn.
-
#task_count ⇒ Object
Returns the value of attribute task_count.
-
#task_definition_arn ⇒ Object
Returns the value of attribute task_definition_arn.
-
#task_role_arn ⇒ Object
Returns the value of attribute task_role_arn.
Instance Method Summary collapse
-
#initialize(cluster, id, aws_options = {}) ⇒ Target
constructor
A new instance of Target.
- #override_container(name, command = nil, environments = {}) ⇒ Object
- #role(role) ⇒ Object
- #task_role(task_role) ⇒ Object
- #to_hash ⇒ Hash
Constructor Details
#initialize(cluster, id, aws_options = {}) ⇒ Target
Returns a new instance of Target.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 13 def initialize(cluster, id, = {}) ecs = Aws::ECS::Client.new() 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 = [] role(TARGET_ROLE) end |
Instance Attribute Details
#arn ⇒ Object
Returns the value of attribute arn.
5 6 7 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5 def arn @arn end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 4 def id @id end |
#role_arn ⇒ Object
Returns the value of attribute role_arn.
5 6 7 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 5 def role_arn @role_arn end |
#task_count ⇒ Object
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_arn ⇒ Object
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_arn ⇒ Object
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 37 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 |
#role(role) ⇒ Object
26 27 28 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 26 def role(role) @role_arn = Aws::IAM::Role.new(role, @aws_options).arn end |
#task_role(task_role) ⇒ Object
30 31 32 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 30 def task_role(task_role) @task_role_arn = Aws::IAM::Role.new(task_role, @aws_options).arn end |
#to_hash ⇒ Hash
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ecs_deployer/scheduled_task/target.rb', line 58 def to_hash { id: @id, arn: @arn, role_arn: @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 |