Skip to content

Commit ee758d9

Browse files
committed
Only use barrier when needed, more descriptive info
1 parent bb2ca81 commit ee758d9

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

lib/kamal/cli/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def boot
1515
end
1616

1717
#  Primary hosts and roles are returned first, so they can open the barrier
18-
barrier = Kamal::Cli::Healthcheck::Barrier.new
18+
barrier = Kamal::Cli::Healthcheck::Barrier.new if KAMAL.roles.many?
1919

2020
on(KAMAL.hosts, **KAMAL.boot_strategy) do |host|
2121
KAMAL.roles_on(host).each do |role|

lib/kamal/cli/app/boot.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def start_new_version
4343

4444
reach_barrier
4545
rescue => e
46-
if barrier_role? && barrier.close
47-
info "Deploy failed, so closed barrier (#{host})"
46+
if barrier_role? && barrier&.close
47+
info "First #{KAMAL.primary_role} container unhealthy, stopping other roles (#{host})"
4848
error capture_with_info(*app.logs(version: version))
4949
error capture_with_info(*app.container_health_log(version: version))
5050
end
@@ -71,7 +71,7 @@ def reach_barrier
7171
if barrier
7272
if barrier_role?
7373
if barrier.open
74-
info "Opened barrier (#{host})"
74+
info "First #{KAMAL.primary_role} container healthy, continuing other roles (#{host})"
7575
end
7676
else
7777
wait_for_barrier
@@ -80,11 +80,11 @@ def reach_barrier
8080
end
8181

8282
def wait_for_barrier
83-
info "Waiting at web barrier (#{host})..."
83+
info "Waiting for a healthy #{KAMAL.primary_role} container (#{host})..."
8484
barrier.wait
85-
info "Barrier opened (#{host})"
85+
info "First #{KAMAL.primary_role} container is healthy, continuing (#{host})"
8686
rescue Kamal::Cli::Healthcheck::Error
87-
info "Barrier closed, shutting down new container (#{host})..."
87+
info "First #{KAMAL.primary_role} container is unhealthy, stopping (#{host})"
8888
raise
8989
end
9090

test/cli/app_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ 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 at web barrier (1.1.1.3)...", output
140-
assert_match "Waiting at web barrier (1.1.1.4)...", output
141-
assert_match "Barrier opened (1.1.1.3)", output
142-
assert_match "Barrier opened (1.1.1.4)", 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
143143
end
144144
end
145145

@@ -160,10 +160,10 @@ class CliAppTest < CliTestCase
160160

161161
stderred do
162162
run_command("boot", config: :with_roles, host: nil, allow_execute_error: true).tap do |output|
163-
assert_match "Waiting at web barrier (1.1.1.3)...", output
164-
assert_match "Waiting at web barrier (1.1.1.4)...", output
165-
assert_match "Barrier closed, shutting down new container (1.1.1.3)...", output
166-
assert_match "Barrier closed, shutting down new container (1.1.1.4)...", output
163+
assert_match "Waiting for a healthy web container (1.1.1.3)...", output
164+
assert_match "Waiting for a healthy web container (1.1.1.4)...", output
165+
assert_match "First web container is unhealthy, stopping (1.1.1.3)", output
166+
assert_match "First web container is unhealthy, stopping (1.1.1.4)", output
167167
assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.1", output
168168
assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.2", output
169169
assert_match "Running docker container ls --all --filter name=^app-workers-latest$ --quiet | xargs docker stop on 1.1.1.3", output

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 at web barrier (vm3)...", output
29-
assert_match /Deploy failed, so closed barrier \(vm[12]\)/, output
30-
assert_match "Barrier closed, shutting down new container (vm3)...", 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
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)