Added tests for accessory deploy and remove commands
This commit is contained in:
@@ -18,7 +18,11 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
execute *accessory.ensure_env_directory
|
execute *accessory.ensure_env_directory
|
||||||
upload! accessory.secrets_io, accessory.secrets_path, mode: "0600"
|
upload! accessory.secrets_io, accessory.secrets_path, mode: "0600"
|
||||||
execute *accessory.run
|
execute *accessory.run
|
||||||
execute *accessory.deploy if accessory.running_proxy?
|
|
||||||
|
if accessory.running_proxy?
|
||||||
|
target = accessory.container_id_for(container_name: accessory.service_name, only_running: true)
|
||||||
|
execute *accessory.deploy(target: target)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -76,7 +80,10 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
on(hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.start
|
execute *accessory.start
|
||||||
execute *accessory.deploy if accessory.running_proxy?
|
if accessory.running_proxy?
|
||||||
|
target = container_id_for(container_name: service_name, only_running: true)
|
||||||
|
execute *accessory.deploy(target: target)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -89,7 +96,11 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
on(hosts) do
|
on(hosts) do
|
||||||
execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.stop, raise_on_non_zero_exit: false
|
execute *accessory.stop, raise_on_non_zero_exit: false
|
||||||
execute *accessory.remove if accessory.running_proxy?
|
|
||||||
|
if accessory.running_proxy?
|
||||||
|
target = accessory.container_id_for(container_name: accessory.service_name, only_running: true)
|
||||||
|
execute *accessory.remove(target: target)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
docker :ps, *service_filter
|
docker :ps, *service_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy
|
def deploy(target:)
|
||||||
target = container_id_for(container_name: service_name, only_running: true)
|
proxy_exec :deploy, service_name, *accessory_config.proxy.deploy_command_args(target: target)
|
||||||
proxy_exec :deploy, service_name, *accessory_config.proxy.deploy_command_args(target: target) if target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove
|
def remove(target:)
|
||||||
target = container_id_for(container_name: service_name, only_running: true)
|
proxy_exec :remove, service_name, *accessory_config.proxy.remove_command_args(target: target)
|
||||||
proxy_exec :remove, service_name, *accessory_config.proxy.remove_command_args(target: target) if target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
"busybox" => {
|
"busybox" => {
|
||||||
"service" => "custom-busybox",
|
"service" => "custom-busybox",
|
||||||
"image" => "busybox:latest",
|
"image" => "busybox:latest",
|
||||||
"host" => "1.1.1.7"
|
"host" => "1.1.1.7",
|
||||||
|
"proxy" => {
|
||||||
|
"host" => "busybox.example.com"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,6 +169,18 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
new_command(:mysql).remove_image.join(" ")
|
new_command(:mysql).remove_image.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "deploy" do
|
||||||
|
assert_equal \
|
||||||
|
"docker exec kamal-proxy kamal-proxy deploy custom-busybox --target \"172.1.0.2:80\" --deploy-timeout \"30s\" --drain-timeout \"30s\" --buffer-requests --buffer-responses --log-request-header \"Cache-Control\" --log-request-header \"Last-Modified\" --log-request-header \"User-Agent\"",
|
||||||
|
new_command(:busybox).deploy(target: "172.1.0.2").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "remove" do
|
||||||
|
assert_equal \
|
||||||
|
"docker exec kamal-proxy kamal-proxy remove custom-busybox --target \"172.1.0.2:80\"",
|
||||||
|
new_command(:busybox).remove(target: "172.1.0.2").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def new_command(accessory)
|
def new_command(accessory)
|
||||||
Kamal::Commands::Accessory.new(Kamal::Configuration.new(@config), name: accessory)
|
Kamal::Commands::Accessory.new(Kamal::Configuration.new(@config), name: accessory)
|
||||||
|
|||||||
Reference in New Issue
Block a user