From f1f3fc566f6f8b9cda48cab737c8faf177258df9 Mon Sep 17 00:00:00 2001 From: Nick Hammond Date: Thu, 27 Jun 2024 10:26:11 -0600 Subject: [PATCH 1/2] Add ENV['SERVICE'] to hooks --- lib/kamal/tags.rb | 3 ++- test/cli/cli_test_case.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/kamal/tags.rb b/lib/kamal/tags.rb index 4538f28d..95145f29 100644 --- a/lib/kamal/tags.rb +++ b/lib/kamal/tags.rb @@ -13,7 +13,8 @@ class Kamal::Tags performer: `whoami`.chomp, destination: config.destination, version: config.version, - service_version: service_version(config) } + service_version: service_version(config), + service: config.service } end def service_version(config) diff --git a/test/cli/cli_test_case.rb b/test/cli/cli_test_case.rb index 5db20c05..a680824c 100644 --- a/test/cli/cli_test_case.rb +++ b/test/cli/cli_test_case.rb @@ -43,6 +43,7 @@ class CliTestCase < ActiveSupport::TestCase def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: false) performer = `whoami`.strip + service = service_version.split("@").first assert_match "Running the #{hook} hook...\n", output @@ -52,6 +53,7 @@ class CliTestCase < ActiveSupport::TestCase KAMAL_PERFORMER=\"#{performer}\"\s KAMAL_VERSION=\"#{version}\"\s KAMAL_SERVICE_VERSION=\"#{service_version}\"\s + KAMAL_SERVICE=\"#{service}\"\s KAMAL_HOSTS=\"#{hosts}\"\s KAMAL_COMMAND=\"#{command}\"\s #{"KAMAL_SUBCOMMAND=\\\"#{subcommand}\\\"\\s" if subcommand} From 58a51b079e7cc7d1344f3e08cc5b548148b5a6c7 Mon Sep 17 00:00:00 2001 From: Nick Hammond Date: Thu, 27 Jun 2024 10:52:55 -0600 Subject: [PATCH 2/2] Add KAMAL_SERVICE to custom hooks and exclude from auditor --- lib/kamal/commands/auditor.rb | 2 +- test/commands/hook_test.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/kamal/commands/auditor.rb b/lib/kamal/commands/auditor.rb index 3e1a71a7..f0c0850d 100644 --- a/lib/kamal/commands/auditor.rb +++ b/lib/kamal/commands/auditor.rb @@ -9,7 +9,7 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base # Runs remotely def record(line, **details) append \ - [ :echo, audit_tags(**details).except(:version, :service_version).to_s, line ], + [ :echo, audit_tags(**details).except(:version, :service_version, :service).to_s, line ], audit_log_file end diff --git a/test/commands/hook_test.rb b/test/commands/hook_test.rb index 688c7156..932c92f2 100644 --- a/test/commands/hook_test.rb +++ b/test/commands/hook_test.rb @@ -22,7 +22,8 @@ class CommandsHookTest < ActiveSupport::TestCase "KAMAL_RECORDED_AT" => @recorded_at, "KAMAL_PERFORMER" => @performer, "KAMAL_VERSION" => "123", - "KAMAL_SERVICE_VERSION" => "app@123" } } + "KAMAL_SERVICE_VERSION" => "app@123", + "KAMAL_SERVICE" => "app" } } ], new_command.run("foo") end @@ -33,7 +34,8 @@ class CommandsHookTest < ActiveSupport::TestCase "KAMAL_RECORDED_AT" => @recorded_at, "KAMAL_PERFORMER" => @performer, "KAMAL_VERSION" => "123", - "KAMAL_SERVICE_VERSION" => "app@123" } } + "KAMAL_SERVICE_VERSION" => "app@123", + "KAMAL_SERVICE" => "app" } } ], new_command(hooks_path: "custom/hooks/path").run("foo") end