From 9ab448e1860e4bd43badaeadeed6ae0a3574630a Mon Sep 17 00:00:00 2001 From: Lewis Buckley Date: Wed, 19 Jul 2023 14:39:27 +0100 Subject: [PATCH 1/3] Support a --rolling option for traefik reboots --- lib/mrsk/cli/traefik.rb | 11 ++++++++--- test/cli/traefik_test.rb | 15 +++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/mrsk/cli/traefik.rb b/lib/mrsk/cli/traefik.rb index 30fd10f32..aaa079a26 100644 --- a/lib/mrsk/cli/traefik.rb +++ b/lib/mrsk/cli/traefik.rb @@ -9,12 +9,17 @@ def boot 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 diff --git a/test/cli/traefik_test.rb b/test/cli/traefik_test.rb index a1f661d27..efd00c810 100644 --- a/test/cli/traefik_test.rb +++ b/test/cli/traefik_test.rb @@ -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 From ecfd258093f8fd082a1babee6dfbc043fa6ebaa8 Mon Sep 17 00:00:00 2001 From: Lewis Buckley Date: Wed, 19 Jul 2023 14:58:46 +0100 Subject: [PATCH 2/3] Document the rolling reboot option --- lib/mrsk/cli/traefik.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mrsk/cli/traefik.rb b/lib/mrsk/cli/traefik.rb index e404f0fd0..42d610d30 100644 --- a/lib/mrsk/cli/traefik.rb +++ b/lib/mrsk/cli/traefik.rb @@ -9,7 +9,7 @@ def boot end end - method_option :rolling, type: :boolean, default: false + method_option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel" desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)" def reboot mutating do From 9d5a6d13218b5a60d8a9091d5d5d11bb52c8d61a Mon Sep 17 00:00:00 2001 From: Lewis Buckley Date: Wed, 19 Jul 2023 15:03:15 +0100 Subject: [PATCH 3/3] Document the rolling option for traefik reboots --- README.md | 10 ++++++++++ lib/mrsk/cli/traefik.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 034e0a777..3b0ce634b 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,16 @@ traefik: entrypoints.otherentrypoint.address: ':9000' ``` +### Rebooting Traefik + +If you make changes to Traefik args or labels, you'll need to reboot with: + +`mrsk traefik reboot` + +In production, reboot the Traefik containers one by one with a slower but safer approach, using a rolling reboot: + +`mrsk traefik reboot --rolling` + ### Configuring build args for new images Build arguments that aren't secret can also be configured: diff --git a/lib/mrsk/cli/traefik.rb b/lib/mrsk/cli/traefik.rb index 42d610d30..b96b59d60 100644 --- a/lib/mrsk/cli/traefik.rb +++ b/lib/mrsk/cli/traefik.rb @@ -9,8 +9,8 @@ def boot end end - method_option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel" desc "reboot", "Reboot Traefik on servers (stop container, remove container, start new container)" + option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel" def reboot mutating do on(MRSK.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do