class EcsSolo::Deploy
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
EcsSolo::AbstractBase::new
# File lib/ecs_solo/deploy.rb, line 3 def initialize(options={}) super @identifier = options[:identifier] # ECS Service or CloudFormation Stack @cluster = options[:cluster] @command = options[:command] end
Public Instance Methods
cloudformation_ecs_service_arn(stack_name)
click to toggle source
# File lib/ecs_solo/deploy.rb, line 48 def cloudformation_ecs_service_arn(stack_name) resp = cloudformation.describe_stack_resources(stack_name: stack_name) resource = resp.stack_resources.find { |r| r.resource_type == "AWS::ECS::Service" } resource.physical_resource_id # IE: arn:aws:ecs:us-west-2:112233445566:service/development/demo-web-development-Ecs-179L598PRC44 rescue Aws::CloudFormation::Errors::ValidationError => e if e.message.include?("does not exist") return else raise(e) end end
ecs_service(service)
click to toggle source
# File lib/ecs_solo/deploy.rb, line 60 def ecs_service(service) begin resp = ecs.describe_services(services: [service], cluster: @cluster) rescue Aws::ECS::Errors::ClusterNotFoundException => e puts "#{e.class}: #{e.message}" puts "WARN: #{@cluster.color(:green)} not found." return end resp.services.first end
find_service()
click to toggle source
# File lib/ecs_solo/deploy.rb, line 37 def find_service ecs_service_arn = cloudformation_ecs_service_arn(@identifier) if ecs_service_arn # IE: arn:aws:ecs:us-west-2:112233445566:service/development/demo-web-development-Ecs-179L598PRC44 @cluster = ecs_service_arn.split('/')[1] # override @cluster ecs_service(ecs_service_arn) else ecs_service(@identifier) end end
find_task_definition()
click to toggle source
# File lib/ecs_solo/deploy.rb, line 26 def find_task_definition puts "Finding Docker image associated with #{@identifier}" service = find_service return unless service task_definition = service.task_definition resp = ecs.describe_task_definition(task_definition: task_definition) puts "Found task definition with Docker image" resp.task_definition end
run()
click to toggle source
# File lib/ecs_solo/deploy.rb, line 10 def run if @options[:noop] puts "NOOP: Will find task definition associated with #{@identifier.color(:green)} in the cluster #{@cluster.color(:green)}" return end task_definition = find_task_definition unless task_definition puts "Unable to task definition associated with #{@identifier.color(:green)} in the cluster #{@cluster.color(:green)}" exit 1 end @docker = Docker.new(@options.merge(task_definition: task_definition)) @docker.execute end
Private Instance Methods
docker()
click to toggle source
# File lib/ecs_solo/deploy.rb, line 73 def docker Docker.new end