diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index 4a81c8ce8..c1f5adb39 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -180,7 +180,7 @@ def envify env_path = ".env" end - File.write(env_path, ERB.new(File.read(env_template_path)).result, perm: 0600) + File.write(env_path, ERB.new(File.read(env_template_path), trim_mode: "-").result, perm: 0600) load_envs # reload new file invoke "kamal:cli:env:push", options unless options[:skip_push] diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index bc53dfbe0..a19ff90e7 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -354,6 +354,20 @@ class CliMainTest < CliTestCase run_command("envify") end + test "envify with blank line trimming" do + file = <<~EOF + HELLO=<%= 'world' %> + <% if true -%> + KEY=value + <% end -%> + EOF + + File.expects(:read).with(".env.erb").returns(file.strip) + File.expects(:write).with(".env", "HELLO=world\nKEY=value\n", perm: 0600) + + run_command("envify") + end + test "envify with destination" do File.expects(:read).with(".env.world.erb").returns("HELLO=<%= 'world' %>") File.expects(:write).with(".env.world", "HELLO=world", perm: 0600)