Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect yml.erb #391

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/deploy.staging.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry:
password: <%= "my-password-override" %>
File renamed without changes.