Skip to content

Commit

Permalink
Reset the env before pushing
Browse files Browse the repository at this point in the history
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.

#512
  • Loading branch information
djmb committed Oct 30, 2023
1 parent b732b2d commit dd748fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/kamal/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dd748fa

Please sign in to comment.