Skip to content

Commit

Permalink
Merge pull request #573 from basecamp/pre-post-traefik-reboot-hooks
Browse files Browse the repository at this point in the history
Pre and post Traefik reboot hooks
  • Loading branch information
djmb authored Nov 15, 2023
2 parents 77a79b2 + 5fd4a28 commit a0959b5
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "Rebooted Traefik on $KAMAL_HOSTS"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "Rebooting Traefik on $KAMAL_HOSTS..."
18 changes: 12 additions & 6 deletions lib/kamal/cli/traefik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ def boot
option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel"
def reboot
mutating do
on(KAMAL.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do
execute *KAMAL.auditor.record("Rebooted traefik"), verbosity: :debug
execute *KAMAL.registry.login
execute *KAMAL.traefik.stop
execute *KAMAL.traefik.remove_container
execute *KAMAL.traefik.run
host_groups = options[:rolling] ? KAMAL.traefik_hosts : [KAMAL.traefik_hosts]
host_groups.each do |hosts|
host_list = Array(hosts).join(",")
run_hook "pre-traefik-reboot", hosts: host_list
on(hosts) do
execute *KAMAL.auditor.record("Rebooted traefik"), verbosity: :debug
execute *KAMAL.registry.login
execute *KAMAL.traefik.stop
execute *KAMAL.traefik.remove_container
execute *KAMAL.traefik.run
end
run_hook "post-traefik-reboot", hosts: host_list
end
end
end
Expand Down
747 changes: 747 additions & 0 deletions queries

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Rebooted Traefik on ${KAMAL_HOSTS}"
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-traefik-reboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Rebooting Traefik on ${KAMAL_HOSTS}..."
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-traefik-reboot
13 changes: 12 additions & 1 deletion test/integration/traefik_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ class TraefikTest < IntegrationTest
kamal :traefik, :boot
assert_traefik_running

kamal :traefik, :reboot
output = kamal :traefik, :reboot, capture: true
assert_traefik_running
assert_hooks_ran "pre-traefik-reboot", "post-traefik-reboot"
assert_match /Rebooting Traefik on vm1,vm2.../, output
assert_match /Rebooted Traefik on vm1,vm2/, output

output = kamal :traefik, :reboot, :"--rolling", capture: true
assert_traefik_running
assert_hooks_ran "pre-traefik-reboot", "post-traefik-reboot"
assert_match /Rebooting Traefik on vm1.../, output
assert_match /Rebooted Traefik on vm1/, output
assert_match /Rebooting Traefik on vm2.../, output
assert_match /Rebooted Traefik on vm2/, output

kamal :traefik, :boot
assert_traefik_running
Expand Down

0 comments on commit a0959b5

Please sign in to comment.