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
@@ -44,9 +44,22 @@ module Kamal::Cli
|
||||
|
||||
def load_env
|
||||
if destination = options[:destination]
|
||||
Dotenv.load(".env.#{destination}", ".env")
|
||||
if File.exist?(".kamal/env.#{destination}") || File.exist?(".kamal/env")
|
||||
Dotenv.load(".kamal/env.#{destination}", ".kamal/env")
|
||||
else
|
||||
loading_files = [ (".env" if File.exist?(".env")), (".env.#{destination}" if File.exist?(".env.#{destination}")) ].compact
|
||||
if loading_files.any?
|
||||
warn "Loading #{loading_files.join(" and ")} from the project root, use .kamal/env* instead"
|
||||
Dotenv.load(".env.#{destination}", ".env")
|
||||
end
|
||||
end
|
||||
else
|
||||
Dotenv.load(".env")
|
||||
if File.exist?(".kamal/env")
|
||||
Dotenv.load(".kamal/env")
|
||||
elsif File.exist?(".env")
|
||||
warn "Loading .env from the project root is deprecated, use .kamal/env instead"
|
||||
Dotenv.load(".env")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -183,11 +183,25 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip .env file push"
|
||||
def envify
|
||||
if destination = options[:destination]
|
||||
env_template_path = ".env.#{destination}.erb"
|
||||
env_path = ".env.#{destination}"
|
||||
env_template_path = ".kamal/env.#{destination}.erb"
|
||||
env_path = ".kamal/env.#{destination}"
|
||||
else
|
||||
env_template_path = ".env.erb"
|
||||
env_path = ".env"
|
||||
env_template_path = ".kamal/env.erb"
|
||||
env_path = ".kamal/env"
|
||||
end
|
||||
|
||||
unless Pathname.new(File.expand_path(env_template_path)).exist?
|
||||
if destination = options[:destination]
|
||||
env_template_path = ".env.#{destination}.erb"
|
||||
env_path = ".env.#{destination}"
|
||||
else
|
||||
env_template_path = ".env.erb"
|
||||
env_path = ".env"
|
||||
end
|
||||
|
||||
if Pathname.new(File.expand_path(env_template_path)).exist?
|
||||
warn "Loading #{env_template_path} from the project root is deprecated, use .kamal/env[.<DESTINATION>].erb instead"
|
||||
end
|
||||
end
|
||||
|
||||
if Pathname.new(File.expand_path(env_template_path)).exist?
|
||||
|
||||
Reference in New Issue
Block a user