Skip to content
Merged
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
9 changes: 6 additions & 3 deletions lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ def restart(name)

desc "details [NAME]", "Show details about accessory on host (use NAME=all to show all accessories)"
def details(name)
quiet = options[:quiet]
if name == "all"
KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
else
type = "Accessory #{name}"
with_accessory(name) do |accessory, hosts|
on(hosts) { puts_by_host host, capture_with_info(*accessory.info), type: type }
on(hosts) { puts_by_host host, capture_with_info(*accessory.info), type: type, quiet: quiet }
end
end
end
Expand All @@ -145,6 +146,8 @@ def exec(name, *cmd)
pre_connect_if_required

cmd = Kamal::Utils.join_commands(cmd)
quiet = options[:quiet]

with_accessory(name) do |accessory, hosts|
case
when options[:interactive] && options[:reuse]
Expand All @@ -160,15 +163,15 @@ def exec(name, *cmd)
say "Launching command from existing container...", :magenta
on(hosts) do |host|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
puts_by_host host, capture_with_info(*accessory.execute_in_existing_container(cmd))
puts_by_host host, capture_with_info(*accessory.execute_in_existing_container(cmd)), quiet: quiet
end

else
say "Launching command from new container...", :magenta
on(hosts) do |host|
execute *KAMAL.registry.login
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
puts_by_host host, capture_with_info(*accessory.execute_in_new_container(cmd))
puts_by_host host, capture_with_info(*accessory.execute_in_new_container(cmd)), quiet: quiet
end
end
end
Expand Down
27 changes: 17 additions & 10 deletions lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ def stop
# FIXME: Drop in favor of just containers?
desc "details", "Show details about app containers"
def details
quiet = options[:quiet]
on(KAMAL.app_hosts) do |host|
roles = KAMAL.roles_on(host)

roles.each do |role|
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).info)
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).info), quiet: quiet
end
end
end
Expand All @@ -120,6 +121,7 @@ def exec(*cmd)
cmd = Kamal::Utils.join_commands(cmd)
env = options[:env]
detach = options[:detach]
quiet = options[:quiet]
case
when options[:interactive] && options[:reuse]
say "Get current version of running container...", :magenta unless options[:version]
Expand Down Expand Up @@ -148,7 +150,7 @@ def exec(*cmd)

roles.each do |role|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}", role: role), verbosity: :debug
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).execute_in_existing_container(cmd, env: env))
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).execute_in_existing_container(cmd, env: env)), quiet: quiet
end
end
end
Expand All @@ -164,7 +166,7 @@ def exec(*cmd)

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, host: host).execute_in_new_container(cmd, env: env, detach: detach))
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).execute_in_new_container(cmd, env: env, detach: detach)), quiet: quiet
end
end
end
Expand All @@ -173,12 +175,14 @@ def exec(*cmd)

desc "containers", "Show app containers on servers"
def containers
on(KAMAL.app_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_containers) }
quiet = options[:quiet]
on(KAMAL.app_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_containers), quiet: quiet }
end

desc "stale_containers", "Detect app stale containers"
option :stop, aliases: "-s", type: :boolean, default: false, desc: "Stop the stale containers found"
def stale_containers
quiet = options[:quiet]
stop = options[:stop]

with_lock_if_stopping do
Expand All @@ -192,10 +196,10 @@ def stale_containers

versions.each do |version|
if stop
puts_by_host host, "Stopping stale container for role #{role} with version #{version}"
puts_by_host host, "Stopping stale container for role #{role} with version #{version}", quiet: quiet
execute *app.stop(version: version), raise_on_non_zero_exit: false
else
puts_by_host host, "Detected stale container for role #{role} with version #{version} (use `kamal app stale_containers --stop` to stop)"
puts_by_host host, "Detected stale container for role #{role} with version #{version} (use `kamal app stale_containers --stop` to stop)", quiet: quiet
end
end
end
Expand All @@ -205,7 +209,8 @@ def stale_containers

