Support a --rolling option for traefik reboots

This commit is contained in:
Lewis Buckley
2023-07-19 14:39:27 +01:00
parent 9a501867b4
commit 9ab448e186
2 changed files with 19 additions and 7 deletions

View File

@@ -9,12 +9,17 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
end end
end end
method_option :rolling, type: :boolean, default: false
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
stop on(MRSK.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do
remove_container execute *MRSK.auditor.record("Rebooted traefik"), verbosity: :debug
boot execute *MRSK.traefik.stop, raise_on_non_zero_exit: false
execute *MRSK.traefik.remove_container
execute *MRSK.registry.login
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
end
end end
end end

View File

@@ -9,11 +9,18 @@ class CliTraefikTest < CliTestCase
end end
test "reboot" do test "reboot" do
Mrsk::Cli::Traefik.any_instance.expects(:stop) run_command("reboot").tap do |output|
Mrsk::Cli::Traefik.any_instance.expects(:remove_container) assert_match "docker container stop traefik", output
Mrsk::Cli::Traefik.any_instance.expects(:boot) assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output
assert_match "docker login", output
assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Mrsk::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output
end
end
run_command("reboot") test "reboot --rolling" do
run_command("reboot", "--rolling").tap do |output|
assert_match "Running docker container prune --force --filter label=org.opencontainers.image.title=Traefik on 1.1.1.1", output.lines[2]
end
end end
test "start" do test "start" do