Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove accessory env file from host, when accessory is removed #615

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def logs(name)
end
end

desc "remove [NAME]", "Remove accessory container, image and data directory from host (use NAME=all to remove all accessories)"
desc "remove [NAME]", "Remove accessory container, image, data directory and env file from host (use NAME=all to remove all accessories)"
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
def remove(name)
confirming "This will remove all containers, images and data directories for #{name}. Are you sure?" do
Expand Down Expand Up @@ -222,6 +222,17 @@ def remove_service_directory(name)
end
end

desc "remove_env_file [NAME]", "Remove accessory env file from host", hide: true
def remove_env_file(name)
with_lock do
with_accessory(name) do |accessory, hosts|
on(hosts) do
execute *accessory.remove_env_file
end
end
end
end

private
def with_accessory(name)
if KAMAL.config.accessory(name)
Expand Down Expand Up @@ -254,6 +265,7 @@ def remove_accessory(name)
remove_container(name)
remove_image(name)
remove_service_directory(name)
remove_env_file(name)
end
end
end
7 changes: 7 additions & 0 deletions test/cli/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CliAccessoryTest < CliTestCase
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_service_directory).with("mysql")
Kamal::Cli::Accessory.any_instance.expects(:remove_env_file).with("mysql")

run_command("remove", "mysql", "-y")
end
Expand All @@ -165,10 +166,12 @@ class CliAccessoryTest < CliTestCase
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_service_directory).with("mysql")
Kamal::Cli::Accessory.any_instance.expects(:remove_env_file).with("mysql")
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_image).with("redis")
Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("redis")
Kamal::Cli::Accessory.any_instance.expects(:remove_env_file).with("redis")

run_command("remove", "all", "-y")
end
Expand All @@ -185,6 +188,10 @@ class CliAccessoryTest < CliTestCase
assert_match "rm -rf app-mysql", run_command("remove_service_directory", "mysql")
end

test "remove_env_file" do
assert_match "rm -f .kamal/env/accessories/app-mysql.env", run_command("remove_env_file", "mysql")
end

test "hosts param respected" do
Kamal::Cli::Accessory.any_instance.expects(:directories).with("redis")
Kamal::Cli::Accessory.any_instance.expects(:upload).with("redis")
Expand Down