Configurable Kamal directory

To avoid polluting the default SSH directory with lots of Kamal config,
we'll default to putting them in a `kamal` sub directory.

But also make the directory configurable with the `run_directory` key,
so for example you can set it as `/var/run/kamal/`

The directory is created during bootstrap or before any command that
will need to access a file.
This commit is contained in:
Donal McBreen
2023-08-28 16:12:56 +01:00
parent 9363b6a464
commit bcfa1d83e8
17 changed files with 101 additions and 23 deletions

View File

@@ -21,7 +21,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo,
"[#{@recorded_at}] [#{@performer}]",
"app removed container",
">>", "kamal-app-audit.log"
">>", "kamal/app-audit.log"
], @auditor.record("app removed container")
end
@@ -31,7 +31,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo,
"[#{@recorded_at}] [#{@performer}] [staging]",
"app removed container",
">>", "kamal-app-staging-audit.log"
">>", "kamal/app-staging-audit.log"
], auditor.record("app removed container")
end
end
@@ -42,7 +42,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo,
"[#{@recorded_at}] [#{@performer}] [web]",
"app removed container",
">>", "kamal-app-audit.log"
">>", "kamal/app-audit.log"
], auditor.record("app removed container")
end
end
@@ -52,7 +52,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo,
"[#{@recorded_at}] [#{@performer}] [value]",
"app removed container",
">>", "kamal-app-audit.log"
">>", "kamal/app-audit.log"
], @auditor.record("app removed container", detail: "value")
end

View File

@@ -10,19 +10,19 @@ class CommandsLockTest < ActiveSupport::TestCase
test "status" do
assert_equal \
"stat kamal_lock-app > /dev/null && cat kamal_lock-app/details | base64 -d",
"stat kamal/lock-app > /dev/null && cat kamal/lock-app/details | base64 -d",
new_command.status.join(" ")
end
test "acquire" do
assert_match \
/mkdir kamal_lock-app && echo ".*" > kamal_lock-app\/details/m,
%r{mkdir kamal/lock-app && echo ".*" > kamal/lock-app/details}m,
new_command.acquire("Hello", "123").join(" ")
end
test "release" do
assert_match \
"rm kamal_lock-app/details && rm -r kamal_lock-app",
"rm kamal/lock-app/details && rm -r kamal/lock-app",
new_command.release.join(" ")
end

View File

@@ -0,0 +1,23 @@
require "test_helper"
class CommandsServerTest < ActiveSupport::TestCase
setup do
@config = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ],
traefik: { "args" => { "accesslog.format" => "json", "metrics.prometheus.buckets" => "0.1,0.3,1.2,5.0" } }
}
end
test "ensure run directory" do
assert_equal "mkdir -p kamal", new_command.ensure_run_directory.join(" ")
end
test "ensure non default run directory" do
assert_equal "mkdir -p /var/run/kamal", new_command(run_directory: "/var/run/kamal").ensure_run_directory.join(" ")
end
private
def new_command(extra_config = {})
Kamal::Commands::Server.new(Kamal::Configuration.new(@config.merge(extra_config)))
end
end