Skip to content

Commit

Permalink
Merge pull request basecamp#393 from basecamp/rolling-traefik-restarts
Browse files Browse the repository at this point in the history
Support a --rolling option for traefik reboots
  • Loading branch information
djmb authored Jul 19, 2023
2 parents e1433f3 + 9d5a6d1 commit 5e8df58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions lib/mrsk/cli/traefik.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "boot", "Boot Traefik on servers"
def boot(login: true)
def boot
mutating do
on(MRSK.traefik_hosts) do
execute *MRSK.registry.login if login
execute *MRSK.registry.login
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
end
end
end

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) do
on(MRSK.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do
execute *MRSK.auditor.record("Rebooted traefik"), verbosity: :debug
execute *MRSK.registry.login
execute *MRSK.traefik.stop, raise_on_non_zero_exit: false
execute *MRSK.traefik.remove_container
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
end

stop
remove_container
boot(login: false)
end
end

Expand Down
15 changes: 11 additions & 4 deletions test/cli/traefik_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ class CliTraefikTest < CliTestCase

test "reboot" do
Mrsk::Commands::Registry.any_instance.expects(:login).twice
Mrsk::Cli::Traefik.any_instance.expects(:stop)
Mrsk::Cli::Traefik.any_instance.expects(:remove_container)
Mrsk::Cli::Traefik.any_instance.expects(:boot).with(login: false)

run_command("reboot")
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 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

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[3]
end
end

test "start" do
Expand Down

0 comments on commit 5e8df58

Please sign in to comment.