Skip to content

Commit

Permalink
feature: add NAME=all option for accessory reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrytrager committed Oct 30, 2023
1 parent 83a2d52 commit 2d22143
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ def directories(name)
end
end

desc "reboot [NAME]", "Reboot existing accessory on host (stop container, remove container, start new container)"
desc "reboot [NAME]", "Reboot existing accessory on host (stop container, remove container, start new container; use NAME=all to boot all accessories)"
def reboot(name)
mutating do
with_accessory(name) do |accessory|
on(accessory.hosts) do
execute *KAMAL.registry.login
end
if name == "all"
KAMAL.accessory_names.each { |accessory_name| reboot(accessory_name) }
else
with_accessory(name) do |accessory|
on(accessory.hosts) do
execute *KAMAL.registry.login
end

stop(name)
remove_container(name)
boot(name, login: false)
stop(name)
remove_container(name)
boot(name, login: false)
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/cli/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ class CliAccessoryTest < CliTestCase
run_command("reboot", "mysql")
end

test "reboot all" do
Kamal::Commands::Registry.any_instance.expects(:login).times(3)
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
Kamal::Cli::Accessory.any_instance.expects(:boot).with("mysql", login: false)
Kamal::Cli::Accessory.any_instance.expects(:stop).with("redis")
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("redis")
Kamal::Cli::Accessory.any_instance.expects(:boot).with("redis", login: false)

run_command("reboot", "all")
end

test "start" do
assert_match "docker container start app-mysql", run_command("start", "mysql")
end
Expand Down

0 comments on commit 2d22143

Please sign in to comment.