ufo 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f7705c4016b08dd205ad9209ee255b6cd3411fea731183b6c859b28cf900990
4
- data.tar.gz: 4eb918b33c3a87ed71fbc64e3a0dbac8766a02ccbf15d7e35b863a26f7fd78a3
3
+ metadata.gz: d3cfcec77698c26df14d0107993faaa4b6e74d235c269ff66b8750645db8103e
4
+ data.tar.gz: 9c5a5e8be3b5956ef6dabe22c4ddc792ca3edb9573d739821eb74378392e8ec2
5
5
  SHA512:
6
- metadata.gz: c65f585f02f1a54afa5c3c2c0a36378e219b8490eec8321d1dd18f9cec4026108f39e11215d0ec964b1842dbca8ade66d4f7e0b256c41386f86eb0db60f931b2
7
- data.tar.gz: 16226423b75d58394e9e92dcd4562629e9defc5ed46a2acad4e0f049deca9e0c525e2ddaec984eaac616edebe996c1e8e154f3ea3fbb73ae8dfd108bd68958cf
6
+ metadata.gz: e3fb6884204bb2110ac621bb63f6644ff4f60b66b84d9ca5aeaa6023276d629e0e61c43a6bb539051eb594b0c0ca6294a7e78b5e55db2fb7c51f2983c4da6fdb
7
+ data.tar.gz: 80fd898e6c89cb1ba1ebd3aa2f5eadd04f00b12bf6ac234bdaf9eb9b72d0f2e07490400262263aab07bba73e53e7706a8d8bffb5e3d542ab285ec8502f2dd335
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
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.0.1] - 2022-03-05
7
+ - [#126](https://github.com/tongueroo/ufo/pull/126) ecs deployment_configuration options
8
+ - [#127](https://github.com/tongueroo/ufo/pull/127) improve ps errors reporting
9
+
6
10
  ## [6.0.0] - 2022-03-05
7
11
  - [#125](https://github.com/tongueroo/ufo/pull/125) v6: major ufo upgrades and new structure
8
12
 
@@ -14,6 +14,7 @@ class Ufo::Cfn::Stack::Builder::Resources
14
14
  def properties
15
15
  props = {
16
16
  Cluster: @cluster,
17
+ DeploymentConfiguration: deployment_configuration,
17
18
  DesiredCount: {
18
19
  "Fn::If": [
19
20
  "EcsDesiredCountIsBlank",
@@ -68,5 +69,17 @@ class Ufo::Cfn::Stack::Builder::Resources
68
69
 
69
70
  props
70
71
  end
72
+
73
+ private
74
+ def deployment_configuration
75
+ ecs = Ufo.config.ecs
76
+ return ecs.configuration if ecs.configuration # provide user full control
77
+
78
+ # default
79
+ {
80
+ MaximumPercent: ecs.maximum_percent,
81
+ MinimumHealthyPercent: ecs.minimum_healthy_percent,
82
+ }
83
+ end
71
84
  end
72
85
  end
@@ -17,10 +17,10 @@ Confirm to ship:
17
17
 
18
18
  Will deploy stack demo-web-dev (y/N) y
19
19
  Building Docker Image
20
- => docker build -t 536766270177.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0 -f Dockerfile .
21
- Docker Image built: 536766270177.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0
20
+ => docker build -t 111111111111.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0 -f Dockerfile .
21
+ Docker Image built: 111111111111.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0
22
22
  Pushing Docker Image
23
- => docker push 536766270177.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0
23
+ => docker push 111111111111.dkr.ecr.us-west-2.amazonaws.com/demo:ufo-2022-03-02T20-32-33-12dc6e0
24
24
  Task Definition built: .ufo/output/task_definition.json
25
25
  Parameters built: .ufo/output/params.json
26
26
  Template built: .ufo/output/template.yml
data/lib/ufo/cli/logs.rb CHANGED
@@ -16,7 +16,7 @@ class Ufo::CLI
16
16
 
17
17
  def find_log_group_name
18
18
  unless info.service
19
- logger.info "Cannot find ECS service for #{@stack_name}"
19
+ logger.info "Cannot find stack: #{@stack_name}"
20
20
  exit 1
21
21
  end
22
22
  task_definition = info.service.task_definition
@@ -0,0 +1,116 @@
1
+ class Ufo::CLI::Ps
2
+ class Errors < Ufo::CLI::Ps
3
+ def initialize(options={})
4
+ super
5
+ @tasks = options[:tasks]
6
+ end
7
+
8
+ def show
9
+ message = recent_message
10
+ return unless message
11
+ return if message =~ /has reached a steady state/
12
+
13
+ scale
14
+ target_group
15
+ deployment_configuration
16
+ catchall
17
+ end
18
+
19
+ # If running count < desired account for a long time
20
+ # And see was unable to place a task
21
+ # Probably not enough capacity
22
+ def scale
23
+ return if service.running_count >= service.desired_count
24
+
25
+ error_event = recent_events.find do |e|
26
+ e.message =~ /was unable to place a task/
27
+ end
28
+ return unless error_event
29
+
30
+ logger.info "There is an issue scaling the #{@stack_name.color(:green)} service to #{service.desired_count}. Here's the error:"
31
+ logger.info error_event.message.color(:red)
32
+ if service.launch_type == "EC2"
33
+ logger.info <<~EOL
34
+ If AutoScaling is set up for the container instances,
35
+ it can take a little time to add additional instances.
36
+ You'll see this message until the capacity is added.
37
+ EOL
38
+ end
39
+ end
40
+
41
+ # The error currently happens to be the 5th element.
42
+ #
43
+ # Example:
44
+ # (service XXX) (instance i-XXX) (port 32875) is unhealthy in (target-group arn:aws:elasticloadbalancing:us-east-1:111111111111:targetgroup/devel-Targe-1111111111111/1111111111111111) due to (reason Health checks failed with these codes: [400])">]
45
+ def target_group
46
+ error_event = recent_events.find do |e|
47
+ e.message =~ /is unhealthy in/ &&
48
+ e.message =~ /targetgroup/
49
+ end
50
+ return unless error_event
51
+
52
+ logger.error "There are targets in the target group reporting unhealthy. This can cause containers to cycle. Here's the error:"
53
+ logger.error error_event.message.color(:red)
54
+ logger.error <<~EOL
55
+ Check out the ECS console and EC2 Load Balancer console for more info.
56
+ Sometimes they may not helpful :(
57
+ Docs that may help: https://ufoships.com/docs/debug/unhealthy-targets/
58
+ EOL
59
+ end
60
+
61
+ # To reproduce
62
+ #
63
+ # .ufo/config.rb
64
+ #
65
+ # Ufo.configure do |config|
66
+ # config.ecs.maximum_percent = 150 # need at least 200 to go from 1 to 2 containers
67
+ # config.ecs.minimum_healthy_percent = 100
68
+ # end
69
+ #
70
+ # Event message error:
71
+ #
72
+ # ERROR: (service app1-web-dev-EcsService-8FMliG8m6M2p) was unable to stop or start tasks during a deployment because of the service deployment configuration. Update the minimumHealthyPercent or maximumPercent value and try again.
73
+ #
74
+ def deployment_configuration
75
+ message = recent_message
76
+ return unless message.include?("unable") && message.include?("deployment configuration")
77
+
78
+ logger.error "ERROR: Deployment Configuration".color(:red)
79
+ logger.error <<~EOL
80
+ You might have a Deployment Configuration that prevents the deployment from completing.
81
+
82
+ See: https://ufoships.com/docs/debug/deployment-configuration/
83
+
84
+ EOL
85
+ end
86
+
87
+ # Example:
88
+ # (service app1-web-dev-EcsService-8FMliG8m6M2p) was unable to stop or start tasks during a deployment because of the service deployment configuration. Update the minimumHealthyPercent or maximumPercent value and try again.
89
+ def catchall
90
+ message = recent_message
91
+ words = %w[fail unable]
92
+ found = words.detect { |word| message.include?(word) }
93
+ return unless found
94
+ logger.error "ERROR: #{message}".color(:red)
95
+ logger.error <<~EOL
96
+ You might have to cancel the stack with:
97
+
98
+ ufo cancel
99
+
100
+ And try again after fixing the issue.
101
+ EOL
102
+ end
103
+
104
+ private
105
+ # only check a few most recent
106
+ def recent_events
107
+ service["events"][0..4]
108
+ end
109
+
110
+ def recent_message
111
+ recent = recent_events.first
112
+ return unless recent
113
+ recent.message ? recent.message : nil
114
+ end
115
+ end
116
+ end
data/lib/ufo/cli/ps.rb CHANGED
@@ -25,9 +25,9 @@ class Ufo::CLI
25
25
  resp["tasks"]
26
26
  end.flatten
27
27
 
28
- display_tasks(all_task_arns)
29
- display_scale_help
30
- display_target_group_help
28
+ tasks = convert_to_task_objects(all_task_arns)
29
+ show_tasks(tasks)
30
+ show_errors(tasks)
31
31
  end
32
32
 
33
33
  def summary
@@ -63,50 +63,7 @@ class Ufo::CLI
63
63
  resp.scalable_targets.first # scalable_target
64
64
  end
65
65
 
66
- def display_target_group_help
67
- events = service["events"][0..4]
68
- return if events[0].message =~ /has reached a steady state/
69
-
70
- # The error currently happens to be the 5th element.
71
- #
72
- # Example:
73
- # "(service XXX) (instance i-XXX) (port 32875) is unhealthy in (target-group arn:aws:elasticloadbalancing:us-east-1:111111111111:targetgroup/devel-Targe-1111111111111/1111111111111111) due to (reason Health checks failed with these codes: [400])">]
74
- error_event = events.find do |e|
75
- e.message =~ /is unhealthy in/ &&
76
- e.message =~ /targetgroup/
77
- end
78
- return unless error_event
79
-
80
- logger.error "There are targets in the target group reporting unhealthy. This can cause containers to cycle. Here's the error:"
81
- logger.error error_event.message.color(:red)
82
- logger.error <<~EOL
83
- Check out the ECS console and EC2 Load Balancer console for more info.
84
- Sometimes they may not helpful :(
85
- Docs that may help: https://ufoships.com/docs/debug/unhealthy-targets/
86
- EOL
87
- end
88
-
89
- # If the running count less than the desired account yet, check the events
90
- # and show a message with helpful debugging information.
91
- def display_scale_help
92
- return if service.running_count >= service.desired_count
93
-
94
- events = service["events"][0..3] # only check most recent 4 messages
95
- error_event = events.find do |e|
96
- e.message =~ /was unable to place a task/
97
- end
98
- return unless error_event
99
-
100
- logger.info "There is an issue scaling the #{@service.color(:green)} service to #{service.desired_count}. Here's the error:"
101
- logger.info error_event.message.color(:red)
102
- if service.launch_type == "EC2"
103
- logger.info "If AutoScaling is set up for the container instances, it can take a little time to add additional instances. You'll see this message until the capacity is added."
104
- end
105
- end
106
-
107
- def display_tasks(raw_tasks)
108
- raw_tasks.sort_by! { |t| t["task_arn"] }
109
- tasks = raw_tasks.map { |t| Task.new(t) } # will have Task objects after this point
66
+ def show_tasks(tasks)
110
67
  tasks = tasks.reject(&:hide?)
111
68
  show_notes = show_notes(tasks)
112
69
 
@@ -124,6 +81,11 @@ class Ufo::CLI
124
81
  presenter.show
125
82
  end
126
83
 
84
+ def show_errors(tasks)
85
+ Errors.new(@options.merge(tasks: tasks)).show
86
+ end
87
+
88
+ private
127
89
  def show_notes(tasks)
128
90
  tasks.detect { |t| !t.notes.blank? }
129
91
  end
@@ -167,6 +129,11 @@ class Ufo::CLI
167
129
  status == "ALL" ? valid_statuses : [status]
168
130
  end
169
131
 
132
+ def convert_to_task_objects(task_arns)
133
+ task_arns.sort_by! { |t| t["task_arn"] }
134
+ task_arns.map { |t| Task.new(t) } # will have Task objects after this point
135
+ end
136
+
170
137
  def task_arns
171
138
  threads, results = [], {}
172
139
  statuses.each do |status|
data/lib/ufo/cli.rb CHANGED
@@ -85,7 +85,8 @@ module Ufo
85
85
  long_desc Help.text(:ps)
86
86
  option :status, default: "all", desc: "Status filter: all, pending, stopped, running."
87
87
  # not setting format default so we can use Ufo.config.ps.format and dont want to trigger a config load this early
88
- option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
88
+ formats = CliFormat.formats + ["auto"]
89
+ option :format, desc: "Output formats: #{formats.sort.join(', ')}"
89
90
  def ps
90
91
  Ps.new(options).run
91
92
  end
data/lib/ufo/config.rb CHANGED
@@ -49,7 +49,10 @@ module Ufo
49
49
 
50
50
  config.ecs = ActiveSupport::OrderedOptions.new
51
51
  config.ecs.cluster = ":ENV" # => dev
52
+ config.ecs.deployment_configuration = nil # full control
52
53
  config.ecs.desired_count = nil # only respected when config.autoscaling.enabled = false
54
+ config.ecs.maximum_percent = 200 # nil
55
+ config.ecs.minimum_healthy_percent = 100 # nil
53
56
  config.ecs.scheduling_strategy = "REPLICA"
54
57
 
55
58
  config.elb = ActiveSupport::OrderedOptions.new
@@ -65,8 +65,8 @@ module Ufo::TaskDefinition::Helpers
65
65
  end
66
66
  end
67
67
 
68
- # arn:aws:ssm:us-west-2:536766270177:parameter/demo/dev/DB-NAME
69
- # arn:aws:ssm:us-west-2:536766270177:parameter/demo/dev/DB-NAME
68
+ # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
69
+ # arn:aws:ssm:us-west-2:111111111111:parameter/demo/dev/DB-NAME
70
70
  def expansion(arn)
71
71
  # performance improvement only run names.expansion on the name portion
72
72
  md = arn.match(/(.*:)(parameter\/|secret:)(.*)/)
data/lib/ufo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ufo
2
- VERSION = "6.0.0"
2
+ VERSION = "6.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -518,6 +518,7 @@ files:
518
518
  - lib/ufo/cli/new/sequence.rb
519
519
  - lib/ufo/cli/opts.rb
520
520
  - lib/ufo/cli/ps.rb
521
+ - lib/ufo/cli/ps/errors.rb
521
522
  - lib/ufo/cli/ps/task.rb
522
523
  - lib/ufo/cli/releases.rb
523
524
  - lib/ufo/cli/rollback.rb