Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c8428504d | ||
|
|
8e71c48747 | ||
|
|
67a86e1068 | ||
|
|
b67f40bdf7 | ||
|
|
375f0283c4 | ||
|
|
b8aaddb4c9 | ||
|
|
f48f528043 | ||
|
|
ec0a082542 | ||
|
|
6c638a8a77 | ||
|
|
1f5b936fa2 | ||
|
|
f785451cc7 | ||
|
|
e6d436f646 |
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
kamal (1.5.0)
|
kamal (1.5.2)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
bcrypt_pbkdf (~> 1.0)
|
bcrypt_pbkdf (~> 1.0)
|
||||||
|
|||||||
@@ -107,8 +107,9 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
|
||||||
else
|
else
|
||||||
|
type = "Accessory #{name}"
|
||||||
with_accessory(name) do |accessory, hosts|
|
with_accessory(name) do |accessory, hosts|
|
||||||
on(hosts) { puts capture_with_info(*accessory.info) }
|
on(hosts) { puts_by_host host, capture_with_info(*accessory.info), type: type }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
rescue SSHKit::Command::Failed => e
|
rescue SSHKit::Command::Failed => e
|
||||||
if e.message =~ /(no builder)|(no such file or directory)/
|
if e.message =~ /(no builder)|(no such file or directory)/
|
||||||
error "Missing compatible builder, so creating a new one first"
|
warn "Missing compatible builder, so creating a new one first"
|
||||||
|
|
||||||
if cli.create
|
if cli.create
|
||||||
KAMAL.with_verbosity(:debug) { execute *KAMAL.builder.push }
|
KAMAL.with_verbosity(:debug) { execute *KAMAL.builder.push }
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Kamal::Commander::Specifics
|
|||||||
end
|
end
|
||||||
|
|
||||||
def traefik_hosts
|
def traefik_hosts
|
||||||
specific_hosts || config.traefik_hosts
|
config.traefik_hosts & specified_hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
def accessory_hosts
|
def accessory_hosts
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module Kamal::Commands
|
|||||||
elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
|
elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
|
||||||
cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
|
cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
|
||||||
end
|
end
|
||||||
cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ")}'"
|
cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,12 @@ module Kamal::Utils
|
|||||||
Array(filters).select do |filter|
|
Array(filters).select do |filter|
|
||||||
matches += Array(items).select do |item|
|
matches += Array(items).select do |item|
|
||||||
# Only allow * for a wildcard
|
# Only allow * for a wildcard
|
||||||
pattern = Regexp.escape(filter).gsub('\*', ".*")
|
|
||||||
# items are roles or hosts
|
# items are roles or hosts
|
||||||
(item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
|
File.fnmatch(filter, item.to_s, File::FNM_EXTGLOB)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
matches
|
matches.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def stable_sort!(elements, &block)
|
def stable_sort!(elements, &block)
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Kamal
|
module Kamal
|
||||||
VERSION = "1.5.0"
|
VERSION = "1.5.2"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ class CliAccessoryTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "details" do
|
test "details" do
|
||||||
assert_match "docker ps --filter label=service=app-mysql", run_command("details", "mysql")
|
run_command("details", "mysql").tap do |output|
|
||||||
|
assert_match "docker ps --filter label=service=app-mysql", output
|
||||||
|
assert_match "Accessory mysql Host: 1.1.1.3", output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "details with non-existent accessory" do
|
test "details with non-existent accessory" do
|
||||||
@@ -85,6 +88,8 @@ class CliAccessoryTest < CliTestCase
|
|||||||
|
|
||||||
test "details with all" do
|
test "details with all" do
|
||||||
run_command("details", "all").tap do |output|
|
run_command("details", "all").tap do |output|
|
||||||
|
assert_match "Accessory mysql Host: 1.1.1.3", output
|
||||||
|
assert_match "Accessory redis Host: 1.1.1.2", output
|
||||||
assert_match "docker ps --filter label=service=app-mysql", output
|
assert_match "docker ps --filter label=service=app-mysql", output
|
||||||
assert_match "docker ps --filter label=service=app-redis", output
|
assert_match "docker ps --filter label=service=app-redis", output
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -218,9 +218,9 @@ class CliAppTest < CliTestCase
|
|||||||
|
|
||||||
test "logs with follow" do
|
test "logs with follow" do
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:exec)
|
SSHKit::Backend::Abstract.any_instance.stubs(:exec)
|
||||||
.with("ssh -t root@1.1.1.1 -p 22 'sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --tail 10 --follow 2>&1'")
|
.with("ssh -t root@1.1.1.1 -p 22 'sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --tail 10 --follow 2>&1'")
|
||||||
|
|
||||||
assert_match "sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --tail 10 --follow 2>&1", run_command("logs", "--follow")
|
assert_match "sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --tail 10 --follow 2>&1", run_command("logs", "--follow")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "version" do
|
test "version" do
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class CliBuildTest < CliTestCase
|
|||||||
.returns(true)
|
.returns(true)
|
||||||
|
|
||||||
run_command("push").tap do |output|
|
run_command("push").tap do |output|
|
||||||
assert_match /Missing compatible builder, so creating a new one first/, output
|
assert_match /WARN Missing compatible builder, so creating a new one first/, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
@kamal.specific_hosts = [ "*" ]
|
@kamal.specific_hosts = [ "*" ]
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
|
||||||
|
|
||||||
|
@kamal.specific_hosts = [ "1.1.1.[12]" ]
|
||||||
|
assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.hosts
|
||||||
|
|
||||||
exception = assert_raises(ArgumentError) do
|
exception = assert_raises(ArgumentError) do
|
||||||
@kamal.specific_hosts = [ "*miss" ]
|
@kamal.specific_hosts = [ "*miss" ]
|
||||||
end
|
end
|
||||||
@@ -57,6 +60,9 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
@kamal.specific_roles = [ "*" ]
|
@kamal.specific_roles = [ "*" ]
|
||||||
assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
|
assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
|
||||||
|
|
||||||
|
@kamal.specific_roles = [ "w{eb,orkers}" ]
|
||||||
|
assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
|
||||||
|
|
||||||
exception = assert_raises(ArgumentError) do
|
exception = assert_raises(ArgumentError) do
|
||||||
@kamal.specific_roles = [ "*miss" ]
|
@kamal.specific_roles = [ "*miss" ]
|
||||||
end
|
end
|
||||||
@@ -125,6 +131,20 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "1.1.1.3", "1.1.1.4", "1.1.1.1", "1.1.1.2" ], @kamal.hosts
|
assert_equal [ "1.1.1.3", "1.1.1.4", "1.1.1.1", "1.1.1.2" ], @kamal.hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "traefik hosts should observe filtered roles" do
|
||||||
|
configure_with(:deploy_with_aliases)
|
||||||
|
|
||||||
|
@kamal.specific_roles = [ "web_tokyo" ]
|
||||||
|
assert_equal [ "1.1.1.3", "1.1.1.4" ], @kamal.traefik_hosts
|
||||||
|
end
|
||||||
|
|
||||||
|
test "traefik hosts should observe filtered hosts" do
|
||||||
|
configure_with(:deploy_with_aliases)
|
||||||
|
|
||||||
|
@kamal.specific_hosts = [ "1.1.1.4" ]
|
||||||
|
assert_equal [ "1.1.1.4" ], @kamal.traefik_hosts
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def configure_with(variant)
|
def configure_with(variant)
|
||||||
@kamal = Kamal::Commander.new.tap do |kamal|
|
@kamal = Kamal::Commander.new.tap do |kamal|
|
||||||
|
|||||||
@@ -154,19 +154,19 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "follow logs" do
|
test "follow logs" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"ssh -t root@app-1 -p 22 'sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --follow 2>&1'",
|
"ssh -t root@app-1 -p 22 'sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --follow 2>&1'",
|
||||||
new_command.follow_logs(host: "app-1")
|
new_command.follow_logs(host: "app-1")
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"ssh -t root@app-1 -p 22 'sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --follow 2>&1 | grep \"Completed\"'",
|
"ssh -t root@app-1 -p 22 'sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --follow 2>&1 | grep \"Completed\"'",
|
||||||
new_command.follow_logs(host: "app-1", grep: "Completed")
|
new_command.follow_logs(host: "app-1", grep: "Completed")
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"ssh -t root@app-1 -p 22 'sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --tail 123 --follow 2>&1'",
|
"ssh -t root@app-1 -p 22 'sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --tail 123 --follow 2>&1'",
|
||||||
new_command.follow_logs(host: "app-1", lines: 123)
|
new_command.follow_logs(host: "app-1", lines: 123)
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"ssh -t root@app-1 -p 22 'sh -c 'docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''{{.ID}}'\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | xargs docker logs --timestamps --tail 123 --follow 2>&1 | grep \"Completed\"'",
|
"ssh -t root@app-1 -p 22 'sh -c '\\''docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=dhh/app:latest --format '\\''\\'\\'''\\''{{.ID}}'\\''\\'\\'''\\'') ; docker ps --latest --quiet --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting'\\'' | head -1 | xargs docker logs --timestamps --tail 123 --follow 2>&1 | grep \"Completed\"'",
|
||||||
new_command.follow_logs(host: "app-1", lines: 123, grep: "Completed")
|
new_command.follow_logs(host: "app-1", lines: 123, grep: "Completed")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,15 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "filtered traefik hosts" do
|
||||||
|
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.traefik_hosts
|
||||||
|
|
||||||
|
@deploy_with_roles[:servers]["workers"]["traefik"] = true
|
||||||
|
config = Kamal::Configuration.new(@deploy_with_roles)
|
||||||
|
|
||||||
|
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
|
||||||
|
end
|
||||||
|
|
||||||
test "version no git repo" do
|
test "version no git repo" do
|
||||||
ENV.delete("VERSION")
|
ENV.delete("VERSION")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user