Allow accessory only configurations
If there are accessories defined in the configuration, we'll not require servers to be defined as well. This allows for accessory-only configurations which allows you to run external images with kamal-proxy for zero-downtime deployments. We don't manage image cleanup for accessories though so the user will need to deal with that themselves.
This commit is contained in:
@@ -30,7 +30,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
%i[ service image registry ].each do |key|
|
||||
test "#{key} config required" do
|
||||
assert_raise(Kamal::ConfigurationError) do
|
||||
Kamal::Configuration.new @deploy.tap { _1.delete key }
|
||||
Kamal::Configuration.new @deploy.tap { |config| config.delete key }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -38,21 +38,36 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
%w[ username password ].each do |key|
|
||||
test "registry #{key} required" do
|
||||
assert_raise(Kamal::ConfigurationError) do
|
||||
Kamal::Configuration.new @deploy.tap { _1[:registry].delete key }
|
||||
Kamal::Configuration.new @deploy.tap { |config| config[:registry].delete key }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "service name valid" do
|
||||
assert_nothing_raised do
|
||||
Kamal::Configuration.new(@deploy.tap { _1[:service] = "hey-app1_primary" })
|
||||
Kamal::Configuration.new(@deploy.tap { _1[:service] = "MyApp" })
|
||||
Kamal::Configuration.new(@deploy.tap { |config| config[:service] = "hey-app1_primary" })
|
||||
Kamal::Configuration.new(@deploy.tap { |config| config[:service] = "MyApp" })
|
||||
end
|
||||
end
|
||||
|
||||
test "service name invalid" do
|
||||
assert_raise(Kamal::ConfigurationError) do
|
||||
Kamal::Configuration.new @deploy.tap { _1[:service] = "app.com" }
|
||||
Kamal::Configuration.new @deploy.tap { |config| config[:service] = "app.com" }
|
||||
end
|
||||
end
|
||||
|
||||
test "servers required" do
|
||||
assert_raise(Kamal::ConfigurationError) do
|
||||
Kamal::Configuration.new @deploy.tap { |config| config.delete(:servers) }
|
||||
end
|
||||
end
|
||||
|
||||
test "servers not required with accessories" do
|
||||
assert_nothing_raised do
|
||||
@deploy.delete(:servers)
|
||||
@deploy[:accessories] = { "foo" => { "image" => "foo/bar", "host" => "1.1.1.1" } }
|
||||
|
||||
Kamal::Configuration.new(@deploy)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -250,7 +265,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
test "destination required" do
|
||||
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_required_dest.yml", __dir__))
|
||||
|
||||
assert_raises(Kamal::ConfigurationError) do
|
||||
assert_raises(ArgumentError, "You must specify a destination") do
|
||||
config = Kamal::Configuration.create_from config_file: dest_config_file
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,32 @@ class AccessoryTest < IntegrationTest
|
||||
assert_accessory_not_running :busybox
|
||||
end
|
||||
|
||||
test "proxied: boot, stop, start, restart, logs, remove" do
|
||||
@app = "app_with_proxied_accessory"
|
||||
|
||||
kamal :proxy, :boot
|
||||
|
||||
kamal :accessory, :boot, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :stop, :netcat
|
||||
assert_accessory_not_running :netcat
|
||||
assert_netcat_not_found
|
||||
|
||||
kamal :accessory, :start, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :restart, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :remove, :netcat, "-y"
|
||||
assert_accessory_not_running :netcat
|
||||
assert_netcat_not_found
|
||||
end
|
||||
|
||||
private
|
||||
def assert_accessory_running(name)
|
||||
assert_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
||||
@@ -33,4 +59,25 @@ class AccessoryTest < IntegrationTest
|
||||
def accessory_details(name)
|
||||
kamal :accessory, :details, name, capture: true
|
||||
end
|
||||
|
||||
def assert_netcat_is_up
|
||||
response = netcat_response
|
||||
debug_response_code(response, "200")
|
||||
assert_equal "200", response.code
|
||||
end
|
||||
|
||||
def assert_netcat_not_found
|
||||
response = netcat_response
|
||||
debug_response_code(response, "404")
|
||||
assert_equal "404", response.code
|
||||
end
|
||||
|
||||
def netcat_response
|
||||
uri = URI.parse("http://127.0.0.1:12345/up")
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Get.new(uri)
|
||||
request["Host"] = "netcat"
|
||||
|
||||
http.request(request)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
service: app_with_proxied_accessory
|
||||
image: app_with_proxied_accessory
|
||||
servers:
|
||||
- vm1
|
||||
env:
|
||||
clear:
|
||||
CLEAR_TOKEN: 4321
|
||||
@@ -24,15 +22,13 @@ accessories:
|
||||
service: custom-busybox
|
||||
image: registry:4443/busybox:1.36.0
|
||||
cmd: sh -c 'echo "Starting busybox..."; trap exit term; while true; do sleep 1; done'
|
||||
roles:
|
||||
- web
|
||||
host: vm1
|
||||
netcat:
|
||||
service: netcat
|
||||
image: registry:4443/busybox:1.36.0
|
||||
cmd: >
|
||||
sh -c 'echo "Starting netcat..."; while true; do echo -e "HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello Ruby" | nc -l -p 80; done'
|
||||
roles:
|
||||
- web
|
||||
host: vm1
|
||||
port: 12345:80
|
||||
proxy:
|
||||
host: netcat
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
require_relative "integration_test"
|
||||
|
||||
class ProxiedAccessoryTest < IntegrationTest
|
||||
test "boot, stop, start, restart, logs, remove" do
|
||||
@app = "app_with_proxied_accessory"
|
||||
|
||||
kamal :deploy
|
||||
|
||||
kamal :accessory, :boot, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :stop, :netcat
|
||||
assert_accessory_not_running :netcat
|
||||
assert_netcat_not_found
|
||||
|
||||
kamal :accessory, :start, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :restart, :netcat
|
||||
assert_accessory_running :netcat
|
||||
assert_netcat_is_up
|
||||
|
||||
kamal :accessory, :remove, :netcat, "-y"
|
||||
assert_accessory_not_running :netcat
|
||||
assert_netcat_not_found
|
||||
end
|
||||
|
||||
private
|
||||
def assert_accessory_running(name)
|
||||
assert_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
||||
end
|
||||
|
||||
def assert_accessory_not_running(name)
|
||||
assert_no_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
||||
end
|
||||
|
||||
def accessory_details(name)
|
||||
kamal :accessory, :details, name, capture: true
|
||||
end
|
||||
|
||||
def assert_netcat_is_up
|
||||
response = netcat_response
|
||||
debug_response_code(response, "200")
|
||||
assert_equal "200", response.code
|
||||
end
|
||||
|
||||
def assert_netcat_not_found
|
||||
response = netcat_response
|
||||
debug_response_code(response, "404")
|
||||
assert_equal "404", response.code
|
||||
end
|
||||
|
||||
def netcat_response
|
||||
uri = URI.parse("http://127.0.0.1:12345/up")
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Get.new(uri)
|
||||
request["Host"] = "netcat"
|
||||
|
||||
http.request(request)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user