From ee758d951af5c513a9b1b272dc39393a048936cd Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Mon, 20 May 2024 12:17:01 +0100 Subject: [PATCH] Only use barrier when needed, more descriptive info --- lib/kamal/cli/app.rb | 2 +- lib/kamal/cli/app/boot.rb | 12 ++++++------ test/cli/app_test.rb | 16 ++++++++-------- test/integration/broken_deploy_test.rb | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb index 356b09f8..14cf54ad 100644 --- a/lib/kamal/cli/app.rb +++ b/lib/kamal/cli/app.rb @@ -15,7 +15,7 @@ class Kamal::Cli::App < Kamal::Cli::Base end #  Primary hosts and roles are returned first, so they can open the barrier - barrier = Kamal::Cli::Healthcheck::Barrier.new + barrier = Kamal::Cli::Healthcheck::Barrier.new if KAMAL.roles.many? on(KAMAL.hosts, **KAMAL.boot_strategy) do |host| KAMAL.roles_on(host).each do |role| diff --git a/lib/kamal/cli/app/boot.rb b/lib/kamal/cli/app/boot.rb index a91c6ffa..5100e3cc 100644 --- a/lib/kamal/cli/app/boot.rb +++ b/lib/kamal/cli/app/boot.rb @@ -43,8 +43,8 @@ class Kamal::Cli::App::Boot reach_barrier rescue => e - if barrier_role? && barrier.close - info "Deploy failed, so closed barrier (#{host})" + if barrier_role? && barrier&.close + info "First #{KAMAL.primary_role} container unhealthy, stopping other roles (#{host})" error capture_with_info(*app.logs(version: version)) error capture_with_info(*app.container_health_log(version: version)) end @@ -71,7 +71,7 @@ class Kamal::Cli::App::Boot if barrier if barrier_role? if barrier.open - info "Opened barrier (#{host})" + info "First #{KAMAL.primary_role} container healthy, continuing other roles (#{host})" end else wait_for_barrier @@ -80,11 +80,11 @@ class Kamal::Cli::App::Boot end def wait_for_barrier - info "Waiting at web barrier (#{host})..." + info "Waiting for a healthy #{KAMAL.primary_role} container (#{host})..." barrier.wait - info "Barrier opened (#{host})" + info "First #{KAMAL.primary_role} container is healthy, continuing (#{host})" rescue Kamal::Cli::Healthcheck::Error - info "Barrier closed, shutting down new container (#{host})..." + info "First #{KAMAL.primary_role} container is unhealthy, stopping (#{host})" raise end diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 3d6061b5..b5b03e27 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -136,10 +136,10 @@ class CliAppTest < CliTestCase .returns("running").at_least_once # workers health check run_command("boot", config: :with_roles, host: nil).tap do |output| - assert_match "Waiting at web barrier (1.1.1.3)...", output - assert_match "Waiting at web barrier (1.1.1.4)...", output - assert_match "Barrier opened (1.1.1.3)", output - assert_match "Barrier opened (1.1.1.4)", output + assert_match "Waiting for a healthy web container (1.1.1.3)...", output + assert_match "Waiting for a healthy web container (1.1.1.4)...", output + assert_match "First web container is healthy, continuing (1.1.1.3)", output + assert_match "First web container is healthy, continuing (1.1.1.4)", output end end @@ -160,10 +160,10 @@ class CliAppTest < CliTestCase stderred do run_command("boot", config: :with_roles, host: nil, allow_execute_error: true).tap do |output| - assert_match "Waiting at web barrier (1.1.1.3)...", output - assert_match "Waiting at web barrier (1.1.1.4)...", output - assert_match "Barrier closed, shutting down new container (1.1.1.3)...", output - assert_match "Barrier closed, shutting down new container (1.1.1.4)...", output + assert_match "Waiting for a healthy web container (1.1.1.3)...", output + assert_match "Waiting for a healthy web container (1.1.1.4)...", output + assert_match "First web container is unhealthy, stopping (1.1.1.3)", output + assert_match "First web container is unhealthy, stopping (1.1.1.4)", output assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.1", output assert_match "Running docker container ls --all --filter name=^app-web-latest$ --quiet | xargs docker stop on 1.1.1.2", output assert_match "Running docker container ls --all --filter name=^app-workers-latest$ --quiet | xargs docker stop on 1.1.1.3", output diff --git a/test/integration/broken_deploy_test.rb b/test/integration/broken_deploy_test.rb index efa90fc9..6b71844e 100644 --- a/test/integration/broken_deploy_test.rb +++ b/test/integration/broken_deploy_test.rb @@ -25,9 +25,9 @@ class BrokenDeployTest < IntegrationTest private def assert_failed_deploy(output) - assert_match "Waiting at web barrier (vm3)...", output - assert_match /Deploy failed, so closed barrier \(vm[12]\)/, output - assert_match "Barrier closed, shutting down new container (vm3)...", output + assert_match "Waiting for a healthy web container (vm3)...", output + assert_match /First #{KAMAL.primary_role} container is unhealthy, stopping \(vm[12]\)/, output + assert_match "First #{KAMAL.primary_role} container unhealthy, stopping other roles (vm3)...", output assert_match "nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /etc/nginx/conf.d/default.conf:2", output assert_match 'ERROR {"Status":"unhealthy","FailingStreak":0,"Log":[]}', output end