Compare commits
24 Commits
v1.9.1
...
revert-905
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
459ba95bbf | ||
|
|
6adf3c117f | ||
|
|
9f0b10425c | ||
|
|
5f2384f123 | ||
|
|
eab7d3adc5 | ||
|
|
d2d0223c37 | ||
|
|
56268d724d | ||
|
|
cffb6c3d7e | ||
|
|
bd1726f305 | ||
|
|
7ddb122a22 | ||
|
|
98c951bbdb | ||
|
|
374c117b79 | ||
|
|
d6a5cf3c78 | ||
|
|
2aeabda455 | ||
|
|
c048c097ed | ||
|
|
ed148628fb | ||
|
|
d48080c772 | ||
|
|
3f64338929 | ||
|
|
0ab838bc25 | ||
|
|
b7382ceeaf | ||
|
|
69367fbc6b | ||
|
|
2515bd705c | ||
|
|
579e169be2 | ||
|
|
b8af719bb7 |
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@@ -3,7 +3,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- 1-8-stable
|
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
rubocop:
|
rubocop:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
kamal (1.9.1)
|
kamal (2.0.0.alpha)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
bcrypt_pbkdf (~> 1.0)
|
bcrypt_pbkdf (~> 1.0)
|
||||||
@@ -10,7 +10,7 @@ PATH
|
|||||||
ed25519 (~> 1.2)
|
ed25519 (~> 1.2)
|
||||||
net-ssh (~> 7.0)
|
net-ssh (~> 7.0)
|
||||||
sshkit (>= 1.23.0, < 2.0)
|
sshkit (>= 1.23.0, < 2.0)
|
||||||
thor (~> 1.2)
|
thor (~> 1.3)
|
||||||
zeitwerk (~> 2.5)
|
zeitwerk (~> 2.5)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
|
|||||||
20
bin/docs
20
bin/docs
@@ -17,6 +17,7 @@ end
|
|||||||
|
|
||||||
DOCS = {
|
DOCS = {
|
||||||
"accessory" => "Accessories",
|
"accessory" => "Accessories",
|
||||||
|
"alias" => "Aliases",
|
||||||
"boot" => "Booting",
|
"boot" => "Booting",
|
||||||
"builder" => "Builders",
|
"builder" => "Builders",
|
||||||
"configuration" => "Configuration overview",
|
"configuration" => "Configuration overview",
|
||||||
@@ -67,26 +68,27 @@ class DocWriter
|
|||||||
output.puts
|
output.puts
|
||||||
place = :new_section
|
place = :new_section
|
||||||
elsif line =~ /^ *#/
|
elsif line =~ /^ *#/
|
||||||
generate_line(line, place: place)
|
generate_line(line, heading: place == :new_section)
|
||||||
place = :in_section
|
place = :in_section
|
||||||
else
|
else
|
||||||
output.puts "```yaml"
|
output.puts "```yaml"
|
||||||
output.print line
|
output.puts line
|
||||||
place = :in_yaml
|
place = :in_yaml
|
||||||
end
|
end
|
||||||
when :in_yaml
|
when :in_yaml, :in_empty_line_yaml
|
||||||
if line =~ /^ *#/
|
if line =~ /^ *#/
|
||||||
output.puts "```"
|
output.puts "```"
|
||||||
generate_line(line, place: :new_section)
|
generate_line(line, heading: place == :in_empty_line_yaml)
|
||||||
place = :in_section
|
place = :in_section
|
||||||
|
elsif line.empty?
|
||||||
|
place = :in_empty_line_yaml
|
||||||
else
|
else
|
||||||
output.puts
|
output.puts line
|
||||||
output.print line
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output.puts "\n```" if place == :in_yaml
|
output.puts "```" if place == :in_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_header
|
def generate_header
|
||||||
@@ -98,7 +100,7 @@ class DocWriter
|
|||||||
output.puts
|
output.puts
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_line(line, place: :in_section)
|
def generate_line(line, heading: false)
|
||||||
line = line.gsub(/^ *#\s?/, "")
|
line = line.gsub(/^ *#\s?/, "")
|
||||||
|
|
||||||
if line =~ /(.*)kamal docs ([a-z]*)(.*)/
|
if line =~ /(.*)kamal docs ([a-z]*)(.*)/
|
||||||
@@ -109,7 +111,7 @@ class DocWriter
|
|||||||
line = "#{$1}[#{titlify($2.split("/").last)}](#{$2})#{$3}"
|
line = "#{$1}[#{titlify($2.split("/").last)}](#{$2})#{$3}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if place == :new_section
|
if heading
|
||||||
output.puts "## [#{line}](##{linkify(line)})"
|
output.puts "## [#{line}](##{linkify(line)})"
|
||||||
else
|
else
|
||||||
output.puts line
|
output.puts line
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_dependency "activesupport", ">= 7.0"
|
spec.add_dependency "activesupport", ">= 7.0"
|
||||||
spec.add_dependency "sshkit", ">= 1.23.0", "< 2.0"
|
spec.add_dependency "sshkit", ">= 1.23.0", "< 2.0"
|
||||||
spec.add_dependency "net-ssh", "~> 7.0"
|
spec.add_dependency "net-ssh", "~> 7.0"
|
||||||
spec.add_dependency "thor", "~> 1.2"
|
spec.add_dependency "thor", "~> 1.3"
|
||||||
spec.add_dependency "dotenv", "~> 2.8"
|
spec.add_dependency "dotenv", "~> 2.8"
|
||||||
spec.add_dependency "zeitwerk", "~> 2.5"
|
spec.add_dependency "zeitwerk", "~> 2.5"
|
||||||
spec.add_dependency "ed25519", "~> 1.2"
|
spec.add_dependency "ed25519", "~> 1.2"
|
||||||
|
|||||||
@@ -222,25 +222,6 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "downgrade", "Downgrade accessories from Kamal 2 to 1.9"
|
|
||||||
option :rolling, type: :boolean, default: false, desc: "Upgrade one host at a time"
|
|
||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
|
||||||
def downgrade(name)
|
|
||||||
confirming "This will restart all accessories" do
|
|
||||||
with_lock do
|
|
||||||
host_groups = options[:rolling] ? KAMAL.accessory_hosts : [ KAMAL.accessory_hosts ]
|
|
||||||
host_groups.each do |hosts|
|
|
||||||
host_list = Array(hosts).join(",")
|
|
||||||
KAMAL.with_specific_hosts(hosts) do
|
|
||||||
say "Downgrading #{name} accessories on #{host_list}...", :magenta
|
|
||||||
reboot name
|
|
||||||
say "Downgraded #{name} accessories on #{host_list}...", :magenta
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def with_accessory(name)
|
def with_accessory(name)
|
||||||
if KAMAL.config.accessory(name)
|
if KAMAL.config.accessory(name)
|
||||||
|
|||||||
9
lib/kamal/cli/alias/command.rb
Normal file
9
lib/kamal/cli/alias/command.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class Kamal::Cli::Alias::Command < Thor::DynamicCommand
|
||||||
|
def run(instance, args = [])
|
||||||
|
if (_alias = KAMAL.config.aliases[name])
|
||||||
|
Kamal::Cli::Main.start(Shellwords.split(_alias.command) + ARGV[1..-1])
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -71,11 +71,12 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "exec [CMD]", "Execute a custom command on servers within the app container (use --help to show options)"
|
desc "exec [CMD...]", "Execute a custom command on servers within the app container (use --help to show options)"
|
||||||
option :interactive, aliases: "-i", type: :boolean, default: false, desc: "Execute command over ssh for an interactive shell (use for console/bash)"
|
option :interactive, aliases: "-i", type: :boolean, default: false, desc: "Execute command over ssh for an interactive shell (use for console/bash)"
|
||||||
option :reuse, type: :boolean, default: false, desc: "Reuse currently running container instead of starting a new one"
|
option :reuse, type: :boolean, default: false, desc: "Reuse currently running container instead of starting a new one"
|
||||||
option :env, aliases: "-e", type: :hash, desc: "Set environment variables for the command"
|
option :env, aliases: "-e", type: :hash, desc: "Set environment variables for the command"
|
||||||
def exec(cmd)
|
def exec(*cmd)
|
||||||
|
cmd = Kamal::Utils.join_commands(cmd)
|
||||||
env = options[:env]
|
env = options[:env]
|
||||||
case
|
case
|
||||||
when options[:interactive] && options[:reuse]
|
when options[:interactive] && options[:reuse]
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ module Kamal::Cli
|
|||||||
class Base < Thor
|
class Base < Thor
|
||||||
include SSHKit::DSL
|
include SSHKit::DSL
|
||||||
|
|
||||||
def self.exit_on_failure?() true end
|
def self.exit_on_failure?() false end
|
||||||
|
def self.dynamic_command_class() Kamal::Cli::Alias::Command end
|
||||||
|
|
||||||
class_option :verbose, type: :boolean, aliases: "-v", desc: "Detailed logging"
|
class_option :verbose, type: :boolean, aliases: "-v", desc: "Detailed logging"
|
||||||
class_option :quiet, type: :boolean, aliases: "-q", desc: "Minimal logging"
|
class_option :quiet, type: :boolean, aliases: "-q", desc: "Minimal logging"
|
||||||
@@ -22,8 +23,14 @@ module Kamal::Cli
|
|||||||
|
|
||||||
class_option :skip_hooks, aliases: "-H", type: :boolean, default: false, desc: "Don't run hooks"
|
class_option :skip_hooks, aliases: "-H", type: :boolean, default: false, desc: "Don't run hooks"
|
||||||
|
|
||||||
def initialize(*)
|
def initialize(args = [], local_options = {}, config = {})
|
||||||
super
|
if config[:current_command].is_a?(Kamal::Cli::Alias::Command)
|
||||||
|
# When Thor generates a dynamic command, it doesn't attempt to parse the arguments.
|
||||||
|
# For our purposes, it means the arguments are passed in args rather than local_options.
|
||||||
|
super([], args, config)
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
@original_env = ENV.to_h.dup
|
@original_env = ENV.to_h.dup
|
||||||
load_env
|
load_env
|
||||||
initialize_commander(options_with_subcommand_class_options)
|
initialize_commander(options_with_subcommand_class_options)
|
||||||
@@ -206,10 +213,6 @@ module Kamal::Cli
|
|||||||
instance_variable_get("@_invocations").first
|
instance_variable_get("@_invocations").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_invocation(cli_class)
|
|
||||||
instance_variable_get("@_invocations")[cli_class].pop
|
|
||||||
end
|
|
||||||
|
|
||||||
def ensure_run_and_locks_directory
|
def ensure_run_and_locks_directory
|
||||||
on(KAMAL.hosts) do
|
on(KAMAL.hosts) do
|
||||||
execute(*KAMAL.server.ensure_run_directory)
|
execute(*KAMAL.server.ensure_run_directory)
|
||||||
|
|||||||
@@ -217,37 +217,6 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "downgrade", "Downgrade from Kamal 2 to 1.9"
|
|
||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
|
||||||
option :rolling, type: :boolean, default: false, desc: "Downgrade one host at a time"
|
|
||||||
def downgrade
|
|
||||||
confirming "This will replace Traefik with kamal-proxy and restart all accessories" do
|
|
||||||
with_lock do
|
|
||||||
if options[:rolling]
|
|
||||||
(KAMAL.hosts | KAMAL.accessory_hosts).each do |host|
|
|
||||||
KAMAL.with_specific_hosts(host) do
|
|
||||||
say "Downgrading #{host}...", :magenta
|
|
||||||
if KAMAL.hosts.include?(host)
|
|
||||||
invoke "kamal:cli:traefik:downgrade", [], options.merge(confirmed: true, rolling: false)
|
|
||||||
reset_invocation(Kamal::Cli::Traefik)
|
|
||||||
end
|
|
||||||
if KAMAL.accessory_hosts.include?(host)
|
|
||||||
invoke "kamal:cli:accessory:downgrade", [ "all" ], options.merge(confirmed: true, rolling: false)
|
|
||||||
reset_invocation(Kamal::Cli::Accessory)
|
|
||||||
end
|
|
||||||
say "Downgraded #{host}", :magenta
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
say "Downgrading all hosts...", :magenta
|
|
||||||
invoke "kamal:cli:traefik:downgrade", [], options.merge(confirmed: true)
|
|
||||||
invoke "kamal:cli:accessory:downgrade", [ "all" ], options.merge(confirmed: true)
|
|
||||||
say "Downgraded all hosts", :magenta
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "version", "Show Kamal version"
|
desc "version", "Show Kamal version"
|
||||||
def version
|
def version
|
||||||
puts Kamal::VERSION
|
puts Kamal::VERSION
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class Kamal::Cli::Server < Kamal::Cli::Base
|
class Kamal::Cli::Server < Kamal::Cli::Base
|
||||||
desc "exec", "Run a custom command on the server (use --help to show options)"
|
desc "exec", "Run a custom command on the server (use --help to show options)"
|
||||||
option :interactive, type: :boolean, aliases: "-i", default: false, desc: "Run the command interactively (use for console/bash)"
|
option :interactive, type: :boolean, aliases: "-i", default: false, desc: "Run the command interactively (use for console/bash)"
|
||||||
def exec(cmd)
|
def exec(*cmd)
|
||||||
|
cmd = Kamal::Utils.join_commands(cmd)
|
||||||
hosts = KAMAL.hosts | KAMAL.accessory_hosts
|
hosts = KAMAL.hosts | KAMAL.accessory_hosts
|
||||||
|
|
||||||
case
|
case
|
||||||
|
|||||||
@@ -119,44 +119,4 @@ class Kamal::Cli::Traefik < Kamal::Cli::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "downgrade", "Downgrade to Traefik on servers (stop container, remove container, start new container, reboot app)"
|
|
||||||
option :rolling, type: :boolean, default: false, desc: "Reboot proxy on hosts in sequence, rather than in parallel"
|
|
||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
|
||||||
def downgrade
|
|
||||||
invoke_options = { "version" => KAMAL.config.latest_tag }.merge(options)
|
|
||||||
|
|
||||||
confirming "This will cause a brief outage on each host. Are you sure?" do
|
|
||||||
host_groups = options[:rolling] ? KAMAL.hosts : [ KAMAL.hosts ]
|
|
||||||
host_groups.each do |hosts|
|
|
||||||
host_list = Array(hosts).join(",")
|
|
||||||
say "Downgrading to Traefik on #{host_list}...", :magenta
|
|
||||||
run_hook "pre-traefik-reboot", hosts: host_list
|
|
||||||
on(hosts) do |host|
|
|
||||||
execute *KAMAL.auditor.record("Rebooted Traefik"), verbosity: :debug
|
|
||||||
execute *KAMAL.registry.login
|
|
||||||
|
|
||||||
"Stopping and removing kamal-proxy on #{host}, if running..."
|
|
||||||
execute *KAMAL.traefik.cleanup_kamal_proxy
|
|
||||||
|
|
||||||
"Stopping and removing Traefik on #{host}, if running..."
|
|
||||||
execute *KAMAL.traefik.stop, raise_on_non_zero_exit: false
|
|
||||||
execute *KAMAL.traefik.remove_container
|
|
||||||
execute *KAMAL.traefik.remove_image
|
|
||||||
end
|
|
||||||
|
|
||||||
KAMAL.with_specific_hosts(hosts) do
|
|
||||||
invoke "kamal:cli:traefik:boot", [], invoke_options
|
|
||||||
reset_invocation(Kamal::Cli::Traefik)
|
|
||||||
invoke "kamal:cli:app:boot", [], invoke_options
|
|
||||||
reset_invocation(Kamal::Cli::App)
|
|
||||||
invoke "kamal:cli:prune:all", [], invoke_options
|
|
||||||
reset_invocation(Kamal::Cli::Prune)
|
|
||||||
end
|
|
||||||
|
|
||||||
run_hook "post-traefik-reboot", hosts: host_list
|
|
||||||
say "Downgraded to Traefik on #{host_list}", :magenta
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ class Kamal::Commander
|
|||||||
|
|
||||||
def specific_primary!
|
def specific_primary!
|
||||||
@specifics = nil
|
@specifics = nil
|
||||||
self.specific_hosts = [ config.primary_host ]
|
if specific_roles.present?
|
||||||
|
self.specific_hosts = [ specific_roles.first.primary_host ]
|
||||||
|
else
|
||||||
|
self.specific_hosts = [ config.primary_host ]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def specific_roles=(role_names)
|
def specific_roles=(role_names)
|
||||||
@@ -56,13 +60,6 @@ class Kamal::Commander
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_specific_hosts(hosts)
|
|
||||||
original_hosts, self.specific_hosts = specific_hosts, hosts
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
self.specific_hosts = original_hosts
|
|
||||||
end
|
|
||||||
|
|
||||||
def accessory_names
|
def accessory_names
|
||||||
config.accessories&.collect(&:name) || []
|
config.accessories&.collect(&:name) || []
|
||||||
end
|
end
|
||||||
@@ -120,6 +117,10 @@ class Kamal::Commander
|
|||||||
@traefik ||= Kamal::Commands::Traefik.new(config)
|
@traefik ||= Kamal::Commands::Traefik.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def alias(name)
|
||||||
|
config.aliases[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def with_verbosity(level)
|
def with_verbosity(level)
|
||||||
old_level = self.verbosity
|
old_level = self.verbosity
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class Kamal::Commander::Specifics
|
|||||||
end
|
end
|
||||||
|
|
||||||
def accessory_hosts
|
def accessory_hosts
|
||||||
config.accessories.flat_map(&:hosts) & specified_hosts
|
specific_hosts || config.accessories.flat_map(&:hosts)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -58,8 +58,4 @@ class Kamal::Commands::Builder::Multiarch::Remote < Kamal::Commands::Builder::Mu
|
|||||||
def remove_context(arch)
|
def remove_context(arch)
|
||||||
docker :context, :rm, builder_name_with_arch(arch)
|
docker :context, :rm, builder_name_with_arch(arch)
|
||||||
end
|
end
|
||||||
|
|
||||||
def platform_names
|
|
||||||
"linux/#{local_arch},linux/#{remote_arch}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -62,15 +62,6 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|||||||
[ :rm, "-f", env.secrets_file ]
|
[ :rm, "-f", env.secrets_file ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_kamal_proxy
|
|
||||||
chain \
|
|
||||||
docker(:container, :stop, "kamal-proxy"),
|
|
||||||
combine(
|
|
||||||
docker(:container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy"),
|
|
||||||
docker(:image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy")
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def publish_args
|
def publish_args
|
||||||
argumentize "--publish", port if publish?
|
argumentize "--publish", port if publish?
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Kamal::Configuration
|
|||||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||||
|
|
||||||
attr_reader :destination, :raw_config
|
attr_reader :destination, :raw_config
|
||||||
attr_reader :accessories, :boot, :builder, :env, :healthcheck, :logging, :traefik, :servers, :ssh, :sshkit, :registry
|
attr_reader :accessories, :aliases, :boot, :builder, :env, :healthcheck, :logging, :traefik, :servers, :ssh, :sshkit, :registry
|
||||||
|
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ class Kamal::Configuration
|
|||||||
@registry = Registry.new(config: self)
|
@registry = Registry.new(config: self)
|
||||||
|
|
||||||
@accessories = @raw_config.accessories&.keys&.collect { |name| Accessory.new(name, config: self) } || []
|
@accessories = @raw_config.accessories&.keys&.collect { |name| Accessory.new(name, config: self) } || []
|
||||||
|
@aliases = @raw_config.aliases&.keys&.to_h { |name| [ name, Alias.new(name, config: self) ] } || {}
|
||||||
@boot = Boot.new(config: self)
|
@boot = Boot.new(config: self)
|
||||||
@builder = Builder.new(config: self)
|
@builder = Builder.new(config: self)
|
||||||
@env = Env.new(config: @raw_config.env || {})
|
@env = Env.new(config: @raw_config.env || {})
|
||||||
|
|||||||
15
lib/kamal/configuration/alias.rb
Normal file
15
lib/kamal/configuration/alias.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class Kamal::Configuration::Alias
|
||||||
|
include Kamal::Configuration::Validation
|
||||||
|
|
||||||
|
attr_reader :name, :command
|
||||||
|
|
||||||
|
def initialize(name, config:)
|
||||||
|
@name, @command = name.inquiry, config.raw_config["aliases"][name]
|
||||||
|
|
||||||
|
validate! \
|
||||||
|
command,
|
||||||
|
example: validation_yml["aliases"]["uname"],
|
||||||
|
context: "aliases/#{name}",
|
||||||
|
with: Kamal::Configuration::Validator::Alias
|
||||||
|
end
|
||||||
|
end
|
||||||
26
lib/kamal/configuration/docs/alias.yml
Normal file
26
lib/kamal/configuration/docs/alias.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Aliases
|
||||||
|
#
|
||||||
|
# Aliases are shortcuts for Kamal commands.
|
||||||
|
#
|
||||||
|
# For example, for a Rails app, you might open a console with:
|
||||||
|
#
|
||||||
|
# ```shell
|
||||||
|
# kamal app exec -i -r console "rails console"
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# By defining an alias, like this:
|
||||||
|
aliases:
|
||||||
|
console: app exec -r console -i "rails console"
|
||||||
|
# You can now open the console with:
|
||||||
|
# ```shell
|
||||||
|
# kamal console
|
||||||
|
# ```
|
||||||
|
|
||||||
|
# Configuring aliases
|
||||||
|
#
|
||||||
|
# Aliases are defined in the root config under the alias key
|
||||||
|
#
|
||||||
|
# Each alias is named and can only contain lowercase letters, numbers, dashes and underscores.
|
||||||
|
|
||||||
|
aliases:
|
||||||
|
uname: app exec -p -q -r web "uname -a"
|
||||||
@@ -166,3 +166,9 @@ healthcheck:
|
|||||||
# Docker logging configuration, see kamal docs logging
|
# Docker logging configuration, see kamal docs logging
|
||||||
logging:
|
logging:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
# Aliases
|
||||||
|
#
|
||||||
|
# Alias configuration, see kamal docs alias
|
||||||
|
aliases:
|
||||||
|
...
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ traefik:
|
|||||||
|
|
||||||
# Image
|
# Image
|
||||||
#
|
#
|
||||||
# The Traefik image to use, defaults to `traefik:v2.11`
|
# The Traefik image to use, defaults to `traefik:v2.10`
|
||||||
image: traefik:v2.11
|
image: traefik:v2.9
|
||||||
|
|
||||||
# Host port
|
# Host port
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Kamal::Configuration::Traefik
|
class Kamal::Configuration::Traefik
|
||||||
DEFAULT_IMAGE = "traefik:v2.11"
|
DEFAULT_IMAGE = "traefik:v2.10"
|
||||||
CONTAINER_PORT = 80
|
CONTAINER_PORT = 80
|
||||||
DEFAULT_ARGS = {
|
DEFAULT_ARGS = {
|
||||||
"log.level" => "DEBUG"
|
"log.level" => "DEBUG"
|
||||||
|
|||||||
@@ -13,32 +13,34 @@ class Kamal::Configuration::Validator
|
|||||||
|
|
||||||
private
|
private
|
||||||
def validate_against_example!(validation_config, example)
|
def validate_against_example!(validation_config, example)
|
||||||
validate_type! validation_config, Hash
|
validate_type! validation_config, example.class
|
||||||
|
|
||||||
check_unknown_keys! validation_config, example
|
if example.class == Hash
|
||||||
|
check_unknown_keys! validation_config, example
|
||||||
|
|
||||||
validation_config.each do |key, value|
|
validation_config.each do |key, value|
|
||||||
next if extension?(key)
|
next if extension?(key)
|
||||||
with_context(key) do
|
with_context(key) do
|
||||||
example_value = example[key]
|
example_value = example[key]
|
||||||
|
|
||||||
if example_value == "..."
|
if example_value == "..."
|
||||||
validate_type! value, *(Array if key == :servers), Hash
|
validate_type! value, *(Array if key == :servers), Hash
|
||||||
elsif key == "hosts"
|
elsif key == "hosts"
|
||||||
validate_servers! value
|
validate_servers! value
|
||||||
elsif example_value.is_a?(Array)
|
elsif example_value.is_a?(Array)
|
||||||
validate_array_of! value, example_value.first.class
|
validate_array_of! value, example_value.first.class
|
||||||
elsif example_value.is_a?(Hash)
|
elsif example_value.is_a?(Hash)
|
||||||
case key.to_s
|
case key.to_s
|
||||||
when "options", "args"
|
when "options", "args"
|
||||||
validate_type! value, Hash
|
validate_type! value, Hash
|
||||||
when "labels"
|
when "labels"
|
||||||
validate_hash_of! value, example_value.first[1].class
|
validate_hash_of! value, example_value.first[1].class
|
||||||
|
else
|
||||||
|
validate_against_example! value, example_value
|
||||||
|
end
|
||||||
else
|
else
|
||||||
validate_against_example! value, example_value
|
validate_type! value, example_value.class
|
||||||
end
|
end
|
||||||
else
|
|
||||||
validate_type! value, example_value.class
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
15
lib/kamal/configuration/validator/alias.rb
Normal file
15
lib/kamal/configuration/validator/alias.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class Kamal::Configuration::Validator::Alias < Kamal::Configuration::Validator
|
||||||
|
def validate!
|
||||||
|
super
|
||||||
|
|
||||||
|
name = context.delete_prefix("aliases/")
|
||||||
|
|
||||||
|
if name !~ /\A[a-z0-9_-]+\z/
|
||||||
|
error "Invalid alias name: '#{name}'. Must only contain lowercase letters, alphanumeric, hyphens and underscores."
|
||||||
|
end
|
||||||
|
|
||||||
|
if Kamal::Cli::Main.commands.include?(name)
|
||||||
|
error "Alias '#{name}' conflicts with a built-in command."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -77,4 +77,8 @@ module Kamal::Utils
|
|||||||
def stable_sort!(elements, &block)
|
def stable_sort!(elements, &block)
|
||||||
elements.sort_by!.with_index { |element, index| [ block.call(element), index ] }
|
elements.sort_by!.with_index { |element, index| [ block.call(element), index ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def join_commands(commands)
|
||||||
|
commands.map(&:strip).join(" ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Kamal
|
module Kamal
|
||||||
VERSION = "1.9.1"
|
VERSION = "2.0.0.alpha"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -209,24 +209,6 @@ class CliAccessoryTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "downgrade" do
|
|
||||||
run_command("downgrade", "-y", "all").tap do |output|
|
|
||||||
assert_match "Downgrading all accessories on 1.1.1.3,1.1.1.1,1.1.1.2...", output
|
|
||||||
assert_match "docker container stop app-mysql on 1.1.1.3", output
|
|
||||||
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
|
||||||
assert_match "Downgraded all accessories on 1.1.1.3,1.1.1.1,1.1.1.2", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "downgrade rolling" do
|
|
||||||
run_command("downgrade", "--rolling", "-y", "all").tap do |output|
|
|
||||||
assert_match "Downgrading all accessories on 1.1.1.3...", output
|
|
||||||
assert_match "docker container stop app-mysql on 1.1.1.3", output
|
|
||||||
assert_match "docker run --name app-mysql --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 3306:3306 --env-file .kamal/env/accessories/app-mysql.env --env MYSQL_ROOT_HOST=\"%\" --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output
|
|
||||||
assert_match "Downgraded all accessories on 1.1.1.3", 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.yml" ]) }
|
stdouted { Kamal::Cli::Accessory.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
||||||
|
|||||||
@@ -247,6 +247,12 @@ class CliAppTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "exec separate arguments" do
|
||||||
|
run_command("exec", "ruby", " -v").tap do |output|
|
||||||
|
assert_match "docker run --rm --env-file .kamal/env/roles/app-web.env dhh/app:latest ruby -v", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "exec with reuse" do
|
test "exec with reuse" do
|
||||||
run_command("exec", "--reuse", "ruby -v").tap do |output|
|
run_command("exec", "--reuse", "ruby -v").tap do |output|
|
||||||
assert_match "sh -c 'docker ps --latest --format '\\''{{.Names}}'\\'' --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 --format '\\''{{.Names}}'\\'' --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | while read line; do echo ${line#app-web-}; done", output # Get current version
|
assert_match "sh -c 'docker ps --latest --format '\\''{{.Names}}'\\'' --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 --format '\\''{{.Names}}'\\'' --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting' | head -1 | while read line; do echo ${line#app-web-}; done", output # Get current version
|
||||||
|
|||||||
@@ -63,4 +63,12 @@ class CliTestCase < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_match expected, output
|
assert_match expected, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_argv(*argv)
|
||||||
|
old_argv = ARGV
|
||||||
|
ARGV.replace(*argv)
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ARGV.replace(old_argv)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -537,37 +537,47 @@ class CliMainTest < CliTestCase
|
|||||||
assert_equal Kamal::VERSION, version
|
assert_equal Kamal::VERSION, version
|
||||||
end
|
end
|
||||||
|
|
||||||
test "downgrade" do
|
test "run an alias for details" do
|
||||||
invoke_options = { "config_file" => "test/fixtures/deploy_with_accessories.yml", "skip_hooks" => false, "confirmed" => true, "rolling" => false }
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:details")
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:downgrade", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:downgrade", [ "all" ], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:details", [ "all" ])
|
||||||
|
|
||||||
run_command("downgrade", "-y", config_file: "deploy_with_accessories").tap do |output|
|
run_command("info", config_file: "deploy_with_aliases")
|
||||||
assert_match "Downgrading all hosts...", output
|
end
|
||||||
assert_match "Downgraded all hosts", output
|
|
||||||
|
test "run an alias for a console" do
|
||||||
|
run_command("console", config_file: "deploy_with_aliases").tap do |output|
|
||||||
|
assert_match "docker exec app-console-999 bin/console on 1.1.1.5", output
|
||||||
|
assert_match "App Host: 1.1.1.5", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "downgrade rolling" do
|
test "run an alias for a console overriding role" do
|
||||||
invoke_options = { "config_file" => "test/fixtures/deploy_with_accessories.yml", "skip_hooks" => false, "confirmed" => true, "rolling" => false }
|
run_command("console", "-r", "workers", config_file: "deploy_with_aliases").tap do |output|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:downgrade", [], invoke_options).times(4)
|
assert_match "docker exec app-workers-999 bin/console on 1.1.1.3", output
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:downgrade", [ "all" ], invoke_options).times(3)
|
assert_match "App Host: 1.1.1.3", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
run_command("downgrade", "--rolling", "-y", config_file: "deploy_with_accessories").tap do |output|
|
test "run an alias for a console passing command" do
|
||||||
assert_match "Downgrading 1.1.1.1...", output
|
run_command("exec", "bin/job", config_file: "deploy_with_aliases").tap do |output|
|
||||||
assert_match "Downgraded 1.1.1.1", output
|
assert_match "docker exec app-console-999 bin/job on 1.1.1.5", output
|
||||||
assert_match "Downgrading 1.1.1.2...", output
|
assert_match "App Host: 1.1.1.5", output
|
||||||
assert_match "Downgraded 1.1.1.2", output
|
end
|
||||||
assert_match "Downgrading 1.1.1.3...", output
|
end
|
||||||
assert_match "Downgraded 1.1.1.3", output
|
|
||||||
assert_match "Downgrading 1.1.1.4...", output
|
test "append to command with an alias" do
|
||||||
assert_match "Downgraded 1.1.1.4", output
|
run_command("rails", "db:migrate:status", config_file: "deploy_with_aliases").tap do |output|
|
||||||
|
assert_match "docker exec app-console-999 rails db:migrate:status on 1.1.1.5", output
|
||||||
|
assert_match "App Host: 1.1.1.5", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_command(*command, config_file: "deploy_simple")
|
def run_command(*command, config_file: "deploy_simple")
|
||||||
stdouted { Kamal::Cli::Main.start([ *command, "-c", "test/fixtures/#{config_file}.yml" ]) }
|
with_argv([ *command, "-c", "test/fixtures/#{config_file}.yml" ]) do
|
||||||
|
stdouted { Kamal::Cli::Main.start }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_test_dotenv(**files)
|
def with_test_dotenv(**files)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ require_relative "cli_test_case"
|
|||||||
class CliServerTest < CliTestCase
|
class CliServerTest < CliTestCase
|
||||||
test "running a command with exec" do
|
test "running a command with exec" do
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||||
.with("date", verbosity: 1)
|
.with("date", verbosity: 1)
|
||||||
.returns("Today")
|
.returns("Today")
|
||||||
|
|
||||||
hosts = "1.1.1.1".."1.1.1.4"
|
hosts = "1.1.1.1".."1.1.1.4"
|
||||||
run_command("exec", "date").tap do |output|
|
run_command("exec", "date").tap do |output|
|
||||||
@@ -15,6 +15,20 @@ class CliServerTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "running a command with exec multiple arguments" do
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||||
|
.with("date -j", verbosity: 1)
|
||||||
|
.returns("Today")
|
||||||
|
|
||||||
|
hosts = "1.1.1.1".."1.1.1.4"
|
||||||
|
run_command("exec", "date", "-j").tap do |output|
|
||||||
|
hosts.map do |host|
|
||||||
|
assert_match "Running 'date -j' on #{hosts.to_a.join(', ')}...", output
|
||||||
|
assert_match "App Host: #{host}\nToday", output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "bootstrap already installed" do
|
test "bootstrap already installed" do
|
||||||
stub_setup
|
stub_setup
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(true).at_least_once
|
||||||
|
|||||||
@@ -103,90 +103,6 @@ class CliTraefikTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "downgrade" do
|
|
||||||
Object.any_instance.stubs(:sleep)
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
|
||||||
.returns("12345678")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", raise_on_non_zero_exit: false)
|
|
||||||
.returns("12345678")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with { |*args| args[0..1] == [ :sh, "-c" ] }
|
|
||||||
.returns("123") # old version
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running") # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running").at_least_once # workers health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", raise_on_non_zero_exit: false)
|
|
||||||
.returns("") # old version
|
|
||||||
|
|
||||||
run_command("downgrade", "-y").tap do |output|
|
|
||||||
assert_match "Downgrading to Traefik on 1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4...", output
|
|
||||||
assert_match "docker login -u [REDACTED] -p [REDACTED]", output
|
|
||||||
assert_match "docker container stop kamal-proxy ; docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy && docker image prune --all --force --filter label=org.opencontainers.image.title=kamal-proxy", output
|
|
||||||
assert_match "docker container stop traefik", output
|
|
||||||
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output
|
|
||||||
assert_match "docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik", output
|
|
||||||
assert_match "/usr/bin/env mkdir -p .kamal", output
|
|
||||||
assert_match "docker login -u [REDACTED] -p [REDACTED]", output
|
|
||||||
assert_match "docker container start traefik || docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size=\"10m\" --label traefik.http.routers.catchall.entryPoints=\"http\" --label traefik.http.routers.catchall.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.catchall.service=\"unavailable\" --label traefik.http.routers.catchall.priority=\"1\" --label traefik.http.services.unavailable.loadbalancer.server.port=\"0\" traefik:v2.11 --providers.docker --log.level=\"DEBUG\"", output
|
|
||||||
assert_match "/usr/bin/env mkdir -p .kamal", output
|
|
||||||
assert_match %r{docker rename app-web-latest app-web-latest_replaced_.*}, output
|
|
||||||
assert_match %r{docker run --detach --restart unless-stopped --name app-web-latest --hostname 1.1.1.1-.* -e KAMAL_CONTAINER_NAME="app-web-latest" -e KAMAL_VERSION="latest" --env-file .kamal/env/roles/app-web.env --health-cmd}, output
|
|
||||||
assert_match "docker tag dhh/app:latest dhh/app:latest", output
|
|
||||||
assert_match "/usr/bin/env mkdir -p .kamal", output
|
|
||||||
assert_match "docker ps -q -a --filter label=service=app --filter status=created --filter status=exited --filter status=dead | tail -n +6 | while read container_id; do docker rm $container_id; done", output
|
|
||||||
assert_match "docker image prune --force --filter label=service=app", output
|
|
||||||
assert_match "Downgraded to Traefik on 1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "downgrade rolling" do
|
|
||||||
Object.any_instance.stubs(:sleep)
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
|
|
||||||
.returns("12345678")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", raise_on_non_zero_exit: false)
|
|
||||||
.returns("12345678")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with { |*args| args[0..1] == [ :sh, "-c" ] }
|
|
||||||
.returns("123") # old version
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running") # health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
|
|
||||||
.returns("running").at_least_once # workers health check
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture_with_info)
|
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", raise_on_non_zero_exit: false)
|
|
||||||
.returns("") # old version
|
|
||||||
|
|
||||||
run_command("downgrade", "--rolling", "-y",).tap do |output|
|
|
||||||
%w[1.1.1.1 1.1.1.2 1.1.1.3 1.1.1.4].each do |host|
|
|
||||||
assert_match "Downgrading to Traefik on #{host}...", output
|
|
||||||
assert_match "docker container stop kamal-proxy ; docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy && docker image prune --all --force --filter label=org.opencontainers.image.title=kamal-proxy", output
|
|
||||||
assert_match "Downgraded to Traefik on #{host}", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_command(*command)
|
def run_command(*command)
|
||||||
stdouted { Kamal::Cli::Traefik.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
stdouted { Kamal::Cli::Traefik.start([ *command, "-c", "test/fixtures/deploy_with_accessories.yml" ]) }
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "target multiarch remote when local and remote is set" do
|
test "target multiarch remote when local and remote is set" do
|
||||||
builder = new_builder_command(builder: { "local" => { "arch" => "arm64" }, "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } })
|
builder = new_builder_command(builder: { "local" => {}, "remote" => {}, "cache" => { "type" => "gha" } })
|
||||||
assert_equal "multiarch/remote", builder.name
|
assert_equal "multiarch/remote", builder.name
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker buildx build --push --platform linux/arm64,linux/amd64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
|
||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
21
test/fixtures/deploy_with_aliases.yml
vendored
Normal file
21
test/fixtures/deploy_with_aliases.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
service: app
|
||||||
|
image: dhh/app
|
||||||
|
servers:
|
||||||
|
web:
|
||||||
|
- 1.1.1.1
|
||||||
|
- 1.1.1.2
|
||||||
|
workers:
|
||||||
|
hosts:
|
||||||
|
- 1.1.1.3
|
||||||
|
- 1.1.1.4
|
||||||
|
console:
|
||||||
|
hosts:
|
||||||
|
- 1.1.1.5
|
||||||
|
registry:
|
||||||
|
username: user
|
||||||
|
password: pw
|
||||||
|
aliases:
|
||||||
|
info: details
|
||||||
|
console: app exec --reuse -p -r console "bin/console"
|
||||||
|
exec: app exec --reuse -p -r console
|
||||||
|
rails: app exec --reuse -p -r console rails
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "About to lock..."
|
echo "About to lock..."
|
||||||
if [ "$KAMAL_HOSTS" != "vm1,vm2" ]; then
|
|
||||||
echo "Expected hosts to be 'vm1,vm2', got $KAMAL_HOSTS"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ traefik:
|
|||||||
args:
|
args:
|
||||||
accesslog: true
|
accesslog: true
|
||||||
accesslog.format: json
|
accesslog.format: json
|
||||||
image: registry:4443/traefik:v2.11
|
image: registry:4443/traefik:v2.10
|
||||||
accessories:
|
accessories:
|
||||||
busybox:
|
busybox:
|
||||||
service: custom-busybox
|
service: custom-busybox
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "About to lock..."
|
echo "About to lock..."
|
||||||
if [ "$KAMAL_HOSTS" != "vm1,vm2,vm3" ]; then
|
|
||||||
echo "Expected hosts to be 'vm1,vm2,vm3', got $KAMAL_HOSTS"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ traefik:
|
|||||||
args:
|
args:
|
||||||
accesslog: true
|
accesslog: true
|
||||||
accesslog.format: json
|
accesslog.format: json
|
||||||
image: registry:4443/traefik:v2.11
|
image: registry:4443/traefik:v2.10
|
||||||
accessories:
|
accessories:
|
||||||
busybox:
|
busybox:
|
||||||
service: custom-busybox
|
service: custom-busybox
|
||||||
@@ -37,3 +37,7 @@ accessories:
|
|||||||
- web
|
- web
|
||||||
stop_wait_time: 1
|
stop_wait_time: 1
|
||||||
readiness_delay: 0
|
readiness_delay: 0
|
||||||
|
aliases:
|
||||||
|
whome: version
|
||||||
|
worker_hostname: app exec -r workers -q --reuse hostname
|
||||||
|
uname: server exec -q -p uname
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ push_image_to_registry_4443() {
|
|||||||
|
|
||||||
install_kamal
|
install_kamal
|
||||||
push_image_to_registry_4443 nginx 1-alpine-slim
|
push_image_to_registry_4443 nginx 1-alpine-slim
|
||||||
push_image_to_registry_4443 traefik v2.11
|
push_image_to_registry_4443 traefik v2.10
|
||||||
push_image_to_registry_4443 busybox 1.36.0
|
push_image_to_registry_4443 busybox 1.36.0
|
||||||
|
|
||||||
# .ssh is on a shared volume that persists between runs. Clean it up as the
|
# .ssh is on a shared volume that persists between runs. Clean it up as the
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class MainTest < IntegrationTest
|
|||||||
assert_match /Traefik Host: vm2/, details
|
assert_match /Traefik Host: vm2/, details
|
||||||
assert_match /App Host: vm1/, details
|
assert_match /App Host: vm1/, details
|
||||||
assert_match /App Host: vm2/, details
|
assert_match /App Host: vm2/, details
|
||||||
assert_match /traefik:v2.11/, details
|
assert_match /traefik:v2.10/, details
|
||||||
assert_match /registry:4443\/app:#{first_version}/, details
|
assert_match /registry:4443\/app:#{first_version}/, details
|
||||||
|
|
||||||
audit = kamal :audit, capture: true
|
audit = kamal :audit, capture: true
|
||||||
@@ -82,6 +82,22 @@ class MainTest < IntegrationTest
|
|||||||
assert_equal({ "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1", "interval"=>"1s", "max_attempts"=>3, "port"=>3000, "path"=>"/up", "cord"=>"/tmp/kamal-cord", "log_lines"=>50 }, config[:healthcheck])
|
assert_equal({ "cmd"=>"wget -qO- http://localhost > /dev/null || exit 1", "interval"=>"1s", "max_attempts"=>3, "port"=>3000, "path"=>"/up", "cord"=>"/tmp/kamal-cord", "log_lines"=>50 }, config[:healthcheck])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "aliases" do
|
||||||
|
@app = "app_with_roles"
|
||||||
|
|
||||||
|
kamal :envify
|
||||||
|
kamal :deploy
|
||||||
|
|
||||||
|
output = kamal :whome, capture: true
|
||||||
|
assert_equal Kamal::VERSION, output
|
||||||
|
|
||||||
|
output = kamal :worker_hostname, capture: true
|
||||||
|
assert_match /App Host: vm3\nvm3-[0-9a-f]{12}$/, output
|
||||||
|
|
||||||
|
output = kamal :uname, "-o", capture: true
|
||||||
|
assert_match "App Host: vm1\nGNU/Linux", output
|
||||||
|
end
|
||||||
|
|
||||||
test "setup and remove" do
|
test "setup and remove" do
|
||||||
# Check remove completes when nothing has been setup yet
|
# Check remove completes when nothing has been setup yet
|
||||||
kamal :remove, "-y"
|
kamal :remove, "-y"
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ class TraefikTest < IntegrationTest
|
|||||||
|
|
||||||
private
|
private
|
||||||
def assert_traefik_running
|
def assert_traefik_running
|
||||||
assert_match /traefik:v2.11 "\/entrypoint.sh/, traefik_details
|
assert_match /traefik:v2.10 "\/entrypoint.sh/, traefik_details
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_traefik_not_running
|
def assert_traefik_not_running
|
||||||
assert_no_match /traefik:v2.11 "\/entrypoint.sh/, traefik_details
|
assert_no_match /traefik:v2.10 "\/entrypoint.sh/, traefik_details
|
||||||
end
|
end
|
||||||
|
|
||||||
def traefik_details
|
def traefik_details
|
||||||
|
|||||||
Reference in New Issue
Block a user