Class: EcsDeploy::TaskDefinition
- Inherits:
-
Object
- Object
- EcsDeploy::TaskDefinition
- Defined in:
- lib/ecs_deploy/task_definition.rb
Constant Summary collapse
- RETRY_BACKOFF =
lambda do |c| sleep(1) end
- RETRY_LIMIT =
10
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(task_definition_name:, region: nil, network_mode: "bridge", volumes: [], container_definitions: [], placement_constraints: [], task_role_arn: nil, execution_role_arn: nil, requires_compatibilities: nil, cpu: nil, memory: nil, tags: nil) ⇒ TaskDefinition
constructor
A new instance of TaskDefinition.
- #recent_task_definition_arns ⇒ Object
- #register ⇒ Object
Constructor Details
#initialize(task_definition_name:, region: nil, network_mode: "bridge", volumes: [], container_definitions: [], placement_constraints: [], task_role_arn: nil, execution_role_arn: nil, requires_compatibilities: nil, cpu: nil, memory: nil, tags: nil) ⇒ TaskDefinition
Returns a new instance of TaskDefinition.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ecs_deploy/task_definition.rb', line 19 def initialize( task_definition_name:, region: nil, network_mode: "bridge", volumes: [], container_definitions: [], placement_constraints: [], task_role_arn: nil, execution_role_arn: nil, requires_compatibilities: nil, cpu: nil, memory: nil, tags: nil ) @task_definition_name = task_definition_name @task_role_arn = task_role_arn @execution_role_arn = execution_role_arn region ||= EcsDeploy.config.default_region @container_definitions = container_definitions.map do |cd| if cd[:docker_labels] cd[:docker_labels] = cd[:docker_labels].map { |k, v| [k.to_s, v] }.to_h end if cd.dig(:log_configuration, :options) cd[:log_configuration][:options] = cd.dig(:log_configuration, :options).map { |k, v| [k.to_s, v] }.to_h end cd end @volumes = volumes @network_mode = network_mode @placement_constraints = placement_constraints @requires_compatibilities = requires_compatibilities @cpu = cpu&.to_s @memory = memory&.to_s = param = {retry_backoff: RETRY_BACKOFF, retry_limit: RETRY_LIMIT} @client = region ? Aws::ECS::Client.new(param.merge(region: region)) : Aws::ECS::Client.new(param) @region = @client.config.region end |
Class Method Details
.deregister(arn, region: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/ecs_deploy/task_definition.rb', line 9 def self.deregister(arn, region: nil) region ||= EcsDeploy.config.default_region param = {retry_backoff: RETRY_BACKOFF, retry_limit: RETRY_LIMIT} client = region ? Aws::ECS::Client.new(param.merge(region: region)) : Aws::ECS::Client.new(param) client.deregister_task_definition({ task_definition: arn, }) EcsDeploy.logger.info "deregister task definition [#{arn}] [#{client.config.region}] [#{Paint['OK', :green]}]" end |
Instance Method Details
#recent_task_definition_arns ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/ecs_deploy/task_definition.rb', line 54 def recent_task_definition_arns resp = @client.list_task_definitions( family_prefix: @task_definition_name, sort: "DESC" ) resp.task_definition_arns rescue [] end |
#register ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ecs_deploy/task_definition.rb', line 64 def register res = @client.register_task_definition({ family: @task_definition_name, network_mode: @network_mode, container_definitions: @container_definitions, volumes: @volumes, placement_constraints: @placement_constraints, task_role_arn: @task_role_arn, execution_role_arn: @execution_role_arn, requires_compatibilities: @requires_compatibilities, cpu: @cpu, memory: @memory, tags: }) EcsDeploy.logger.info "register task definition [#{@task_definition_name}] [#{@region}] [#{Paint['OK', :green]}]" res.task_definition end |