module Stax::Ecs
Public Class Methods
included(thor)
click to toggle source
# File lib/stax/mixin/ecs.rb, line 6 def self.included(thor) thor.desc('ecs COMMAND', 'ECS subcommands') thor.subcommand(:ecs, Cmd::Ecs) end
Public Instance Methods
ecs_cluster_name()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 15 def ecs_cluster_name @_ecs_cluster_name ||= (ecs_clusters&.first&.physical_resource_id || 'default') end
ecs_clusters()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 11 def ecs_clusters @_ecs_clusters ||= Aws::Cfn.resources_by_type(stack_name, 'AWS::ECS::Cluster') end
ecs_deploy(id) { |hash| ... }
click to toggle source
update taskdef for a service, triggering a deploy modify current taskdef in block
# File lib/stax/mixin/ecs/deploy.rb, line 36 def ecs_deploy(id, &block) service = Aws::Ecs.services(ecs_cluster_name, [resource(id)]).first taskdef = get_taskdef(service) ## convert to a hash and modify in block hash = taskdef_to_hash(taskdef) yield(hash) if block_given? taskdef = register_taskdef(hash) update_service(service, taskdef) end
ecs_service_names()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 45 def ecs_service_names @_ecs_service_names ||= ecs_services.map(&:physical_resource_id) end
ecs_service_objects()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 49 def ecs_service_objects Aws::Ecs.services(ecs_cluster_name, ecs_service_names) end
ecs_services()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 19 def ecs_services @_ecs_services ||= Aws::Cfn.resources_by_type(stack_name, 'AWS::ECS::Service') end
ecs_services_with_ids(*ids)
click to toggle source
get services with a list of logical ids
# File lib/stax/mixin/ecs.rb, line 28 def ecs_services_with_ids(*ids) if ids.empty? ecs_services else ecs_services.select do |s| ids.include?(s.logical_resource_id) end end end
ecs_task_definitions()
click to toggle source
# File lib/stax/mixin/ecs.rb, line 23 def ecs_task_definitions @_ecs_task_definitions ||= Aws::Cfn.resources_by_type(stack_name, 'AWS::ECS::TaskDefinition') end
ecs_task_families()
click to toggle source
mangle taskdef arn into family name
# File lib/stax/mixin/ecs.rb, line 39 def ecs_task_families ecs_task_definitions.map do |r| r.physical_resource_id.split(':')[-2].split('/').last end end
ecs_update_service(id, taskdef)
click to toggle source
deprecated: update service to use a new task definition
# File lib/stax/mixin/ecs.rb, line 64 def ecs_update_service(id, taskdef) service_name = resource(id).split('/').last taskdef_name = taskdef.task_definition_arn.split('/').last debug("Updating #{service_name} to #{taskdef_name}") Aws::Ecs.update_service(service: service_name, task_definition: taskdef_name).tap do |s| puts s.task_definition end end
ecs_update_taskdef(id)
click to toggle source
deprecated: register a new revision of existing task definition
# File lib/stax/mixin/ecs.rb, line 54 def ecs_update_taskdef(id) taskdef = Aws::Ecs.task_definition(resource(id)) debug("Registering new revision of #{taskdef.family}") args = %i[family cpu memory requires_compatibilities task_role_arn execution_role_arn network_mode container_definitions volumes placement_constraints] Aws::Ecs.client.register_task_definition(taskdef.to_hash.slice(*args)).task_definition.tap do |t| puts t.task_definition_arn end end
get_taskdef(service)
click to toggle source
# File lib/stax/mixin/ecs/deploy.rb, line 10 def get_taskdef(service) debug("Current task definition for #{service.service_name}") Aws::Ecs.task_definition(service.task_definition).tap do |t| puts t.task_definition_arn end end
register_taskdef(hash)
click to toggle source
# File lib/stax/mixin/ecs/deploy.rb, line 17 def register_taskdef(hash) debug("Registering new revision") Aws::Ecs.client.register_task_definition(hash).task_definition.tap do |t| puts t.task_definition_arn end end
taskdef_to_hash(taskdef)
click to toggle source
convert to hash for registering new taskdef
# File lib/stax/mixin/ecs/deploy.rb, line 5 def taskdef_to_hash(taskdef) args = %i[family cpu memory requires_compatibilities task_role_arn execution_role_arn network_mode container_definitions volumes placement_constraints] taskdef.to_hash.slice(*args) end
update_service(service, taskdef)
click to toggle source
# File lib/stax/mixin/ecs/deploy.rb, line 24 def update_service(service, taskdef) debug("Updating #{service.service_name} to new revision") Aws::Ecs.update_service( service: service.service_name, task_definition: taskdef.task_definition_arn ).tap do |s| puts s.deployments.first.id end end