Compare commits
1 Commits
revert-905
...
dot-kamal-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70096160c9 |
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
kamal (2.0.0.alpha)
|
kamal (1.8.1)
|
||||||
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.3)
|
thor (~> 1.2)
|
||||||
zeitwerk (~> 2.5)
|
zeitwerk (~> 2.5)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
|
|||||||
20
bin/docs
20
bin/docs
@@ -17,7 +17,6 @@ end
|
|||||||
|
|
||||||
DOCS = {
|
DOCS = {
|
||||||
"accessory" => "Accessories",
|
"accessory" => "Accessories",
|
||||||
"alias" => "Aliases",
|
|
||||||
"boot" => "Booting",
|
"boot" => "Booting",
|
||||||
"builder" => "Builders",
|
"builder" => "Builders",
|
||||||
"configuration" => "Configuration overview",
|
"configuration" => "Configuration overview",
|
||||||
@@ -68,27 +67,26 @@ class DocWriter
|
|||||||
output.puts
|
output.puts
|
||||||
place = :new_section
|
place = :new_section
|
||||||
elsif line =~ /^ *#/
|
elsif line =~ /^ *#/
|
||||||
generate_line(line, heading: place == :new_section)
|
generate_line(line, place: place)
|
||||||
place = :in_section
|
place = :in_section
|
||||||
else
|
else
|
||||||
output.puts "```yaml"
|
output.puts "```yaml"
|
||||||
output.puts line
|
output.print line
|
||||||
place = :in_yaml
|
place = :in_yaml
|
||||||
end
|
end
|
||||||
when :in_yaml, :in_empty_line_yaml
|
when :in_yaml
|
||||||
if line =~ /^ *#/
|
if line =~ /^ *#/
|
||||||
output.puts "```"
|
output.puts "```"
|
||||||
generate_line(line, heading: place == :in_empty_line_yaml)
|
generate_line(line, place: :new_section)
|
||||||
place = :in_section
|
place = :in_section
|
||||||
elsif line.empty?
|
|
||||||
place = :in_empty_line_yaml
|
|
||||||
else
|
else
|
||||||
output.puts line
|
output.puts
|
||||||
|
output.print line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output.puts "```" if place == :in_yaml
|
output.puts "\n```" if place == :in_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_header
|
def generate_header
|
||||||
@@ -100,7 +98,7 @@ class DocWriter
|
|||||||
output.puts
|
output.puts
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_line(line, heading: false)
|
def generate_line(line, place: :in_section)
|
||||||
line = line.gsub(/^ *#\s?/, "")
|
line = line.gsub(/^ *#\s?/, "")
|
||||||
|
|
||||||
if line =~ /(.*)kamal docs ([a-z]*)(.*)/
|
if line =~ /(.*)kamal docs ([a-z]*)(.*)/
|
||||||
@@ -111,7 +109,7 @@ class DocWriter
|
|||||||
line = "#{$1}[#{titlify($2.split("/").last)}](#{$2})#{$3}"
|
line = "#{$1}[#{titlify($2.split("/").last)}](#{$2})#{$3}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if heading
|
if place == :new_section
|
||||||
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.3"
|
spec.add_dependency "thor", "~> 1.2"
|
||||||
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"
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
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,12 +71,11 @@ 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,8 +6,7 @@ module Kamal::Cli
|
|||||||
class Base < Thor
|
class Base < Thor
|
||||||
include SSHKit::DSL
|
include SSHKit::DSL
|
||||||
|
|
||||||
def self.exit_on_failure?() false end
|
def self.exit_on_failure?() true 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"
|
||||||
@@ -23,14 +22,8 @@ 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(args = [], local_options = {}, config = {})
|
def initialize(*)
|
||||||
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
|
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)
|
||||||
@@ -44,11 +37,24 @@ module Kamal::Cli
|
|||||||
|
|
||||||
def load_env
|
def load_env
|
||||||
if destination = options[:destination]
|
if destination = options[:destination]
|
||||||
Dotenv.load(".env.#{destination}", ".env")
|
if File.exist?(".kamal/env.#{destination}") || File.exist?(".kamal/env")
|
||||||
|
Dotenv.load(".kamal/env.#{destination}", ".kamal/env")
|
||||||
else
|
else
|
||||||
|
loading_files = [ (".env" if File.exist?(".env")), (".env.#{destination}" if File.exist?(".env.#{destination}")) ].compact
|
||||||
|
if loading_files.any?
|
||||||
|
warn "Loading #{loading_files.join(" and ")} from the project root, use .kamal/env* instead"
|
||||||
|
Dotenv.load(".env.#{destination}", ".env")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if File.exist?(".kamal/env")
|
||||||
|
Dotenv.load(".kamal/env")
|
||||||
|
elsif File.exist?(".env")
|
||||||
|
warn "Loading .env from the project root is deprecated, use .kamal/env instead"
|
||||||
Dotenv.load(".env")
|
Dotenv.load(".env")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def reset_env
|
def reset_env
|
||||||
replace_env @original_env
|
replace_env @original_env
|
||||||
|
|||||||
@@ -182,6 +182,15 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
desc "envify", "Create .env by evaluating .env.erb (or .env.staging.erb -> .env.staging when using -d staging)"
|
desc "envify", "Create .env by evaluating .env.erb (or .env.staging.erb -> .env.staging when using -d staging)"
|
||||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip .env file push"
|
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip .env file push"
|
||||||
def envify
|
def envify
|
||||||
|
if destination = options[:destination]
|
||||||
|
env_template_path = ".kamal/env.#{destination}.erb"
|
||||||
|
env_path = ".kamal/env.#{destination}"
|
||||||
|
else
|
||||||
|
env_template_path = ".kamal/env.erb"
|
||||||
|
env_path = ".kamal/env"
|
||||||
|
end
|
||||||
|
|
||||||
|
unless Pathname.new(File.expand_path(env_template_path)).exist?
|
||||||
if destination = options[:destination]
|
if destination = options[:destination]
|
||||||
env_template_path = ".env.#{destination}.erb"
|
env_template_path = ".env.#{destination}.erb"
|
||||||
env_path = ".env.#{destination}"
|
env_path = ".env.#{destination}"
|
||||||
@@ -190,6 +199,11 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
env_path = ".env"
|
env_path = ".env"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Pathname.new(File.expand_path(env_template_path)).exist?
|
||||||
|
warn "Loading #{env_template_path} from the project root is deprecated, use .kamal/env[.<DESTINATION>].erb instead"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Pathname.new(File.expand_path(env_template_path)).exist?
|
if Pathname.new(File.expand_path(env_template_path)).exist?
|
||||||
# Ensure existing env doesn't pollute template evaluation
|
# Ensure existing env doesn't pollute template evaluation
|
||||||
content = with_original_env { ERB.new(File.read(env_template_path), trim_mode: "-").result }
|
content = with_original_env { ERB.new(File.read(env_template_path), trim_mode: "-").result }
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
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
|
||||||
|
|||||||
@@ -27,12 +27,8 @@ class Kamal::Commander
|
|||||||
|
|
||||||
def specific_primary!
|
def specific_primary!
|
||||||
@specifics = nil
|
@specifics = nil
|
||||||
if specific_roles.present?
|
|
||||||
self.specific_hosts = [ specific_roles.first.primary_host ]
|
|
||||||
else
|
|
||||||
self.specific_hosts = [ config.primary_host ]
|
self.specific_hosts = [ config.primary_host ]
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def specific_roles=(role_names)
|
def specific_roles=(role_names)
|
||||||
@specifics = nil
|
@specifics = nil
|
||||||
@@ -117,10 +113,6 @@ 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
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ module Kamal::Commands::Builder::Clone
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clone
|
def clone
|
||||||
git :clone, Kamal::Git.root, "--recurse-submodules", path: clone_directory
|
git :clone, Kamal::Git.root, path: clone_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone_reset_steps
|
def clone_reset_steps
|
||||||
@@ -14,8 +14,7 @@ module Kamal::Commands::Builder::Clone
|
|||||||
git(:remote, "set-url", :origin, Kamal::Git.root, path: build_directory),
|
git(:remote, "set-url", :origin, Kamal::Git.root, path: build_directory),
|
||||||
git(:fetch, :origin, path: build_directory),
|
git(:fetch, :origin, path: build_directory),
|
||||||
git(:reset, "--hard", Kamal::Git.revision, path: build_directory),
|
git(:reset, "--hard", Kamal::Git.revision, path: build_directory),
|
||||||
git(:clean, "-fdx", path: build_directory),
|
git(:clean, "-fdx", path: build_directory)
|
||||||
git(:submodule, :update, "--init", path: build_directory)
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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, :aliases, :boot, :builder, :env, :healthcheck, :logging, :traefik, :servers, :ssh, :sshkit, :registry
|
attr_reader :accessories, :boot, :builder, :env, :healthcheck, :logging, :traefik, :servers, :ssh, :sshkit, :registry
|
||||||
|
|
||||||
include Validation
|
include Validation
|
||||||
|
|
||||||
@@ -54,7 +54,6 @@ 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 || {})
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# 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,9 +166,3 @@ 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:
|
|
||||||
...
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ env:
|
|||||||
# To pass the secrets you should list them under the `secret` key. When you do this the
|
# To pass the secrets you should list them under the `secret` key. When you do this the
|
||||||
# other variables need to be moved under the `clear` key.
|
# other variables need to be moved under the `clear` key.
|
||||||
#
|
#
|
||||||
# Unlike clear values, secrets are not passed directly to the container,
|
# Unlike clear valies, secrets are not passed directly to the container,
|
||||||
# but are stored in an env file on the host
|
# but are stored in an env file on the host
|
||||||
# The file is not updated when deploying, only when running `kamal envify` or `kamal env push`.
|
# The file is not updated when deploying, only when running `kamal envify` or `kamal env push`.
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ class Kamal::Configuration::Validator
|
|||||||
|
|
||||||
private
|
private
|
||||||
def validate_against_example!(validation_config, example)
|
def validate_against_example!(validation_config, example)
|
||||||
validate_type! validation_config, example.class
|
validate_type! validation_config, Hash
|
||||||
|
|
||||||
if example.class == Hash
|
|
||||||
check_unknown_keys! validation_config, example
|
check_unknown_keys! validation_config, example
|
||||||
|
|
||||||
validation_config.each do |key, value|
|
validation_config.each do |key, value|
|
||||||
@@ -44,7 +43,6 @@ class Kamal::Configuration::Validator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def valid_type?(value, type)
|
def valid_type?(value, type)
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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,8 +77,4 @@ 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 = "2.0.0.alpha"
|
VERSION = "1.8.1"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -247,12 +247,6 @@ 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
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class CliBuildTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "--version", "&&", :docker, :buildx, "version")
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "--version", "&&", :docker, :buildx, "version")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||||
.with(:git, "-C", "#{Dir.tmpdir}/kamal-clones/app-#{pwd_sha}", :clone, Dir.pwd, "--recurse-submodules")
|
.with(:git, "-C", "#{Dir.tmpdir}/kamal-clones/app-#{pwd_sha}", :clone, Dir.pwd)
|
||||||
.raises(SSHKit::Command::Failed.new("fatal: destination path 'kamal' already exists and is not an empty directory"))
|
.raises(SSHKit::Command::Failed.new("fatal: destination path 'kamal' already exists and is not an empty directory"))
|
||||||
.then
|
.then
|
||||||
.returns(true)
|
.returns(true)
|
||||||
@@ -50,7 +50,6 @@ class CliBuildTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :fetch, :origin)
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :fetch, :origin)
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :reset, "--hard", Kamal::Git.revision)
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :reset, "--hard", Kamal::Git.revision)
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :clean, "-fdx")
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :clean, "-fdx")
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:git, "-C", build_directory, :submodule, :update, "--init")
|
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||||
.with(:docker, :buildx, :build, "--push", "--platform", "linux/amd64,linux/arm64", "--builder", "kamal-app-multiarch", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".")
|
.with(:docker, :buildx, :build, "--push", "--platform", "linux/amd64,linux/arm64", "--builder", "kamal-app-multiarch", "-t", "dhh/app:999", "-t", "dhh/app:latest", "--label", "service=\"app\"", "--file", "Dockerfile", ".")
|
||||||
@@ -89,7 +88,7 @@ class CliBuildTest < CliTestCase
|
|||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "--version", "&&", :docker, :buildx, "version")
|
SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "--version", "&&", :docker, :buildx, "version")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
||||||
.with(:git, "-C", "#{Dir.tmpdir}/kamal-clones/app-#{pwd_sha}", :clone, Dir.pwd, "--recurse-submodules")
|
.with(:git, "-C", "#{Dir.tmpdir}/kamal-clones/app-#{pwd_sha}", :clone, Dir.pwd)
|
||||||
.raises(SSHKit::Command::Failed.new("fatal: destination path 'kamal' already exists and is not an empty directory"))
|
.raises(SSHKit::Command::Failed.new("fatal: destination path 'kamal' already exists and is not an empty directory"))
|
||||||
.then
|
.then
|
||||||
.returns(true)
|
.returns(true)
|
||||||
|
|||||||
@@ -63,12 +63,4 @@ 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
|
||||||
|
|||||||
@@ -447,9 +447,9 @@ class CliMainTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "envify" do
|
test "envify" do
|
||||||
with_test_dotenv(".env.erb": "HELLO=<%= 'world' %>") do
|
with_test_env_files("env.erb": "HELLO=<%= 'world' %>") do
|
||||||
run_command("envify")
|
run_command("envify")
|
||||||
assert_equal("HELLO=world", File.read(".env"))
|
assert_equal("HELLO=world", File.read(".kamal/env"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -461,32 +461,32 @@ class CliMainTest < CliTestCase
|
|||||||
<% end -%>
|
<% end -%>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
with_test_dotenv(".env.erb": file) do
|
with_test_env_files("env.erb": file) do
|
||||||
run_command("envify")
|
run_command("envify")
|
||||||
assert_equal("HELLO=world\nKEY=value\n", File.read(".env"))
|
assert_equal("HELLO=world\nKEY=value\n", File.read(".kamal/env"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "envify with destination" do
|
test "envify with destination" do
|
||||||
with_test_dotenv(".env.world.erb": "HELLO=<%= 'world' %>") do
|
with_test_env_files("env.world.erb": "HELLO=<%= 'world' %>") do
|
||||||
run_command("envify", "-d", "world", config_file: "deploy_for_dest")
|
run_command("envify", "-d", "world", config_file: "deploy_for_dest")
|
||||||
assert_equal "HELLO=world", File.read(".env.world")
|
assert_equal "HELLO=world", File.read(".kamal/env.world")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "envify with skip_push" do
|
test "envify with skip_push" do
|
||||||
Pathname.any_instance.expects(:exist?).returns(true).times(1)
|
Pathname.any_instance.expects(:exist?).returns(true).times(2)
|
||||||
File.expects(:read).with(".env.erb").returns("HELLO=<%= 'world' %>")
|
File.expects(:read).with(".kamal/env.erb").returns("HELLO=<%= 'world' %>")
|
||||||
File.expects(:write).with(".env", "HELLO=world", perm: 0600)
|
File.expects(:write).with(".kamal/env", "HELLO=world", perm: 0600)
|
||||||
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push").never
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push").never
|
||||||
run_command("envify", "--skip-push")
|
run_command("envify", "--skip-push")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "envify with clean env" do
|
test "envify with clean env" do
|
||||||
with_test_dotenv(".env": "HELLO=already", ".env.erb": "HELLO=<%= ENV.fetch 'HELLO', 'never' %>") do
|
with_test_env_files("env": "HELLO=already", "env.erb": "HELLO=<%= ENV.fetch 'HELLO', 'never' %>") do
|
||||||
run_command("envify", "--skip-push")
|
run_command("envify", "--skip-push")
|
||||||
assert_equal "HELLO=never", File.read(".env")
|
assert_equal "HELLO=never", File.read(".kamal/env")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -537,59 +537,24 @@ class CliMainTest < CliTestCase
|
|||||||
assert_equal Kamal::VERSION, version
|
assert_equal Kamal::VERSION, version
|
||||||
end
|
end
|
||||||
|
|
||||||
test "run an alias for details" do
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:details")
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
|
|
||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:details", [ "all" ])
|
|
||||||
|
|
||||||
run_command("info", config_file: "deploy_with_aliases")
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
test "run an alias for a console overriding role" do
|
|
||||||
run_command("console", "-r", "workers", config_file: "deploy_with_aliases").tap do |output|
|
|
||||||
assert_match "docker exec app-workers-999 bin/console on 1.1.1.3", output
|
|
||||||
assert_match "App Host: 1.1.1.3", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "run an alias for a console passing command" do
|
|
||||||
run_command("exec", "bin/job", config_file: "deploy_with_aliases").tap do |output|
|
|
||||||
assert_match "docker exec app-console-999 bin/job on 1.1.1.5", output
|
|
||||||
assert_match "App Host: 1.1.1.5", output
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "append to command with an alias" do
|
|
||||||
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
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_command(*command, config_file: "deploy_simple")
|
def run_command(*command, config_file: "deploy_simple")
|
||||||
with_argv([ *command, "-c", "test/fixtures/#{config_file}.yml" ]) do
|
stdouted { Kamal::Cli::Main.start([ *command, "-c", "test/fixtures/#{config_file}.yml" ]) }
|
||||||
stdouted { Kamal::Cli::Main.start }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_test_dotenv(**files)
|
def with_test_env_files(**files)
|
||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
fixtures_dup = File.join(dir, "test")
|
fixtures_dup = File.join(dir, "test")
|
||||||
FileUtils.mkdir_p(fixtures_dup)
|
FileUtils.mkdir_p(fixtures_dup)
|
||||||
FileUtils.cp_r("test/fixtures/", fixtures_dup)
|
FileUtils.cp_r("test/fixtures/", fixtures_dup)
|
||||||
|
|
||||||
Dir.chdir(dir) do
|
Dir.chdir(dir) do
|
||||||
|
FileUtils.mkdir_p(".kamal")
|
||||||
|
Dir.chdir(".kamal") do
|
||||||
files.each do |filename, contents|
|
files.each do |filename, contents|
|
||||||
File.binwrite(filename.to_s, contents)
|
File.binwrite(filename.to_s, contents)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,20 +15,6 @@ 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
|
||||||
|
|||||||
21
test/fixtures/deploy_with_aliases.yml
vendored
21
test/fixtures/deploy_with_aliases.yml
vendored
@@ -1,21 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -29,6 +29,8 @@ services:
|
|||||||
context: docker/registry
|
context: docker/registry
|
||||||
environment:
|
environment:
|
||||||
- REGISTRY_HTTP_ADDR=0.0.0.0:4443
|
- REGISTRY_HTTP_ADDR=0.0.0.0:4443
|
||||||
|
- REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
|
||||||
|
- REGISTRY_HTTP_TLS_KEY=/certs/domain.key
|
||||||
volumes:
|
volumes:
|
||||||
- shared:/shared
|
- shared:/shared
|
||||||
- registry:/var/lib/registry/
|
- registry:/var/lib/registry/
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ COPY app_with_roles/ app_with_roles/
|
|||||||
|
|
||||||
RUN rm -rf /root/.ssh
|
RUN rm -rf /root/.ssh
|
||||||
RUN ln -s /shared/ssh /root/.ssh
|
RUN ln -s /shared/ssh /root/.ssh
|
||||||
|
RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt /etc/docker/certs.d/registry:4443/ca.crt
|
||||||
|
|
||||||
RUN git config --global user.email "deployer@example.com"
|
RUN git config --global user.email "deployer@example.com"
|
||||||
RUN git config --global user.name "Deployer"
|
RUN git config --global user.name "Deployer"
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/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
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/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
|
||||||
|
|||||||
@@ -37,7 +37,3 @@ 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
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
dockerd --max-concurrent-downloads 1 --insecure-registry registry:4443 &
|
dockerd --max-concurrent-downloads 1 &
|
||||||
|
|
||||||
exec sleep infinity
|
exec sleep infinity
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
while [ ! -f /certs/domain.crt ]; do sleep 1; done
|
||||||
|
|
||||||
exec /entrypoint.sh /etc/docker/registry/config.yml
|
exec /entrypoint.sh /etc/docker/registry/config.yml
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ RUN mkdir ssh && \
|
|||||||
COPY registry-dns.conf .
|
COPY registry-dns.conf .
|
||||||
COPY boot.sh .
|
COPY boot.sh .
|
||||||
|
|
||||||
|
RUN mkdir certs && openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt -subj '/CN=registry' -extensions EXT -config registry-dns.conf
|
||||||
|
|
||||||
HEALTHCHECK --interval=1s CMD pgrep sleep
|
HEALTHCHECK --interval=1s CMD pgrep sleep
|
||||||
|
|
||||||
CMD ["./boot.sh"]
|
CMD ["./boot.sh"]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ WORKDIR /work
|
|||||||
RUN apt-get update --fix-missing && apt-get -y install openssh-client openssh-server docker.io
|
RUN apt-get update --fix-missing && apt-get -y install openssh-client openssh-server docker.io
|
||||||
|
|
||||||
RUN mkdir /root/.ssh && ln -s /shared/ssh/id_rsa.pub /root/.ssh/authorized_keys
|
RUN mkdir /root/.ssh && ln -s /shared/ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||||
|
RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt /etc/docker/certs.d/registry:4443/ca.crt
|
||||||
|
|
||||||
RUN echo "HOST_TOKEN=abcd" >> /etc/environment
|
RUN echo "HOST_TOKEN=abcd" >> /etc/environment
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ while [ ! -f /root/.ssh/authorized_keys ]; do echo "Waiting for ssh keys"; sleep
|
|||||||
|
|
||||||
service ssh restart
|
service ssh restart
|
||||||
|
|
||||||
dockerd --max-concurrent-downloads 1 --insecure-registry registry:4443 &
|
dockerd --max-concurrent-downloads 1 &
|
||||||
|
|
||||||
exec sleep infinity
|
exec sleep infinity
|
||||||
|
|||||||
@@ -82,22 +82,6 @@ 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"
|
||||||
@@ -113,7 +97,7 @@ class MainTest < IntegrationTest
|
|||||||
|
|
||||||
private
|
private
|
||||||
def assert_local_env_file(contents)
|
def assert_local_env_file(contents)
|
||||||
assert_equal contents, deployer_exec("cat .env", capture: true)
|
assert_equal contents, deployer_exec("cat .kamal/env", capture: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_envs(version:)
|
def assert_envs(version:)
|
||||||
@@ -143,7 +127,7 @@ class MainTest < IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_local_env_file
|
def remove_local_env_file
|
||||||
deployer_exec("rm .env")
|
deployer_exec("rm .kamal/env")
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_remote_env_file(contents, vm:)
|
def assert_remote_env_file(contents, vm:)
|
||||||
|
|||||||
Reference in New Issue
Block a user