desc "images", "Show app images on servers"
def images
on(KAMAL.app_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_images) }
quiet = options[:quiet]
on(KAMAL.app_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_images), quiet: quiet }
end

desc "logs", "Show log lines from app on servers (use --help to show options)"
Expand All @@ -224,6 +229,7 @@ def logs
since = options[:since]
container_id = options[:container_id]
timestamps = !options[:skip_timestamps]
quiet = options[:quiet]

if options[:follow]
lines = options[:lines].presence || ((since || grep) ? nil : 10) # Default to 10 lines if since or grep isn't set
Expand All @@ -246,9 +252,9 @@ def logs

roles.each do |role|
begin
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).logs(container_id: container_id, timestamps: timestamps, since: since, lines: lines, grep: grep, grep_options: grep_options))
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).logs(container_id: container_id, timestamps: timestamps, since: since, lines: lines, grep: grep, grep_options: grep_options)), quiet: quiet
rescue SSHKit::Command::Failed
puts_by_host host, "Nothing found"
puts_by_host host, "Nothing found", quiet: quiet
end
end
end
Expand Down Expand Up @@ -352,9 +358,10 @@ def remove_app_directories

desc "version", "Show app version currently running on servers"
def version
quiet = options[:quiet]
on(KAMAL.app_hosts) do |host|
role = KAMAL.roles_on(host).first
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).current_running_version).strip
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).current_running_version).strip, quiet: quiet
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ def details

desc "audit", "Show audit log from servers"
def audit
quiet = options[:quiet]
on(KAMAL.hosts) do |host|
puts_by_host host, capture_with_info(*KAMAL.auditor.reveal)
puts_by_host host, capture_with_info(*KAMAL.auditor.reveal), quiet: quiet
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/kamal/cli/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def restart

desc "details", "Show details about proxy container from servers"
def details
on(KAMAL.proxy_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.proxy.info), type: "Proxy" }
quiet = options[:quiet]
on(KAMAL.proxy_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.proxy.info), type: "Proxy", quiet: quiet }
end

desc "logs", "Show log lines from proxy on servers"
Expand Down
3 changes: 2 additions & 1 deletion lib/kamal/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def exec(*cmd)

cmd = Kamal::Utils.join_commands(cmd)
hosts = KAMAL.hosts
quiet = options[:quiet]

case
when options[:interactive]
Expand All @@ -19,7 +20,7 @@ def exec(*cmd)

on(hosts) do |host|
execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{host}"), verbosity: :debug
puts_by_host host, capture_with_info(cmd)
puts_by_host host, capture_with_info(cmd), quiet: quiet
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/kamal/sshkit_with_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def capture_with_pretty_json(*args, **kwargs)
JSON.pretty_generate(JSON.parse(capture(*args, **kwargs)))
end

def puts_by_host(host, output, type: "App")
puts "#{type} Host: #{host}\n#{output}\n\n"
def puts_by_host(host, output, type: "App", quiet: false)
unless quiet
puts "#{type} Host: #{host}"
end
puts "#{output}\n\n"
end

# Our execution pattern is for the CLI execute args lists returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ accessories:
- web
aliases:
whome: version
worker_hostname: app exec -r workers -q --reuse hostname
uname: server exec -q -p uname
worker_hostname: app exec -r workers --reuse hostname
worker_hostname_quiet: app exec -r workers -q --reuse hostname
uname: server exec -p uname
uname_quiet: server exec -q -p uname
6 changes: 6 additions & 0 deletions test/integration/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ class MainTest < IntegrationTest
output = kamal :worker_hostname, capture: true
assert_match /App Host: vm3\nvm3-[0-9a-f]{12}$/, output

output = kamal :worker_hostname_quiet, capture: true
assert_match /vm3-[0-9a-f]{12}$/, output

output = kamal :uname, "-o", capture: true
assert_match "App Host: vm1\nGNU/Linux", output

output = kamal :uname_quiet, "-o", capture: true
assert_match "GNU/Linux", output
end

test "setup and remove" do
Expand Down