ufo 6.3.3 → 6.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b97f721b8915f665745b998087e612bb4bae0cc7f2a4046a9efe8492e2eac0c
4
- data.tar.gz: b093ecdafedad9522784798d331256112efdcfabce099c97b980d03a7ddc4e09
3
+ metadata.gz: c98f420b247f0c49a22f00a8f700ac37b89c610a32a32d6368532411dd93dc13
4
+ data.tar.gz: 4e2413294c3541dcfe6f207136fd2f466b3d723603d58bc97830f9aec2753a19
5
5
  SHA512:
6
- metadata.gz: 787c7cb0f1818a34bdba0e4a075ca428cefc53b5c51fde23deda1fdd180eb12a845af279d6793743dd867ca7be68122366d104d7a56b6c94ed1742f3c7938a2b
7
- data.tar.gz: 1e1a58d83901bf2218faad41263e51095022b1db1fc138cad9502b9c49da08131490b8d649b22e07027cae2ba61782d5a3c1bddc14789675e537b2b2254e6e71
6
+ metadata.gz: f0d8d600619c3b76738d0d1d909f4158904ea2483257755342e8b2121f9b6d96ae6cbfddaa2774e9ad67a258ebfd18ddd2cc0ea54f7be297de9f6c2635ba3bae
7
+ data.tar.gz: 6f187d51020fd603d6b664763ff2930d6e1c0d883369acfa51d76d879c53cac87be348f14655ac92fc1ce9a5775a0c92298e04f6fda64c185b78ea29e5520e93
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [6.3.4] - 2022-04-27
7
+ - [#168](https://github.com/tongueroo/ufo/pull/168) ufo ps: show multiple container names
8
+ - [#169](https://github.com/tongueroo/ufo/pull/169) ufo logs improvements
9
+ - [#170](https://github.com/tongueroo/ufo/pull/170) infer ecs managed sg based on awsvpc network mode
10
+
6
11
  ## [6.3.3] - 2022-03-27
7
12
  - [#167](https://github.com/tongueroo/ufo/pull/167) fix edge case include_dir for ruby 2.7
8
13
  - remove update_dockerignore
@@ -18,22 +18,23 @@ class Ufo::Cfn::Stack::Builder
18
18
  def security_groups(type)
19
19
  group_ids = Ufo.config.vpc.security_groups[type] || []
20
20
  # no security groups at all
21
- return if !managed_security_groups? && group_ids.blank?
21
+ return if type == :ecs && !manage_ecs_security_group? && group_ids.blank?
22
22
 
23
23
  groups = []
24
24
  groups += group_ids
25
- groups += [managed_security_group(type.to_s.camelize)] if managed_security_groups?
25
+ groups += [managed_security_group(type)] if manage_ecs_security_group? || type == :elb
26
26
  groups
27
27
  end
28
28
 
29
29
  def managed_security_group(type)
30
- logical_id = managed_security_groups? ? "#{type.camelize}SecurityGroup" : "AWS::NoValue"
30
+ logical_id = type == :elb || manage_ecs_security_group? ? "#{type.to_s.camelize}SecurityGroup" : "AWS::NoValue"
31
31
  {Ref: logical_id}
32
32
  end
33
33
 
34
- def managed_security_groups?
35
- managed = Ufo.config.vpc.security_groups.managed
36
- managed.nil? ? true : managed
34
+ # With network mode is awsvpc always create UFO managed ECS security group
35
+ # With bridge mode, never create as there's no point.
36
+ def manage_ecs_security_group?
37
+ vars[:container][:network_mode].to_s == 'awsvpc'
37
38
  end
38
39
 
39
40
  def self.build(options={})
@@ -1,7 +1,8 @@
1
1
  module Ufo::Cfn::Stack::Builder::Resources::SecurityGroup
2
2
  class Ecs < Base
3
3
  def build
4
- return unless managed_security_groups?
4
+ return unless manage_ecs_security_group?
5
+ return unless vars[:container][:network_mode].to_s == 'awsvpc'
5
6
 
6
7
  {
7
8
  Type: "AWS::EC2::SecurityGroup",
@@ -1,8 +1,7 @@
1
1
  module Ufo::Cfn::Stack::Builder::Resources::SecurityGroup
2
2
  class EcsRule < Base
3
3
  def build
4
- return unless managed_security_groups?
5
- return unless vars[:elb_type] == "application"
4
+ return unless manage_ecs_security_group?
6
5
 
7
6
  {
8
7
  Type: "AWS::EC2::SecurityGroupIngress",
@@ -1,7 +1,7 @@
1
1
  module Ufo::Cfn::Stack::Builder::Resources::SecurityGroup
2
2
  class Elb < Base
3
3
  def build
4
- return unless managed_security_groups?
4
+ # Always create elb security group it seems like its required
5
5
  return unless vars[:elb_type] == "application"
6
6
 
7
7
  {
data/lib/ufo/cli/logs.rb CHANGED
@@ -6,11 +6,11 @@ class Ufo::CLI
6
6
 
7
7
  def run
8
8
  log = find_log_group_name
9
- puts "Showing logs for stack: #{@stack_name} log group: #{log["awslogs-group"]} and stream prefix: #{log["awslogs-stream-prefix"]}"
9
+ logger.info "Showing logs for stack: #{@stack_name} log group: #{log["awslogs-group"]} and stream prefix: #{log["awslogs-stream-prefix"]}"
10
10
  if log
11
11
  cloudwatch_tail(log)
12
12
  else
13
- puts "Unable to find log group for service: #{service.service_name}"
13
+ logger.info "Unable to find log group for service: #{service.service_name}"
14
14
  end
15
15
  end
16
16
 
@@ -24,22 +24,40 @@ class Ufo::CLI
24
24
 
25
25
  container_definitions = resp.task_definition.container_definitions
26
26
 
27
- unless container_definitions.size == 1
28
- puts "ERROR: ufo logs command only supports 1 container definition in the ECS task definition".color(:red)
29
- return
27
+ if container_definitions.size > 1 && !@options[:container]
28
+ logger.info "Multiple containers found. ufo logs will use the first container."
29
+ logger.info "You can also use the --container option to set the container to use."
30
+ end
31
+
32
+ definition = if @options[:container]
33
+ container_definitions.find do |c|
34
+ c.name == @options[:container]
35
+ end
36
+ else
37
+ container_definitions.first
38
+ end
39
+
40
+ unless definition
41
+ logger.error "ERROR: unable to find a container".color(:red)
42
+ logger.error "You specified --container #{@options[:container]}" if @options[:container]
43
+ exit
30
44
  end
31
45
 
32
- definition = container_definitions.first
33
46
  log_conf = definition.log_configuration
47
+ unless log_conf
48
+ logger.error "ERROR: Unable to find a log_configuration for container: #{definition.name}".color(:red)
49
+ logger.error "You specified --container #{@options[:container]}" if @options[:container]
50
+ exit 1
51
+ end
34
52
 
35
- if log_conf && log_conf.log_driver == "awslogs"
53
+ if log_conf.log_driver == "awslogs"
36
54
  # options["awslogs-group"]
37
55
  # options["awslogs-region"]
38
56
  # options["awslogs-stream-prefix"]
39
57
  log_conf.options
40
58
  else
41
- puts "Only supports awslogs driver. Detected log_driver: #{log_conf.log_driver}"
42
- return
59
+ logger.error "ERROR: Only supports awslogs driver. Detected log_driver: #{log_conf.log_driver}".color(:red)
60
+ exit 1 unless ENV['UFO_TEST']
43
61
  end
44
62
  end
45
63
 
@@ -16,12 +16,36 @@ class Ufo::CLI::Ps
16
16
 
17
17
  def name
18
18
  container_overrides = @task.dig("overrides", "container_overrides")
19
- overrides = container_overrides.first # assume first is one we want
20
- overrides["name"] if overrides # PENDING wont yet have info
19
+ overrides = container_overrides # assume first is one we want
20
+ if !overrides.empty? # PENDING wont yet have info
21
+ overrides.map { |i| i["name"] }.join(',')
22
+ else
23
+ container_names
24
+ end
21
25
  rescue NoMethodError
22
- container = @task["containers"].first
23
- container["name"] if container # PENDING wont yet have info
26
+ container_names
27
+ end
28
+
29
+ # PENDING wont yet have any containers yet but since using task definition we're ok
30
+ def container_names
31
+ task_definition = task_definition(@task.task_definition_arn)
32
+ names = task_definition.container_definitions.map do |container_definition|
33
+ container_definition.name
34
+ end
35
+ names.join(',')
36
+ end
37
+
38
+ # ECS inconsistently returns the container names in random order
39
+ # Look up the names from the task definition to try and get right order
40
+ # This still seems to return inconsistently.
41
+ # IE: Not the order that was defined in the task definition originally
42
+ def task_definition(task_definition_arn)
43
+ resp = ecs.describe_task_definition(
44
+ task_definition: task_definition_arn,
45
+ )
46
+ resp.task_definition
24
47
  end
48
+ memoize :task_definition
25
49
 
26
50
  def container_instance_arn
27
51
  @task['container_instance_arn'].split('/').last
data/lib/ufo/cli.rb CHANGED
@@ -64,6 +64,7 @@ module Ufo
64
64
  option :since, desc: "From what time to begin displaying logs. By default, logs will be displayed starting from 1 minutes in the past. The value provided can be an ISO 8601 timestamp or a relative time."
65
65
  option :format, default: "short", desc: "The format to display the logs. IE: detailed or short. With detailed, the log stream name is also shown."
66
66
  option :filter_pattern, desc: "The filter pattern to use. If not provided, all the events are matched"
67
+ option :container, aliases: :c, desc: "Container name to show logs for. Only needed when ECS task multiple containers"
67
68
  def logs
68
69
  Logs.new(options).run
69
70
  end
data/lib/ufo/config.rb CHANGED
@@ -138,7 +138,6 @@ module Ufo
138
138
  config.vpc.security_groups = ActiveSupport::OrderedOptions.new
139
139
  config.vpc.security_groups.ecs = nil
140
140
  config.vpc.security_groups.elb = nil
141
- config.vpc.security_groups.managed = true
142
141
  config.vpc.subnets = ActiveSupport::OrderedOptions.new
143
142
  config.vpc.subnets.ecs = nil
144
143
  config.vpc.subnets.elb = nil
data/lib/ufo/info.rb CHANGED
@@ -23,9 +23,18 @@ module Ufo
23
23
  load_balancer = service.load_balancers.first
24
24
  return unless load_balancer
25
25
 
26
- resp = elb.describe_target_groups(
27
- target_group_arns: [load_balancer.target_group_arn]
28
- )
26
+ begin
27
+ resp = elb.describe_target_groups(
28
+ target_group_arns: [load_balancer.target_group_arn]
29
+ )
30
+ rescue Aws::ElasticLoadBalancingV2::Errors::TargetGroupNotFound
31
+ # Super edge case when:
32
+ # 1. deploy with ELB
33
+ # 2. deploy again without ELB
34
+ # 3. ECS service sometimes still thinks there's an ELB
35
+ # Error: https://gist.github.com/tongueroo/dc41f408e65414ab5ee864d0d738d81a
36
+ return
37
+ end
29
38
  target_group = resp.target_groups.first
30
39
  load_balancer_arn = target_group.load_balancer_arns.first # assume first only
31
40
  return unless load_balancer_arn # can occur while stack is being deleted
data/lib/ufo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ufo
2
- VERSION = "6.3.3"
2
+ VERSION = "6.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.3
4
+ version: 6.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-27 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-logs
@@ -716,7 +716,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
716
716
  - !ruby/object:Gem::Version
717
717
  version: '0'
718
718
  requirements: []
719
- rubygems_version: 3.3.10
719
+ rubygems_version: 3.3.12
720
720
  signing_key:
721
721
  specification_version: 4
722
722
  summary: AWS ECS Deploy Tool