diff --git a/lib/kamal/commands/healthcheck.rb b/lib/kamal/commands/healthcheck.rb index b68df5bba..5adc02445 100644 --- a/lib/kamal/commands/healthcheck.rb +++ b/lib/kamal/commands/healthcheck.rb @@ -26,7 +26,7 @@ def container_health_log end def logs - pipe container_id, xargs(docker(:logs, "--tail", 50, "2>&1")) + pipe container_id, xargs(docker(:logs, "--tail", log_lines, "2>&1")) end def stop @@ -53,4 +53,8 @@ def health_url def exposed_port config.healthcheck["exposed_port"] end + + def log_lines + config.healthcheck["log_lines"] + end end diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index 4d576c90b..5d2fc8de3 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -152,7 +152,7 @@ def sshkit def healthcheck - { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord" }.merge(raw_config.healthcheck || {}) + { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }.merge(raw_config.healthcheck || {}) end def healthcheck_service diff --git a/test/commands/healthcheck_test.rb b/test/commands/healthcheck_test.rb index 5ef7fc03d..66cdda6b4 100644 --- a/test/commands/healthcheck_test.rb +++ b/test/commands/healthcheck_test.rb @@ -92,6 +92,13 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase new_command.logs.join(" ") end + test "logs with custom lines number" do + @config[:healthcheck] = { "log_lines" => 150 } + assert_equal \ + "docker container ls --all --filter name=^healthcheck-app-123$ --quiet | xargs docker logs --tail 150 2>&1", + new_command.logs.join(" ") + end + test "logs with destination" do @destination = "staging" diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 71a5fe458..5e6eab7d3 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -240,7 +240,7 @@ class ConfigurationTest < ActiveSupport::TestCase :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, :logging=>["--log-opt", "max-size=\"10m\""], - :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord" }} + :healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }} assert_equal expected_config, @config.to_h end diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index 495280bb1..08376f695 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -56,7 +56,7 @@ class MainTest < IntegrationTest assert_equal({ user: "root", keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options]) assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] - assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) + assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999, "cord"=>"/tmp/kamal-cord", "log_lines" => 50, "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1" }, config[:healthcheck]) end private