Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kamal app exec includes secrets #1223

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def details
option :env, aliases: "-e", type: :hash, desc: "Set environment variables for the command"
def exec(*cmd)
cmd = Kamal::Utils.join_commands(cmd)
env = options[:env]
env = KAMAL.primary_role.env(KAMAL.primary_host).secrets.to_h.merge(options[:env] || {})
case
when options[:interactive] && options[:reuse]
say "Get current version of running container...", :magenta unless options[:version]
Expand Down
13 changes: 13 additions & 0 deletions test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,19 @@ class CliAppTest < CliTestCase
end
end

test "exec includes secrets" do
setup_test_secrets("secrets" => "HELLO=world")
run_command("exec", "echo $HELLO").tap do |output|
assert_match "world", output
end
# Env vars passed with --env should override secrets.
run_command("exec", "--env", "HELLO=Dolly!", "echo $HELLO").tap do |output|
assert_match "Dolly!", output
end
ensure
teardown_test_secrets
end

test "containers" do
run_command("containers").tap do |output|
assert_match "docker container ls --all --filter label=service=app", output
Expand Down