diff --git a/lib/kamal/cli/app/boot.rb b/lib/kamal/cli/app/boot.rb index ed7e2ed6e..1179c2edf 100644 --- a/lib/kamal/cli/app/boot.rb +++ b/lib/kamal/cli/app/boot.rb @@ -47,7 +47,8 @@ def old_version_renamed_if_clashing def start_new_version audit "Booted app version #{version}" execute *app.tie_cord(role.cord_host_file) if uses_cord? - execute *app.run(hostname: "#{host}-#{SecureRandom.hex(6)}") + hostname = "#{host.to_s[0...51].gsub(/\.+$/, '')}-#{SecureRandom.hex(6)}" + execute *app.run(hostname: hostname) Kamal::Cli::Healthcheck::Poller.wait_for_healthy(pause_after_ready: true) { capture_with_info(*app.status(version: version)) } end diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index ab0eff51f..9ed9587e5 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -236,6 +236,26 @@ class CliAppTest < CliTestCase end end + test "long hostname" do + stub_running + + hostname = "this-hostname-is-really-unacceptably-long-to-be-honest.example.com" + + stdouted { Kamal::Cli::App.start([ "boot", "-c", "test/fixtures/deploy_with_uncommon_hostnames.yml", "--hosts", hostname ]) }.tap do |output| + assert_match /docker run --detach --restart unless-stopped --name app-web-latest --hostname this-hostname-is-really-unacceptably-long-to-be-hon-[0-9a-f]{12} /, output + end + end + + test "hostname is trimmed if will end with a period" do + stub_running + + hostname = "this-hostname-with-random-part-is-too-long.example.com" + + stdouted { Kamal::Cli::App.start([ "boot", "-c", "test/fixtures/deploy_with_uncommon_hostnames.yml", "--hosts", hostname ]) }.tap do |output| + assert_match /docker run --detach --restart unless-stopped --name app-web-latest --hostname this-hostname-with-random-part-is-too-long.example-[0-9a-f]{12} /, output + end + end + private def run_command(*command, config: :with_accessories) stdouted { Kamal::Cli::App.start([ *command, "-c", "test/fixtures/deploy_#{config}.yml", "--hosts", "1.1.1.1" ]) } diff --git a/test/fixtures/deploy_with_uncommon_hostnames.yml b/test/fixtures/deploy_with_uncommon_hostnames.yml new file mode 100644 index 000000000..71e7a6018 --- /dev/null +++ b/test/fixtures/deploy_with_uncommon_hostnames.yml @@ -0,0 +1,8 @@ +service: app +image: dhh/app +servers: + - "this-hostname-with-random-part-is-too-long.example.com" + - "this-hostname-is-really-unacceptably-long-to-be-honest.example.com" +registry: + username: user + password: pw