Put locks directories in .kamal so they leave no trace when deleted
This commit is contained in:
@@ -207,12 +207,12 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "remove_app_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host", hide: true
|
desc "remove_service_directory [NAME]", "Remove accessory directory used for uploaded files and data directories from host", hide: true
|
||||||
def remove_app_directory(name)
|
def remove_service_directory(name)
|
||||||
with_lock do
|
with_lock do
|
||||||
with_accessory(name) do |accessory, hosts|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(hosts) do
|
on(hosts) do
|
||||||
execute *accessory.remove_app_directory
|
execute *accessory.remove_service_directory
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -248,7 +248,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
stop(name)
|
stop(name)
|
||||||
remove_container(name)
|
remove_container(name)
|
||||||
remove_image(name)
|
remove_image(name)
|
||||||
remove_app_directory(name)
|
remove_service_directory(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare(name)
|
def prepare(name)
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
|
|
||||||
roles.each do |role|
|
roles.each do |role|
|
||||||
execute *KAMAL.auditor.record("Removed #{KAMAL.config.app_directory} on all servers", role: role), verbosity: :debug
|
execute *KAMAL.auditor.record("Removed #{KAMAL.config.app_directory} on all servers", role: role), verbosity: :debug
|
||||||
execute *KAMAL.server.remove_app_directory
|
execute *KAMAL.server.remove_app_directory, raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ module Kamal::Cli
|
|||||||
end
|
end
|
||||||
|
|
||||||
def acquire_lock
|
def acquire_lock
|
||||||
ensure_app_and_locks_directory
|
ensure_run_directory
|
||||||
|
|
||||||
raise_if_locked do
|
raise_if_locked do
|
||||||
say "Acquiring the deploy lock...", :magenta
|
say "Acquiring the deploy lock...", :magenta
|
||||||
@@ -174,13 +174,9 @@ module Kamal::Cli
|
|||||||
instance_variable_get("@_invocations").first
|
instance_variable_get("@_invocations").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_app_and_locks_directory
|
def ensure_run_directory
|
||||||
on(KAMAL.hosts) do
|
on(KAMAL.hosts) do
|
||||||
execute(*KAMAL.server.ensure_app_directory)
|
execute(*KAMAL.server.ensure_run_directory)
|
||||||
end
|
|
||||||
|
|
||||||
on(KAMAL.primary_host) do
|
|
||||||
execute(*KAMAL.lock.ensure_locks_directory)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Kamal::Cli::Lock < Kamal::Cli::Base
|
|||||||
option :message, aliases: "-m", type: :string, desc: "A lock message", required: true
|
option :message, aliases: "-m", type: :string, desc: "A lock message", required: true
|
||||||
def acquire
|
def acquire
|
||||||
message = options[:message]
|
message = options[:message]
|
||||||
ensure_app_and_locks_directory
|
ensure_run_directory
|
||||||
|
|
||||||
raise_if_locked do
|
raise_if_locked do
|
||||||
on(KAMAL.primary_host) do
|
on(KAMAL.primary_host) do
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
|
|||||||
with_lock do
|
with_lock do
|
||||||
on(KAMAL.proxy_hosts) do
|
on(KAMAL.proxy_hosts) do
|
||||||
execute *KAMAL.auditor.record("Removed #{KAMAL.config.proxy_directory}"), verbosity: :debug
|
execute *KAMAL.auditor.record("Removed #{KAMAL.config.proxy_directory}"), verbosity: :debug
|
||||||
execute *KAMAL.proxy.remove_host_directory
|
execute *KAMAL.proxy.remove_host_directory, raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_app_directory
|
def remove_service_directory
|
||||||
[ :rm, "-rf", service_name ]
|
[ :rm, "-rf", service_name ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,10 @@ class Kamal::Commands::Lock < Kamal::Commands::Base
|
|||||||
"/dev/null"
|
"/dev/null"
|
||||||
end
|
end
|
||||||
|
|
||||||
def locks_dir
|
|
||||||
File.join(config.run_directory, "locks")
|
|
||||||
end
|
|
||||||
|
|
||||||
def lock_dir
|
def lock_dir
|
||||||
dir_name = [ config.service, config.destination ].compact.join("-")
|
dir_name = [ "lock", config.service, config.destination ].compact.join("-")
|
||||||
|
|
||||||
File.join(locks_dir, dir_name)
|
File.join(config.run_directory, dir_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock_details_file
|
def lock_details_file
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Kamal::Commands::Server < Kamal::Commands::Base
|
class Kamal::Commands::Server < Kamal::Commands::Base
|
||||||
def ensure_app_directory
|
def ensure_run_directory
|
||||||
make_directory config.app_directory
|
make_directory config.run_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_app_directory
|
def remove_app_directory
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class CliAccessoryTest < CliTestCase
|
|||||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
|
||||||
|
|
||||||
run_command("remove", "mysql", "-y")
|
run_command("remove", "mysql", "-y")
|
||||||
end
|
end
|
||||||
@@ -175,11 +175,11 @@ class CliAccessoryTest < CliTestCase
|
|||||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("mysql")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:stop).with("redis")
|
Kamal::Cli::Accessory.any_instance.expects(:stop).with("redis")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("redis")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("redis")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("redis")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("redis")
|
||||||
Kamal::Cli::Accessory.any_instance.expects(:remove_app_directory).with("redis")
|
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("redis")
|
||||||
|
|
||||||
run_command("remove", "all", "-y")
|
run_command("remove", "all", "-y")
|
||||||
end
|
end
|
||||||
@@ -192,8 +192,8 @@ class CliAccessoryTest < CliTestCase
|
|||||||
assert_match "docker image rm --force mysql", run_command("remove_image", "mysql")
|
assert_match "docker image rm --force mysql", run_command("remove_image", "mysql")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "remove_app_directory" do
|
test "remove_service_directory" do
|
||||||
assert_match "rm -rf app-mysql", run_command("remove_app_directory", "mysql")
|
assert_match "rm -rf app-mysql", run_command("remove_service_directory", "mysql")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "hosts param respected" do
|
test "hosts param respected" do
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class CliAppTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "boot uses group strategy when specified" do
|
test "boot uses group strategy when specified" do
|
||||||
Kamal::Cli::App.any_instance.stubs(:on).with("1.1.1.1").times(3) # ensure locks dir, acquire & release lock
|
Kamal::Cli::App.any_instance.stubs(:on).with("1.1.1.1").times(2) # ensure locks dir, acquire & release lock
|
||||||
Kamal::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
Kamal::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
||||||
|
|
||||||
# Strategy is used when booting the containers
|
# Strategy is used when booting the containers
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ class CliTestCase < ActiveSupport::TestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |arg1, arg2, arg3| arg1 == :mkdir && arg2 == "-p" && arg3 == ".kamal/locks" }
|
.with { |arg1, arg2, arg3| arg1 == :mkdir && arg2 == "-p" && arg3 == ".kamal/lock-app" }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |arg1, arg2| arg1 == :mkdir && arg2 == ".kamal/locks/app" }
|
.with { |arg1, arg2| arg1 == :mkdir && arg2 == ".kamal/lock-app" }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |arg1, arg2| arg1 == :rm && arg2 == ".kamal/locks/app/details" }
|
.with { |arg1, arg2| arg1 == :rm && arg2 == ".kamal/lock-app/details" }
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with(:docker, :buildx, :inspect, "kamal-local-docker-container")
|
.with(:docker, :buildx, :inspect, "kamal-local-docker-container")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require_relative "cli_test_case"
|
|||||||
class CliLockTest < CliTestCase
|
class CliLockTest < CliTestCase
|
||||||
test "status" do
|
test "status" do
|
||||||
run_command("status").tap do |output|
|
run_command("status").tap do |output|
|
||||||
assert_match "Running /usr/bin/env stat .kamal/locks/app > /dev/null && cat .kamal/locks/app/details | base64 -d on 1.1.1.1", output
|
assert_match "Running /usr/bin/env stat .kamal/lock-app > /dev/null && cat .kamal/lock-app/details | base64 -d on 1.1.1.1", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -100,14 +100,11 @@ class CliMainTest < CliTestCase
|
|||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal/locks" ] }
|
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/lock-app" ] }
|
||||||
|
.raises(RuntimeError, "mkdir: cannot create directory ‘kamal/lock-app’: File exists")
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
|
||||||
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/locks/app" ] }
|
|
||||||
.raises(RuntimeError, "mkdir: cannot create directory ‘kamal/locks/app’: File exists")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
|
||||||
.with(:stat, ".kamal/locks/app", ">", "/dev/null", "&&", :cat, ".kamal/locks/app/details", "|", :base64, "-d")
|
.with(:stat, ".kamal/lock-app", ">", "/dev/null", "&&", :cat, ".kamal/lock-app/details", "|", :base64, "-d")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:git, "-C", anything, :"rev-parse", :HEAD)
|
.with(:git, "-C", anything, :"rev-parse", :HEAD)
|
||||||
@@ -137,10 +134,7 @@ class CliMainTest < CliTestCase
|
|||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
.with { |*args| args == [ :mkdir, "-p", ".kamal/apps/app" ] }
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
.with { |*args| args == [ :mkdir, "-p", ".kamal/locks" ] }
|
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/lock-app" ] }
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
|
||||||
.with { |*arg| arg[0..1] == [ :mkdir, ".kamal/locks/app" ] }
|
|
||||||
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")
|
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class CliServerTest < CliTestCase
|
|||||||
test "bootstrap already installed" do
|
test "bootstrap already installed" do
|
||||||
stub_setup
|
stub_setup
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal/apps/app").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
|
|
||||||
assert_equal "Acquiring the deploy lock...\nReleasing the deploy lock...", run_command("bootstrap")
|
assert_equal "Acquiring the deploy lock...\nReleasing the deploy lock...", run_command("bootstrap")
|
||||||
end
|
end
|
||||||
@@ -41,7 +41,7 @@ class CliServerTest < CliTestCase
|
|||||||
stub_setup
|
stub_setup
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal/apps/app").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
|
|
||||||
assert_raise RuntimeError, "Docker is not installed on 1.1.1.1, 1.1.1.3, 1.1.1.4, 1.1.1.2 and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" do
|
assert_raise RuntimeError, "Docker is not installed on 1.1.1.1, 1.1.1.3, 1.1.1.4, 1.1.1.2 and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" do
|
||||||
run_command("bootstrap")
|
run_command("bootstrap")
|
||||||
@@ -53,7 +53,7 @@ class CliServerTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:sh, "-c", "'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \"exit 1\"'", "|", :sh).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:sh, "-c", "'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \"exit 1\"'", "|", :sh).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal/apps/app").returns("").at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once
|
||||||
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/pre-connect", anything).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/pre-connect", anything).at_least_once
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/docker-setup", anything).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/docker-setup", anything).at_least_once
|
||||||
|
|||||||
@@ -10,19 +10,19 @@ class CommandsLockTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "status" do
|
test "status" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"stat .kamal/locks/app-production > /dev/null && cat .kamal/locks/app-production/details | base64 -d",
|
"stat .kamal/lock-app-production > /dev/null && cat .kamal/lock-app-production/details | base64 -d",
|
||||||
new_command.status.join(" ")
|
new_command.status.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "acquire" do
|
test "acquire" do
|
||||||
assert_match \
|
assert_match \
|
||||||
%r{mkdir \.kamal/locks/app-production && echo ".*" > \.kamal/locks/app-production/details}m,
|
%r{mkdir \.kamal/lock-app-production && echo ".*" > \.kamal/lock-app-production/details}m,
|
||||||
new_command.acquire("Hello", "123").join(" ")
|
new_command.acquire("Hello", "123").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "release" do
|
test "release" do
|
||||||
assert_match \
|
assert_match \
|
||||||
"rm .kamal/locks/app-production/details && rm -r .kamal/locks/app-production",
|
"rm .kamal/lock-app-production/details && rm -r .kamal/lock-app-production",
|
||||||
new_command.release.join(" ")
|
new_command.release.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class CommandsServerTest < ActiveSupport::TestCase
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ensure service directory" do
|
test "ensure run directory" do
|
||||||
assert_equal "mkdir -p .kamal/apps/app", new_command.ensure_app_directory.join(" ")
|
assert_equal "mkdir -p .kamal", new_command.ensure_run_directory.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
Reference in New Issue
Block a user