Merge pull request #393 from basecamp/rolling-traefik-restarts
Support a --rolling option for traefik reboots
This commit is contained in:
10
README.md
10
README.md
@@ -633,6 +633,16 @@ traefik:
|
|||||||
entrypoints.otherentrypoint.address: ':9000'
|
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
|
### Configuring build args for new images
|
||||||
|
|
||||||
Build arguments that aren't secret can also be configured:
|
Build arguments that aren't secret can also be configured:
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
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(login: true)
|
def boot
|
||||||
mutating do
|
mutating do
|
||||||
on(MRSK.traefik_hosts) 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
|
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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)"
|
||||||
|
option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel"
|
||||||
def reboot
|
def reboot
|
||||||
mutating do
|
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.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
|
end
|
||||||
|
|
||||||
stop
|
|
||||||
remove_container
|
|
||||||
boot(login: false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,18 @@ class CliTraefikTest < CliTestCase
|
|||||||
|
|
||||||
test "reboot" do
|
test "reboot" do
|
||||||
Mrsk::Commands::Registry.any_instance.expects(:login).twice
|
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
|
end
|
||||||
|
|
||||||
test "start" do
|
test "start" do
|
||||||
|
|||||||
Reference in New Issue
Block a user