From 47f8725cf3f5d243e06fc73c6fd29387faf07bc8 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Fri, 10 Nov 2023 16:35:25 -0800 Subject: [PATCH] Support a dynamic primary_web_role instead of assuming it's 'web'. This allows for more meaningful naming in roles. The only caution here is that we don't support the renaming of roles, so any migration is left to the user. --- lib/kamal/commands/healthcheck.rb | 2 +- lib/kamal/configuration.rb | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/kamal/commands/healthcheck.rb b/lib/kamal/commands/healthcheck.rb index 5adc0244..05379ab6 100644 --- a/lib/kamal/commands/healthcheck.rb +++ b/lib/kamal/commands/healthcheck.rb @@ -1,7 +1,7 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base def run - web = config.role(:web) + web = config.role(config.primary_web_role) docker :run, "--detach", diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index fc881c06..64c74c63 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -90,14 +90,21 @@ class Kamal::Configuration end def primary_web_host - role(:web).primary_host + role(primary_web_role)&.primary_host + end + + def traefik_roles + roles.select(&:running_traefik?) + end + + def traefik_role_names + traefik_roles.flat_map(&:name) end def traefik_hosts - roles.select(&:running_traefik?).flat_map(&:hosts).uniq + traefik_roles.flat_map(&:hosts).uniq end - def repository [ raw_config.registry["server"], image ].compact.join("/") end @@ -199,6 +206,9 @@ class Kamal::Configuration raw_config.asset_path end + def primary_web_role + raw_config.primary_web_role || "web" + end def valid? ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version @@ -253,6 +263,10 @@ class Kamal::Configuration end end + unless traefik_role_names.include?(primary_web_role) + raise ArgumentError, "Role #{primary_web_role} needs to have traefik enabled" + end + true end