Class: Ufo::Info

Inherits:
CLI::Base show all
Includes:
AwsServices
Defined in:
lib/ufo/info.rb

Instance Attribute Summary

Attributes inherited from CLI::Base

#task_definition

Instance Method Summary collapse

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from AwsServices::Concerns

#find_stack, #find_stack_resources, #status, #task_definition_arns

Methods inherited from CLI::Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Methods included from Concerns

#build, #deploy, #info, #ps

Methods included from Concerns::Names

#names

Constructor Details

This class inherits a constructor from Ufo::CLI::Base

Instance Method Details

#load_balancer(service) ⇒ Object

Passing in service so method can be used else where.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ufo/info.rb', line 22

def load_balancer(service)
  load_balancer = service.load_balancers.first
  return unless load_balancer

  begin
    resp = elb.describe_target_groups(
      target_group_arns: [load_balancer.target_group_arn]
    )
  rescue Aws::ElasticLoadBalancingV2::Errors::TargetGroupNotFound
    # Super edge case when:
    # 1. deploy with ELB
    # 2. deploy again without ELB
    # 3. ECS service sometimes still thinks there's an ELB
    # Error: https://gist.github.com/tongueroo/dc41f408e65414ab5ee864d0d738d81a
    return
  end
  target_group = resp.target_groups.first
  load_balancer_arn = target_group.load_balancer_arns.first # assume first only
  return unless load_balancer_arn # can occur while stack is being deleted

  resp = elb.describe_load_balancers(load_balancer_arns: [load_balancer_arn])
  resp.load_balancers.first
end

#no_service_messageObject



17
18
19
# File 'lib/ufo/info.rb', line 17

def no_service_message
  "No stack #{@stack_name.color(:green)} found"
end

#runObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ufo/info.rb', line 5

def run
  unless service
    puts no_service_message
    return
  end
  puts "Resources:"
  stack_resources.each do |r|
    puts "#{r.logical_resource_id} - #{r.resource_type}:".color(:green)
    puts "  #{r.physical_resource_id}"
  end
end

#serviceObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/ufo/info.rb', line 47

def service
  return unless stack

  service = stack_resources.find { |r| r.resource_type == "AWS::ECS::Service" }
  return unless service # stack is still creating
  arn = service.physical_resource_id
  return unless arn # can be nil for a few seconds while stack is still creating it
  resp = ecs.describe_services(services: [arn], cluster: @cluster)
  resp.services.first
end

#service?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ufo/info.rb', line 59

def service?
  !!service
end

#stackObject



63
64
65
# File 'lib/ufo/info.rb', line 63

def stack
  find_stack(@stack_name)
end

#stack_resourcesObject



85
86
87
88
# File 'lib/ufo/info.rb', line 85

def stack_resources
  resp = cfn.describe_stack_resources(stack_name: @stack_name)
  resp.stack_resources
end

#urlObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ufo/info.rb', line 68

def url
  return unless stack

  output = stack.outputs.find do |o|
    o.output_key == "Route53Dns"
  end
  dns_name = output.output_value if output
  return unless dns_name

  ssl = stack_resources.find do |r|
    r.logical_resource_id == "ListenerSsl"
  end

  protocol = ssl ? 'https' : 'http'
  "#{protocol}://#{dns_name}"
end