diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index 605268005..2c3c354ae 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -39,7 +39,10 @@ def load_config_file(file) end def destination_config_file(base_config_file, destination) - base_config_file.sub_ext(".#{destination}.yml") if destination + if destination + base_extension = base_config_file.extname + base_config_file.sub_ext(".#{destination}#{base_extension}") + end end end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 7f631e27f..801f4fc8e 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -262,6 +262,25 @@ class ConfigurationTest < ActiveSupport::TestCase end end + test "destination yaml config preserves extension" do + dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yaml", __dir__)) + + config = Kamal::Configuration.create_from config_file: dest_config_file, destination: "world" + assert_equal "2.1.1.1", config.all_hosts.first + end + + test "destination file preserves base file extension" do + # Test with .yml extension (existing behavior should still work) + yml_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__)) + config = Kamal::Configuration.create_from config_file: yml_config_file, destination: "world" + assert_equal "1.1.1.1", config.all_hosts.first + + # Test with .yaml extension (new behavior) + yaml_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yaml", __dir__)) + config = Kamal::Configuration.create_from config_file: yaml_config_file, destination: "world" + assert_equal "2.1.1.1", config.all_hosts.first + end + test "destination required" do dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_required_dest.yml", __dir__)) diff --git a/test/fixtures/deploy_for_dest.world.yaml b/test/fixtures/deploy_for_dest.world.yaml new file mode 100644 index 000000000..66314f244 --- /dev/null +++ b/test/fixtures/deploy_for_dest.world.yaml @@ -0,0 +1,5 @@ +servers: + - 2.1.1.1 + - 2.1.1.2 +env: + REDIS_URL: redis://x/y diff --git a/test/fixtures/deploy_for_dest.yaml b/test/fixtures/deploy_for_dest.yaml new file mode 100644 index 000000000..1784d95f9 --- /dev/null +++ b/test/fixtures/deploy_for_dest.yaml @@ -0,0 +1,8 @@ +service: app +image: dhh/app +registry: + server: registry.digitalocean.com + username: <%= "my-user" %> + password: <%= "my-password" %> +builder: + arch: amd64