Traefik hosts can now be more than just web

This commit is contained in:
David Heinemeier Hansson
2023-01-20 13:38:57 +01:00
parent 2cb09be0cd
commit 8a32cc9c84
4 changed files with 21 additions and 9 deletions

View File

@@ -3,17 +3,17 @@ require "mrsk/cli/base"
class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "boot", "Boot Traefik on servers"
def boot
on(MRSK.config.role(:web).hosts) { execute *MRSK.traefik.run, raise_on_non_zero_exit: false }
on(MRSK.config.traefik_hosts) { execute *MRSK.traefik.run, raise_on_non_zero_exit: false }
end
desc "start", "Start existing Traefik on servers"
def start
on(MRSK.config.role(:web).hosts) { execute *MRSK.traefik.start, raise_on_non_zero_exit: false }
on(MRSK.config.traefik_hosts) { execute *MRSK.traefik.start, raise_on_non_zero_exit: false }
end
desc "stop", "Stop Traefik on servers"
def stop
on(MRSK.config.role(:web).hosts) { execute *MRSK.traefik.stop, raise_on_non_zero_exit: false }
on(MRSK.config.traefik_hosts) { execute *MRSK.traefik.stop, raise_on_non_zero_exit: false }
end
desc "restart", "Restart Traefik on servers"
@@ -24,7 +24,7 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "details", "Display details about Traefik containers from servers"
def details
on(MRSK.config.role(:web).hosts) { |host| puts "Traefik Host: #{host}\n" + capture(*MRSK.traefik.info, verbosity: Logger::INFO) + "\n\n" }
on(MRSK.config.traefik_hosts) { |host| puts "Traefik Host: #{host}\n" + capture(*MRSK.traefik.info, verbosity: Logger::INFO) + "\n\n" }
end
desc "logs", "Show last 100 log lines from Traefik on servers"
@@ -36,7 +36,7 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
def remove
invoke :stop
on(MRSK.config.role(:web).hosts) do
on(MRSK.config.traefik_hosts) do
execute *MRSK.traefik.remove_container
execute *MRSK.traefik.remove_image
end

View File

@@ -71,6 +71,10 @@ class Mrsk::Configuration
role(:web).hosts.first
end
def traefik_hosts
roles.select(&:running_traefik?).flat_map(&:hosts)
end
def version
@version ||= ENV["VERSION"] || `git rev-parse HEAD`.strip

View File

@@ -31,6 +31,10 @@ class Mrsk::Configuration::Role
specializations["cmd"]
end
def running_traefik?
name.web? || specializations["traefik"]
end
private
attr_accessor :config
@@ -61,10 +65,6 @@ class Mrsk::Configuration::Role
end
end
def running_traefik?
name.web? || specializations["traefik"]
end
def custom_labels
Hash.new.tap do |labels|
labels.merge!(config.labels) if config.labels.present?

View File

@@ -70,6 +70,14 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal "1.1.1.1", @config_with_roles.primary_host
end
test "traefik hosts" do
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.traefik_hosts
@deploy_with_roles[:servers]["workers"]["traefik"] = true
config = Mrsk::Configuration.new(@deploy_with_roles)
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], config.traefik_hosts
end
test "version" do
assert_equal "123", @config.version