Merge pull request #1507 from basecamp/fix-accessory-setup
Fix accessory setup
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
require "active_support/core_ext/array/conversions"
|
require "active_support/core_ext/array/conversions"
|
||||||
|
require "concurrent/array"
|
||||||
|
|
||||||
class Kamal::Cli::Accessory < Kamal::Cli::Base
|
class Kamal::Cli::Accessory < Kamal::Cli::Base
|
||||||
desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)"
|
desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)"
|
||||||
@@ -10,6 +11,16 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
prepare(name) if prepare
|
prepare(name) if prepare
|
||||||
|
|
||||||
with_accessory(name) do |accessory, hosts|
|
with_accessory(name) do |accessory, hosts|
|
||||||
|
booted_hosts = Concurrent::Array.new
|
||||||
|
on(hosts) do |host|
|
||||||
|
booted_hosts << host.to_s if capture_with_info(*accessory.info(all: true, quiet: true)).strip.presence
|
||||||
|
end
|
||||||
|
|
||||||
|
if booted_hosts.any?
|
||||||
|
say "Skipping booting `#{name}` on #{booted_hosts.sort.join(", ")}, a container already exists", :yellow
|
||||||
|
hosts -= booted_hosts
|
||||||
|
end
|
||||||
|
|
||||||
directories(name)
|
directories(name)
|
||||||
upload(name)
|
upload(name)
|
||||||
|
|
||||||
@@ -275,11 +286,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def accessory_hosts(accessory)
|
def accessory_hosts(accessory)
|
||||||
if KAMAL.specific_hosts&.any?
|
KAMAL.accessory_hosts & accessory.hosts
|
||||||
KAMAL.specific_hosts & accessory.hosts
|
|
||||||
else
|
|
||||||
accessory.hosts
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_accessory(name)
|
def remove_accessory(name)
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
docker :container, :stop, service_name
|
docker :container, :stop, service_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
def info(all: false, quiet: false)
|
||||||
docker :ps, *service_filter
|
docker :ps, *("-a" if all), *("-q" if quiet), *service_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
|
def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
|
||||||
|
|||||||
@@ -251,6 +251,19 @@ class CliAccessoryTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "boot with web role filter" do
|
||||||
|
run_command("boot", "redis", "-r", "web").tap do |output|
|
||||||
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --network kamal --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/apps/app/env/accessories/redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --network kamal --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/apps/app/env/accessories/redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "boot with workers role filter" do
|
||||||
|
run_command("boot", "redis", "-r", "workers").tap do |output|
|
||||||
|
assert_no_match "docker run", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_command(*command)
|
def run_command(*command)
|
||||||
stdouted { Kamal::Cli::Accessory.start([ *command, "-c", "test/fixtures/deploy_with_accessories_with_different_registries.yml" ]) }
|
stdouted { Kamal::Cli::Accessory.start([ *command, "-c", "test/fixtures/deploy_with_accessories_with_different_registries.yml" ]) }
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class AccessoryTest < IntegrationTest
|
|||||||
logs = kamal :accessory, :logs, :busybox, capture: true
|
logs = kamal :accessory, :logs, :busybox, capture: true
|
||||||
assert_match /Starting busybox.../, logs
|
assert_match /Starting busybox.../, logs
|
||||||
|
|
||||||
|
boot = kamal :accessory, :boot, :busybox, capture: true
|
||||||
|
assert_match /Skipping booting `busybox` on vm1, vm2, a container already exists/, boot
|
||||||
|
|
||||||
kamal :accessory, :remove, :busybox, "-y"
|
kamal :accessory, :remove, :busybox, "-y"
|
||||||
assert_accessory_not_running :busybox
|
assert_accessory_not_running :busybox
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class IntegrationTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
if !passed? && ENV["DEBUG"]
|
if !passed? && ENV["DEBUG_CONTAINER_LOGS"]
|
||||||
[ :deployer, :vm1, :vm2, :shared, :load_balancer, :registry ].each do |container|
|
[ :deployer, :vm1, :vm2, :shared, :load_balancer, :registry ].each do |container|
|
||||||
puts
|
puts
|
||||||
puts "Logs for #{container}:"
|
puts "Logs for #{container}:"
|
||||||
|
|||||||
Reference in New Issue
Block a user