Skip to content

Commit

Permalink
App exec with env file
Browse files Browse the repository at this point in the history
When calling `kamal app exec` for new non interactive containers, run
the command per role on each server and include the role config
including the environment.

Fixes: #492
  • Loading branch information
djmb committed Sep 25, 2023
1 parent 83a2d52 commit 645f5ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ def exec(cmd)
using_version(version_or_latest) do |version|
say "Launching command with version #{version} from new container...", :magenta
on(KAMAL.hosts) do |host|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
puts_by_host host, capture_with_info(*KAMAL.app.execute_in_new_container(cmd))
roles = KAMAL.roles_on(host)

roles.each do |role|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
puts_by_host host, capture_with_info(*KAMAL.app(role: role).execute_in_new_container(cmd))
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CliAppTest < CliTestCase

test "exec" do
run_command("exec", "ruby -v").tap do |output|
assert_match "docker run --rm dhh/app:latest ruby -v", output
assert_match "docker run --rm --env-file .kamal/env/roles/app-web.env dhh/app:latest ruby -v", output
end
end

Expand Down

0 comments on commit 645f5ab

Please sign in to comment.