Move audits back to run dir so they survive kamal remove

This commit is contained in:
Donal McBreen
2024-09-12 16:05:56 +01:00
parent b8972a6833
commit 35fe9c154d
3 changed files with 13 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base
# Runs remotely # Runs remotely
def record(line, **details) def record(line, **details)
combine \ combine \
[ :mkdir, "-p", config.service_directory ], [ :mkdir, "-p", config.run_directory ],
append( append(
[ :echo, audit_tags(**details).except(:version, :service_version, :service).to_s, line ], [ :echo, audit_tags(**details).except(:version, :service_version, :service).to_s, line ],
audit_log_file audit_log_file
@@ -22,7 +22,9 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base
private private
def audit_log_file def audit_log_file
File.join config.service_directory, "audit.log" file = [ config.service, config.destination, "audit.log" ].compact.join("-")
File.join(config.run_directory, file)
end end
def audit_tags(**details) def audit_tags(**details)

View File

@@ -305,7 +305,7 @@ class CliMainTest < CliTestCase
test "audit" do test "audit" do
run_command("audit").tap do |output| run_command("audit").tap do |output|
assert_match %r{tail -n 50 \.kamal/apps/app/audit.log on 1.1.1.1}, output assert_match %r{tail -n 50 \.kamal/app-audit.log on 1.1.1.1}, output
assert_match /App Host: 1.1.1.1/, output assert_match /App Host: 1.1.1.1/, output
end end
end end

View File

@@ -18,22 +18,22 @@ class CommandsAuditorTest < ActiveSupport::TestCase
test "record" do test "record" do
assert_equal [ assert_equal [
:mkdir, "-p", ".kamal/apps/app", "&&", :mkdir, "-p", ".kamal", "&&",
:echo, :echo,
"[#{@recorded_at}] [#{@performer}]", "[#{@recorded_at}] [#{@performer}]",
"app removed container", "app removed container",
">>", ".kamal/apps/app/audit.log" ">>", ".kamal/app-audit.log"
], @auditor.record("app removed container") ], @auditor.record("app removed container")
end end
test "record with destination" do test "record with destination" do
new_command(destination: "staging").tap do |auditor| new_command(destination: "staging").tap do |auditor|
assert_equal [ assert_equal [
:mkdir, "-p", ".kamal/apps/app-staging", "&&", :mkdir, "-p", ".kamal", "&&",
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [staging]", "[#{@recorded_at}] [#{@performer}] [staging]",
"app removed container", "app removed container",
">>", ".kamal/apps/app-staging/audit.log" ">>", ".kamal/app-staging-audit.log"
], auditor.record("app removed container") ], auditor.record("app removed container")
end end
end end
@@ -41,22 +41,22 @@ class CommandsAuditorTest < ActiveSupport::TestCase
test "record with command details" do test "record with command details" do
new_command(role: "web").tap do |auditor| new_command(role: "web").tap do |auditor|
assert_equal [ assert_equal [
:mkdir, "-p", ".kamal/apps/app", "&&", :mkdir, "-p", ".kamal", "&&",
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [web]", "[#{@recorded_at}] [#{@performer}] [web]",
"app removed container", "app removed container",
">>", ".kamal/apps/app/audit.log" ">>", ".kamal/app-audit.log"
], auditor.record("app removed container") ], auditor.record("app removed container")
end end
end end
test "record with arg details" do test "record with arg details" do
assert_equal [ assert_equal [
:mkdir, "-p", ".kamal/apps/app", "&&", :mkdir, "-p", ".kamal", "&&",
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [value]", "[#{@recorded_at}] [#{@performer}] [value]",
"app removed container", "app removed container",
">>", ".kamal/apps/app/audit.log" ">>", ".kamal/app-audit.log"
], @auditor.record("app removed container", detail: "value") ], @auditor.record("app removed container", detail: "value")
end end