diff --git a/lib/kamal/commands/healthcheck.rb b/lib/kamal/commands/healthcheck.rb index d3c94923..4327087d 100644 --- a/lib/kamal/commands/healthcheck.rb +++ b/lib/kamal/commands/healthcheck.rb @@ -1,5 +1,4 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base - EXPOSED_PORT = 3999 def run web = config.role(:web) @@ -7,7 +6,7 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base docker :run, "--detach", "--name", container_name_with_version, - "--publish", "#{EXPOSED_PORT}:#{config.healthcheck["port"]}", + "--publish", "#{exposed_port}:#{config.healthcheck["port"]}", "--label", "service=#{container_name}", "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"", *web.env_args, @@ -52,6 +51,10 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base end def health_url - "http://localhost:#{EXPOSED_PORT}#{config.healthcheck["path"]}" + "http://localhost:#{exposed_port}#{config.healthcheck["path"]}" + end + + def exposed_port + config.healthcheck["exposed_port"] end end diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index d6e8d757..28da91ef 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -145,7 +145,7 @@ class Kamal::Configuration def healthcheck - { "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {}) + { "path" => "/up", "port" => 3000, "max_attempts" => 7, "exposed_port" => 3999 }.merge(raw_config.healthcheck || {}) end def readiness_delay diff --git a/test/commands/healthcheck_test.rb b/test/commands/healthcheck_test.rb index 4fad7830..9d47c313 100644 --- a/test/commands/healthcheck_test.rb +++ b/test/commands/healthcheck_test.rb @@ -40,8 +40,9 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase test "run with custom options" do @config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere" } } } + @config[:healthcheck] = { "exposed_port" => 4999 } assert_equal \ - "docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --mount \"somewhere\" dhh/app:123", + "docker run --detach --name healthcheck-app-123 --publish 4999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --mount \"somewhere\" dhh/app:123", new_command.run.join(" ") end