Skip to content

Commit 706b82b

Browse files
committed
Simplify messages and remove multiple execute error
1 parent fa7e941 commit 706b82b

File tree

6 files changed

+32
-47
lines changed

6 files changed

+32
-47
lines changed

bin/kamal

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ require "kamal"
77

88
begin
99
Kamal::Cli::Main.start(ARGV)
10-
rescue SSHKit::Runner::MultipleExecuteError => e
11-
e.execute_errors.each do |execute_error|
12-
puts " \e[31mERROR (#{execute_error.cause.class}): #{execute_error.message}\e[0m"
13-
end
14-
if ENV["VERBOSE"]
15-
puts "Backtrace for the first error:"
16-
puts e.execute_errors.first.cause.backtrace
17-
end
18-
exit 1
1910
rescue SSHKit::Runner::ExecuteError => e
2011
puts " \e[31mERROR (#{e.cause.class}): #{e.message}\e[0m"
2112
puts e.cause.backtrace if ENV["VERBOSE"]

lib/kamal/cli/app/boot.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ def initialize(host, role, sshkit, version, barrier)
1414
def run
1515
old_version = old_version_renamed_if_clashing
1616

17-
start_new_version
17+
wait_at_barrier if queuer?
18+
19+
begin
20+
start_new_version
21+
rescue => e
22+
close_barrier if gatekeeper?
23+
stop_new_version
24+
raise
25+
end
26+
27+
release_barrier if gatekeeper?
1828

1929
if old_version
2030
stop_old_version(old_version)
@@ -34,22 +44,16 @@ def old_version_renamed_if_clashing
3444
end
3545

3646
def start_new_version
37-
wait_at_barrier if queuer?
38-
3947
audit "Booted app version #{version}"
4048

4149
execute *app.tie_cord(role.cord_host_file) if uses_cord?
4250
hostname = "#{host.to_s[0...51].gsub(/\.+$/, '')}-#{SecureRandom.hex(6)}"
4351
execute *app.run(hostname: hostname)
4452
Kamal::Cli::Healthcheck::Poller.wait_for_healthy(pause_after_ready: true) { capture_with_info(*app.status(version: version)) }
53+
end
4554

46-
release_barrier if gatekeeper?
47-
rescue => e
48-
close_barrier if gatekeeper?
49-
55+
def stop_new_version
5056
execute *app.stop(version: version), raise_on_non_zero_exit: false
51-
52-
raise
5357
end
5458

5559
def stop_old_version(version)
@@ -68,22 +72,22 @@ def stop_old_version(version)
6872

6973
def release_barrier
7074
if barrier.open
71-
info "First #{KAMAL.primary_role} container healthy, continuing other roles (#{host})"
75+
info "First #{KAMAL.primary_role} container is healthy on #{host}, booting other roles"
7276
end
7377
end
7478

7579
def wait_at_barrier
76-
info "Waiting for a healthy #{KAMAL.primary_role} container (#{host})..."
80+
info "Waiting for the first healthy #{KAMAL.primary_role} container before booting #{role} on #{host}..."
7781
barrier.wait
78-
info "First #{KAMAL.primary_role} container is healthy, continuing (#{host})"
82+
info "First #{KAMAL.primary_role} container is healthy, booting #{role} on #{host}..."
7983
rescue Kamal::Cli::Healthcheck::Error
80-
info "First #{KAMAL.primary_role} container is unhealthy, stopping (#{host})"
84+
info "First #{KAMAL.primary_role} container is unhealthy, not booting #{role} on #{host}"
8185
raise
8286
end
8387

8488
def close_barrier
8589
if barrier.close
86-
info "First #{KAMAL.primary_role} container unhealthy, stopping other roles (#{host})"
90+
info "First #{KAMAL.primary_role} container is unhealthy on #{host}, not booting other roles"
8791
error capture_with_info(*app.logs(version: version))
8892
error capture_with_info(*app.container_health_log(version: version))
8993
end

lib/kamal/cli/main.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def container_available?(version)
244244
raise "Container not found" unless container_id.present?
245245
end
246246
end
247-
rescue SSHKit::Runner::ExecuteError => e
247+
rescue SSHKit::Runner::ExecuteError, SSHKit::Runner::MultipleExecuteError => e
248248
if e.message =~ /Container not found/
249249
say "Error looking for container version #{version}: #{e.message}"
250250
return false

