Trim long hostnames
Hostnames longer than 64 characters are not supported by docker
This commit is contained in:
@@ -47,7 +47,8 @@ class Kamal::Cli::App::Boot
|
||||
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
|
||||
|
||||
|
||||
@@ -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" ]) }
|
||||
|
||||
8
test/fixtures/deploy_with_uncommon_hostnames.yml
vendored
Normal file
8
test/fixtures/deploy_with_uncommon_hostnames.yml
vendored
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user