From 8e918b19061395e084760da62f49db4a2580c626 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 19 Feb 2023 09:33:49 +0100 Subject: [PATCH] Output logs when healthcheck fails --- lib/mrsk/cli/healthcheck.rb | 1 + lib/mrsk/commands/healthcheck.rb | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/mrsk/cli/healthcheck.rb b/lib/mrsk/cli/healthcheck.rb index fcaf6bc8..831fdd27 100644 --- a/lib/mrsk/cli/healthcheck.rb +++ b/lib/mrsk/cli/healthcheck.rb @@ -21,6 +21,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base raise end ensure + error capture_with_info(*MRSK.healthcheck.logs) execute *MRSK.healthcheck.stop, raise_on_non_zero_exit: false execute *MRSK.healthcheck.remove, raise_on_non_zero_exit: false end diff --git a/lib/mrsk/commands/healthcheck.rb b/lib/mrsk/commands/healthcheck.rb index 8fd3b23c..34ff3a46 100644 --- a/lib/mrsk/commands/healthcheck.rb +++ b/lib/mrsk/commands/healthcheck.rb @@ -19,16 +19,16 @@ class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base [ :curl, "--silent", "--output", "/dev/null", "--write-out", "'%{http_code}'", health_url ] end + def logs + pipe container_id, xargs(docker(:logs, "2>&1")) + end + def stop - pipe \ - container_id_for(container_name: container_name), - xargs(docker(:stop)) + pipe container_id, xargs(docker(:stop)) end def remove - pipe \ - container_id_for(container_name: container_name), - xargs(docker(:container, :rm)) + pipe container_id, xargs(docker(:container, :rm)) end private @@ -40,6 +40,10 @@ class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base "healthcheck-#{config.service_with_version}" end + def container_id + container_id_for(container_name: container_name) + end + def health_url "http://localhost:#{EXPOSED_PORT}#{config.healthcheck["path"]}" end