From 3c930c45e9ac85ca30a645be6d2f650c952bf4ea Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 6 Sep 2023 11:38:15 -0400 Subject: [PATCH] Allow setting an env file when running containers --- lib/kamal/utils.rb | 2 ++ test/configuration_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/kamal/utils.rb b/lib/kamal/utils.rb index c2461373b..058e3687f 100644 --- a/lib/kamal/utils.rb +++ b/lib/kamal/utils.rb @@ -21,6 +21,8 @@ def argumentize(argument, attributes, sensitive: false) def argumentize_env_with_secrets(env) if (secrets = env["secret"]).present? argumentize("-e", secrets.to_h { |key| [ key, ENV.fetch(key) ] }, sensitive: true) + argumentize("-e", env["clear"]) + elsif (file = env["file"]).present? + argumentize "--env-file", file else argumentize "-e", env.fetch("clear", env) end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 615053129..7d46e5122 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -128,6 +128,12 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal [ "-e", "REDIS_URL=\"redis://x/y\"" ], @config.env_args end + test "env file" do + config = Kamal::Configuration.new({ env: { file: "/path/to/.env" } }) + + assert_equal [ "--env-file", "/path/to/.env" ], config.env_args + end + test "env args with clear and secrets" do ENV["PASSWORD"] = "secret123"