Login to the registry proactively before stoping Accessory and Traefik

This commit is contained in:
Igor Alexandrov
2023-06-22 15:13:47 +04:00
parent 9a501867b4
commit 2746a48e88
4 changed files with 22 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
class Mrsk::Cli::Accessory < Mrsk::Cli::Base class Mrsk::Cli::Accessory < Mrsk::Cli::Base
desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)" desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)"
def boot(name) def boot(name, login: true)
mutating do mutating do
if name == "all" if name == "all"
MRSK.accessory_names.each { |accessory_name| boot(accessory_name) } MRSK.accessory_names.each { |accessory_name| boot(accessory_name) }
@@ -10,7 +10,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
upload(name) upload(name)
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.registry.login execute *MRSK.registry.login if login
execute *MRSK.auditor.record("Booted #{name} accessory"), verbosity: :debug execute *MRSK.auditor.record("Booted #{name} accessory"), verbosity: :debug
execute *accessory.run execute *accessory.run
end end
@@ -53,9 +53,13 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
def reboot(name) def reboot(name)
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do
execute *MRSK.registry.login
end
stop(name) stop(name)
remove_container(name) remove_container(name)
boot(name) boot(name, login: false)
end end
end end
end end

View File

@@ -1,9 +1,9 @@
class Mrsk::Cli::Traefik < Mrsk::Cli::Base class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "boot", "Boot Traefik on servers" desc "boot", "Boot Traefik on servers"
def boot def boot(login: true)
mutating do mutating do
on(MRSK.traefik_hosts) do on(MRSK.traefik_hosts) do
execute *MRSK.registry.login execute *MRSK.registry.login if login
execute *MRSK.traefik.run, raise_on_non_zero_exit: false execute *MRSK.traefik.run, raise_on_non_zero_exit: false
end end
end end
@@ -12,9 +12,17 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)" desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)"
def reboot def reboot
mutating do mutating do
on(MRSK.traefik_hosts) do
execute *MRSK.registry.login
end
stop stop
remove_container remove_container
boot boot(login: false)
on(MRSK.traefik_hosts) do
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
end
end end
end end

View File

@@ -40,9 +40,10 @@ class CliAccessoryTest < CliTestCase
end end
test "reboot" do test "reboot" do
Mrsk::Commands::Registry.any_instance.expects(:login)
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql") Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("mysql") Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:boot).with("mysql") Mrsk::Cli::Accessory.any_instance.expects(:boot).with("mysql", login: false)
run_command("reboot", "mysql") run_command("reboot", "mysql")
end end

View File

@@ -9,9 +9,10 @@ class CliTraefikTest < CliTestCase
end end
test "reboot" do test "reboot" do
Mrsk::Commands::Registry.any_instance.expects(:login).twice
Mrsk::Cli::Traefik.any_instance.expects(:stop) Mrsk::Cli::Traefik.any_instance.expects(:stop)
Mrsk::Cli::Traefik.any_instance.expects(:remove_container) Mrsk::Cli::Traefik.any_instance.expects(:remove_container)
Mrsk::Cli::Traefik.any_instance.expects(:boot) Mrsk::Cli::Traefik.any_instance.expects(:boot).with(login: false)
run_command("reboot") run_command("reboot")
end end