diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index e5ecbb530..14f8d5549 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -34,7 +34,12 @@ def load_config_file(file) end def destination_config_file(base_config_file, destination) - base_config_file.sub_ext(".#{destination}.yml") if destination + return unless destination + + return base_config_file.sub(/\.yml$/, ".#{destination}.yml") if base_config_file.extname == ".yml" + return base_config_file.sub(/\.yml.erb$/, ".#{destination}.yml.erb") if base_config_file.extname == ".erb" + + raise 'Unsupported config file extension. Please use .yml or .yml.erb' end end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 392b6afb9..74408ad58 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -194,10 +194,18 @@ class ConfigurationTest < ActiveSupport::TestCase end test "erb evaluation of yml config" do - config = Kamal::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__)) + config = Kamal::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.yml.erb", __dir__)) assert_equal "my-user", config.registry["username"] end + test "erb evaluation of yml config with destinations" do + config_file = Pathname.new(File.expand_path("fixtures/deploy.yml.erb", __dir__)) + + config = Mrsk::Configuration.create_from config_file: config_file, destination: 'staging' + assert_equal "my-user", config.registry["username"] + assert_equal "my-password-override", config.registry["password"] + end + test "destination yml config merge" do dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__)) diff --git a/test/fixtures/deploy.staging.yml.erb b/test/fixtures/deploy.staging.yml.erb new file mode 100644 index 000000000..5b2b81f53 --- /dev/null +++ b/test/fixtures/deploy.staging.yml.erb @@ -0,0 +1,2 @@ +registry: + password: <%= "my-password-override" %> diff --git a/test/fixtures/deploy.erb.yml b/test/fixtures/deploy.yml.erb similarity index 100% rename from test/fixtures/deploy.erb.yml rename to test/fixtures/deploy.yml.erb