Skip to content

Commit

Permalink
Merge pull request #1239 from matjack1/output-accessory
Browse files Browse the repository at this point in the history
Add support for exec output in accessories
  • Loading branch information
djmb authored Nov 21, 2024
2 parents f4d98bb + 83fd2a0 commit b9804a0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ def details(name)
end
end

desc "exec [NAME] [CMD]", "Execute a custom command on servers (use --help to show options)"
desc "exec [NAME] [CMD...]", "Execute a custom command on servers within the accessory container (use --help to show options)"
option :interactive, aliases: "-i", type: :boolean, default: false, desc: "Execute command over ssh for an interactive shell (use for console/bash)"
option :reuse, type: :boolean, default: false, desc: "Reuse currently running container instead of starting a new one"
def exec(name, cmd)
def exec(name, *cmd)
cmd = Kamal::Utils.join_commands(cmd)
with_accessory(name) do |accessory, hosts|
case
when options[:interactive] && options[:reuse]
say "Launching interactive command with via SSH from existing container...", :magenta
say "Launching interactive command via SSH from existing container...", :magenta
run_locally { exec accessory.execute_in_existing_container_over_ssh(cmd) }

when options[:interactive]
Expand All @@ -128,16 +129,16 @@ def exec(name, cmd)

when options[:reuse]
say "Launching command from existing container...", :magenta
on(hosts) do
on(hosts) do |host|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
capture_with_info(*accessory.execute_in_existing_container(cmd))
puts_by_host host, capture_with_info(*accessory.execute_in_existing_container(cmd))
end

else
say "Launching command from new container...", :magenta
on(hosts) do
on(hosts) do |host|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
capture_with_info(*accessory.execute_in_new_container(cmd))
puts_by_host host, capture_with_info(*accessory.execute_in_new_container(cmd))
end
end
end
Expand Down

0 comments on commit b9804a0

Please sign in to comment.