From dd748fac8cd93a93e6f4c75f769593bab75dd050 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Mon, 30 Oct 2023 11:29:49 +0000 Subject: [PATCH] Reset the env before pushing Calling `load_envs` again does not load updated env variables, because Dotenv does not overwrite existing values. To fix this we'll store the original ENV and reset to it before reloading. https://github.com/basecamp/kamal/issues/512 --- lib/kamal/cli/base.rb | 7 +++++++ lib/kamal/cli/main.rb | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/kamal/cli/base.rb b/lib/kamal/cli/base.rb index 10925e792..9a38d97e5 100644 --- a/lib/kamal/cli/base.rb +++ b/lib/kamal/cli/base.rb @@ -24,6 +24,7 @@ def self.exit_on_failure?() true end def initialize(*) super + @original_env = ENV.to_h.dup load_envs initialize_commander(options_with_subcommand_class_options) end @@ -37,6 +38,12 @@ def load_envs end end + def reload_envs + ENV.clear + ENV.update(@original_env) + load_envs + end + def options_with_subcommand_class_options options.merge(@_initializer.last[:class_options] || {}) end diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index c1f5adb39..b1f54abab 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -182,8 +182,10 @@ def envify 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] + unless options[:skip_push] + reload_envs + invoke "kamal:cli:env:push", options + end end desc "remove", "Remove Traefik, app, accessories, and registry session from servers"