Replace .env* with .kamal/env*
By default look for the env file in .kamal/env to avoid clashes with other tools using .env. For now we'll still load .env and issue a deprecation warning, but in future we'll stop reading those.
This commit is contained in:
committed by
Donal McBreen
parent
0b5506f6f2
commit
5c4c33e0a8
@@ -439,9 +439,9 @@ class CliMainTest < CliTestCase
|
||||
end
|
||||
|
||||
test "envify" do
|
||||
with_test_dotenv(".env.erb": "HELLO=<%= 'world' %>") do
|
||||
with_test_env_files("env.erb": "HELLO=<%= 'world' %>") do
|
||||
run_command("envify")
|
||||
assert_equal("HELLO=world", File.read(".env"))
|
||||
assert_equal("HELLO=world", File.read(".kamal/env"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -453,32 +453,32 @@ class CliMainTest < CliTestCase
|
||||
<% end -%>
|
||||
EOF
|
||||
|
||||
with_test_dotenv(".env.erb": file) do
|
||||
with_test_env_files("env.erb": file) do
|
||||
run_command("envify")
|
||||
assert_equal("HELLO=world\nKEY=value\n", File.read(".env"))
|
||||
assert_equal("HELLO=world\nKEY=value\n", File.read(".kamal/env"))
|
||||
end
|
||||
end
|
||||
|
||||
test "envify with destination" do
|
||||
with_test_dotenv(".env.world.erb": "HELLO=<%= 'world' %>") do
|
||||
with_test_env_files("env.world.erb": "HELLO=<%= 'world' %>") do
|
||||
run_command("envify", "-d", "world", config_file: "deploy_for_dest")
|
||||
assert_equal "HELLO=world", File.read(".env.world")
|
||||
assert_equal "HELLO=world", File.read(".kamal/env.world")
|
||||
end
|
||||
end
|
||||
|
||||
test "envify with skip_push" do
|
||||
Pathname.any_instance.expects(:exist?).returns(true).times(1)
|
||||
File.expects(:read).with(".env.erb").returns("HELLO=<%= 'world' %>")
|
||||
File.expects(:write).with(".env", "HELLO=world", perm: 0600)
|
||||
Pathname.any_instance.expects(:exist?).returns(true).times(2)
|
||||
File.expects(:read).with(".kamal/env.erb").returns("HELLO=<%= 'world' %>")
|
||||
File.expects(:write).with(".kamal/env", "HELLO=world", perm: 0600)
|
||||
|
||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push").never
|
||||
run_command("envify", "--skip-push")
|
||||
end
|
||||
|
||||
test "envify with clean env" do
|
||||
with_test_dotenv(".env": "HELLO=already", ".env.erb": "HELLO=<%= ENV.fetch 'HELLO', 'never' %>") do
|
||||
with_test_env_files("env": "HELLO=already", "env.erb": "HELLO=<%= ENV.fetch 'HELLO', 'never' %>") do
|
||||
run_command("envify", "--skip-push")
|
||||
assert_equal "HELLO=never", File.read(".env")
|
||||
assert_equal "HELLO=never", File.read(".kamal/env")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -572,15 +572,18 @@ class CliMainTest < CliTestCase
|
||||
end
|
||||
end
|
||||
|
||||
def with_test_dotenv(**files)
|
||||
def with_test_env_files(**files)
|
||||
Dir.mktmpdir do |dir|
|
||||
fixtures_dup = File.join(dir, "test")
|
||||
FileUtils.mkdir_p(fixtures_dup)
|
||||
FileUtils.cp_r("test/fixtures/", fixtures_dup)
|
||||
|
||||
Dir.chdir(dir) do
|
||||
files.each do |filename, contents|
|
||||
File.binwrite(filename.to_s, contents)
|
||||
FileUtils.mkdir_p(".kamal")
|
||||
Dir.chdir(".kamal") do
|
||||
files.each do |filename, contents|
|
||||
File.binwrite(filename.to_s, contents)
|
||||
end
|
||||
end
|
||||
yield
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user