lib/kamal/sshkit_with_ext.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ def start_with_concurrency_limit(*args)
104104
prepend LimitConcurrentStartsInstance
105105
end
106106

107-
class SSHKit::Runner::MultipleExecuteError < SSHKit::StandardError
108-
attr_reader :execute_errors
109-
110-
def initialize(execute_errors)
111-
@execute_errors = execute_errors
112-
end
113-
end
114-
115107
class SSHKit::Runner::Parallel
116108
# SSHKit joins the threads in sequence and fails on the first error it encounters, which means that we wait threads
117109
# before the first failure to complete but not for ones after.
@@ -140,7 +132,7 @@ def execute
140132
if exceptions.one?
141133
raise exceptions.first
142134
elsif exceptions.many?
143-
raise SSHKit::Runner::MultipleExecuteError.new(exceptions)
135+
raise exceptions.first, [ "Exceptions on #{exceptions.count} hosts:", exceptions.map(&:message) ].join("\n")
144136
end
145137
end
146138
end

test/cli/app_test.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ class CliAppTest < CliTestCase
136136
.returns("running").at_least_once # workers health check
137137

138138
run_command("boot", config: :with_roles, host: nil).tap do |output|
139-
assert_match "Waiting for a healthy web container (1.1.1.3)...", output
140-
assert_match "Waiting for a healthy web container (1.1.1.4)...", output
141-
assert_match "First web container is healthy, continuing (1.1.1.3)", output
142-
assert_match "First web container is healthy, continuing (1.1.1.4)", output
143-
end
139+
assert_match "Waiting for the first healthy web container before booting workers on 1.1.1.3...", output
140+
assert_match "Waiting for the first healthy web container before booting workers on 1.1.1.4...", output
141+
assert_match "First web container is healthy, booting workers on 1.1.1.3", output
142+
assert_match "First web container is healthy, booting workers on 1.1.1.4", output
143+
end
144144
end
145145

146146
test "boot with web barrier closed" do
@@ -156,14 +156,12 @@ class CliAppTest < CliTestCase
156156

157157
stderred do
158158
run_command("boot", config: :with_roles, host: nil, allow_execute_error: true).tap do |output|
159-
assert_match "Waiting for a healthy web container (1.1.1.3)...", output
160-
assert_match "Waiting for a healthy web container (1.1.1.4)...", output
161-
assert_match "First web container is unhealthy, stopping (1.1.1.3)", output
162-
assert_match "First web container is unhealthy, stopping (1.1.1.4)", output
159+
assert_match "Waiting for the first healthy web container before booting workers on 1.1.1.3...", output
160+
assert_match "Waiting for the first healthy web container before booting workers on 1.1.1.4...", output
161+
assert_match "First web container is unhealthy, not booting workers on 1.1.1.3", output
162+
assert_match "First web container is unhealthy, not booting workers on 1.1.1.4", output
163163
assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.1", output
164164
assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.2", output
165-
assert_match "Running docker container ls --all --filter name=^app-workers-latest$ --quiet | xargs docker stop on 1.1.1.3", output
166-
assert_match "Running docker container ls --all --filter name=^app-workers-latest$ --quiet | xargs docker stop on 1.1.1.4", output
167165
end
168166
end
169167
ensure

test/integration/broken_deploy_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class BrokenDeployTest < IntegrationTest
2525

2626
private
2727
def assert_failed_deploy(output)
28-
assert_match "Waiting for a healthy web container (vm3)...", output
29-
assert_match /First #{KAMAL.primary_role} container is unhealthy, stopping \(vm[12]\)/, output
30-
assert_match "First #{KAMAL.primary_role} container unhealthy, stopping other roles (vm3)...", output
28+
assert_match "Waiting for the first healthy web container before booting workers on vm3...", output
29+
assert_match /First web container is unhealthy on vm[12], not booting other roles/, output
30+
assert_match "First web container is unhealthy, not booting workers on vm3", output
3131
assert_match "nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /etc/nginx/conf.d/default.conf:2", output
3232
assert_match 'ERROR {"Status":"unhealthy","FailingStreak":0,"Log":[]}', output
3333
end

0 commit comments

Comments
 (0)