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
method_option :rolling, type: :boolean, default: false
desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)"
def reboot
mutating do
stop
remove_container
boot
on(MRSK.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do
execute *MRSK.auditor.record("Rebooted traefik"), verbosity: :debug
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

View File

@@ -9,11 +9,18 @@ class CliTraefikTest < CliTestCase
end
test "reboot" do
Mrsk::Cli::Traefik.any_instance.expects(:stop)
Mrsk::Cli::Traefik.any_instance.expects(:remove_container)
Mrsk::Cli::Traefik.any_instance.expects(:boot)
run_command("reboot").tap do |output|
assert_match "docker container stop traefik", output
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
test "start" do