Add Rubocop
- Pull in the 37signals house style - Autofix violations - Add to CI
This commit is contained in:
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@@ -5,6 +5,21 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
|
rubocop:
|
||||||
|
name: RuboCop
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
BUNDLE_ONLY: rubocop
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Ruby and install gems
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 3.3.0
|
||||||
|
bundler-cache: true
|
||||||
|
- name: Run Rubocop
|
||||||
|
run: bundle exec rubocop --parallel
|
||||||
tests:
|
tests:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|||||||
1
.rubocop.yml
Normal file
1
.rubocop.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
inherit_gem: { rubocop-37signals: rubocop.yml }
|
||||||
6
Gemfile
6
Gemfile
@@ -1,4 +1,8 @@
|
|||||||
source 'https://rubygems.org'
|
source "https://rubygems.org"
|
||||||
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
|
group :rubocop do
|
||||||
|
gem "rubocop-37signals", github: "basecamp/house-style", require: false
|
||||||
|
end
|
||||||
|
|||||||
47
Gemfile.lock
47
Gemfile.lock
@@ -1,3 +1,13 @@
|
|||||||
|
GIT
|
||||||
|
remote: https://github.com/basecamp/house-style.git
|
||||||
|
revision: a9ca7e4ab80b72c1a10053c50efefe8cd275e3b8
|
||||||
|
specs:
|
||||||
|
rubocop-37signals (1.0.0)
|
||||||
|
rubocop
|
||||||
|
rubocop-minitest
|
||||||
|
rubocop-performance
|
||||||
|
rubocop-rails
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
@@ -42,6 +52,7 @@ GEM
|
|||||||
minitest (>= 5.1)
|
minitest (>= 5.1)
|
||||||
mutex_m
|
mutex_m
|
||||||
tzinfo (~> 2.0)
|
tzinfo (~> 2.0)
|
||||||
|
ast (2.4.2)
|
||||||
base64 (0.2.0)
|
base64 (0.2.0)
|
||||||
bcrypt_pbkdf (1.1.0)
|
bcrypt_pbkdf (1.1.0)
|
||||||
bigdecimal (3.1.5)
|
bigdecimal (3.1.5)
|
||||||
@@ -63,6 +74,8 @@ GEM
|
|||||||
irb (1.11.0)
|
irb (1.11.0)
|
||||||
rdoc
|
rdoc
|
||||||
reline (>= 0.3.8)
|
reline (>= 0.3.8)
|
||||||
|
json (2.7.1)
|
||||||
|
language_server-protocol (3.17.0.3)
|
||||||
loofah (2.22.0)
|
loofah (2.22.0)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
@@ -79,6 +92,10 @@ GEM
|
|||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.16.0-x86_64-linux)
|
nokogiri (1.16.0-x86_64-linux)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
|
parallel (1.24.0)
|
||||||
|
parser (3.3.0.5)
|
||||||
|
ast (~> 2.4.1)
|
||||||
|
racc
|
||||||
psych (5.1.2)
|
psych (5.1.2)
|
||||||
stringio
|
stringio
|
||||||
racc (1.7.3)
|
racc (1.7.3)
|
||||||
@@ -105,11 +122,39 @@ GEM
|
|||||||
rake (>= 12.2)
|
rake (>= 12.2)
|
||||||
thor (~> 1.0, >= 1.2.2)
|
thor (~> 1.0, >= 1.2.2)
|
||||||
zeitwerk (~> 2.6)
|
zeitwerk (~> 2.6)
|
||||||
|
rainbow (3.1.1)
|
||||||
rake (13.1.0)
|
rake (13.1.0)
|
||||||
rdoc (6.6.2)
|
rdoc (6.6.2)
|
||||||
psych (>= 4.0.0)
|
psych (>= 4.0.0)
|
||||||
|
regexp_parser (2.9.0)
|
||||||
reline (0.4.2)
|
reline (0.4.2)
|
||||||
io-console (~> 0.5)
|
io-console (~> 0.5)
|
||||||
|
rexml (3.2.6)
|
||||||
|
rubocop (1.61.0)
|
||||||
|
json (~> 2.3)
|
||||||
|
language_server-protocol (>= 3.17.0)
|
||||||
|
parallel (~> 1.10)
|
||||||
|
parser (>= 3.3.0.2)
|
||||||
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
|
regexp_parser (>= 1.8, < 3.0)
|
||||||
|
rexml (>= 3.2.5, < 4.0)
|
||||||
|
rubocop-ast (>= 1.30.0, < 2.0)
|
||||||
|
ruby-progressbar (~> 1.7)
|
||||||
|
unicode-display_width (>= 2.4.0, < 3.0)
|
||||||
|
rubocop-ast (1.31.1)
|
||||||
|
parser (>= 3.3.0.4)
|
||||||
|
rubocop-minitest (0.34.5)
|
||||||
|
rubocop (>= 1.39, < 2.0)
|
||||||
|
rubocop-ast (>= 1.30.0, < 2.0)
|
||||||
|
rubocop-performance (1.20.2)
|
||||||
|
rubocop (>= 1.48.1, < 2.0)
|
||||||
|
rubocop-ast (>= 1.30.0, < 2.0)
|
||||||
|
rubocop-rails (2.24.0)
|
||||||
|
activesupport (>= 4.2.0)
|
||||||
|
rack (>= 1.1)
|
||||||
|
rubocop (>= 1.33.0, < 2.0)
|
||||||
|
rubocop-ast (>= 1.31.1, < 2.0)
|
||||||
|
ruby-progressbar (1.13.0)
|
||||||
ruby2_keywords (0.0.5)
|
ruby2_keywords (0.0.5)
|
||||||
sshkit (1.21.7)
|
sshkit (1.21.7)
|
||||||
mutex_m
|
mutex_m
|
||||||
@@ -119,6 +164,7 @@ GEM
|
|||||||
thor (1.3.0)
|
thor (1.3.0)
|
||||||
tzinfo (2.0.6)
|
tzinfo (2.0.6)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
unicode-display_width (2.5.0)
|
||||||
webrick (1.8.1)
|
webrick (1.8.1)
|
||||||
zeitwerk (2.6.12)
|
zeitwerk (2.6.12)
|
||||||
|
|
||||||
@@ -132,6 +178,7 @@ DEPENDENCIES
|
|||||||
kamal!
|
kamal!
|
||||||
mocha
|
mocha
|
||||||
railties
|
railties
|
||||||
|
rubocop-37signals!
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.4.3
|
2.4.3
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
if name == "all"
|
if name == "all"
|
||||||
KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
|
KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
|
||||||
else
|
else
|
||||||
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w[ y N ], default: "N") == "y"
|
||||||
with_accessory(name) do
|
with_accessory(name) do
|
||||||
stop(name)
|
stop(name)
|
||||||
remove_container(name)
|
remove_container(name)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ module Kamal::Cli
|
|||||||
def print_runtime
|
def print_runtime
|
||||||
started_at = Time.now
|
started_at = Time.now
|
||||||
yield
|
yield
|
||||||
return Time.now - started_at
|
Time.now - started_at
|
||||||
ensure
|
ensure
|
||||||
runtime = Time.now - started_at
|
runtime = Time.now - started_at
|
||||||
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
||||||
def remove
|
def remove
|
||||||
mutating do
|
mutating do
|
||||||
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w[ y N ], default: "N") == "y"
|
||||||
invoke "kamal:cli:traefik:remove", [], options.without(:confirmed)
|
invoke "kamal:cli:traefik:remove", [], options.without(:confirmed)
|
||||||
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
|
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
|
||||||
invoke "kamal:cli:accessory:remove", [ "all" ], options
|
invoke "kamal:cli:accessory:remove", [ "all" ], options
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
||||||
|
|
||||||
def run
|
def run
|
||||||
primary = config.role(config.primary_role)
|
primary = config.role(config.primary_role)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|||||||
DEFAULT_IMAGE = "traefik:v2.10"
|
DEFAULT_IMAGE = "traefik:v2.10"
|
||||||
CONTAINER_PORT = 80
|
CONTAINER_PORT = 80
|
||||||
DEFAULT_ARGS = {
|
DEFAULT_ARGS = {
|
||||||
'log.level' => 'DEBUG'
|
"log.level" => "DEBUG"
|
||||||
}
|
}
|
||||||
DEFAULT_LABELS = {
|
DEFAULT_LABELS = {
|
||||||
# These ensure we serve a 502 rather than a 404 if no containers are available
|
# These ensure we serve a 502 rather than a 404 if no containers are available
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Kamal::EnvFile
|
|||||||
|
|
||||||
private
|
private
|
||||||
def docker_env_file_line(key, value)
|
def docker_env_file_line(key, value)
|
||||||
"#{key.to_s}=#{escape_docker_env_file_value(value)}\n"
|
"#{key}=#{escape_docker_env_file_value(value)}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Escape a value to make it safe to dump in a docker file.
|
# Escape a value to make it safe to dump in a docker file.
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ 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('\*', '.*')
|
pattern = Regexp.escape(filter).gsub('\*', ".*")
|
||||||
# items are roles or hosts
|
# items are roles or hosts
|
||||||
(item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
|
(item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -154,9 +154,9 @@ class CliAccessoryTest < CliTestCase
|
|||||||
|
|
||||||
run_command("boot", "redis", "--hosts", "1.1.1.1").tap do |output|
|
run_command("boot", "redis", "--hosts", "1.1.1.1").tap do |output|
|
||||||
assert_match /docker login.*on 1.1.1.1/, output
|
assert_match /docker login.*on 1.1.1.1/, output
|
||||||
refute_match /docker login.*on 1.1.1.2/, output
|
assert_no_match /docker login.*on 1.1.1.2/, output
|
||||||
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
refute_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
assert_no_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.2", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -166,9 +166,9 @@ class CliAccessoryTest < CliTestCase
|
|||||||
|
|
||||||
run_command("boot", "redis", "--hosts", "1.1.1.1,1.1.1.3").tap do |output|
|
run_command("boot", "redis", "--hosts", "1.1.1.1,1.1.1.3").tap do |output|
|
||||||
assert_match /docker login.*on 1.1.1.1/, output
|
assert_match /docker login.*on 1.1.1.1/, output
|
||||||
refute_match /docker login.*on 1.1.1.3/, output
|
assert_no_match /docker login.*on 1.1.1.3/, output
|
||||||
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
assert_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.1", output
|
||||||
refute_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.3", output
|
assert_no_match "docker run --name app-redis --detach --restart unless-stopped --log-opt max-size=\"10m\" --publish 6379:6379 --env-file .kamal/env/accessories/app-redis.env --volume $PWD/app-redis/data:/data --label service=\"app-redis\" redis:latest on 1.1.1.3", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CliAppTest < CliTestCase
|
|||||||
.returns("123") # old version
|
.returns("123") # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(: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)
|
.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("cordfile") # old version
|
.returns("cordfile") # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
@@ -57,7 +57,7 @@ class CliAppTest < CliTestCase
|
|||||||
test "boot errors leave lock in place" do
|
test "boot errors leave lock in place" do
|
||||||
Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
|
Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
|
||||||
|
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
assert_raises(RuntimeError) do
|
assert_raises(RuntimeError) do
|
||||||
stderred { run_command("boot") }
|
stderred { run_command("boot") }
|
||||||
end
|
end
|
||||||
@@ -79,7 +79,7 @@ class CliAppTest < CliTestCase
|
|||||||
.returns("123").twice # old version
|
.returns("123").twice # old version
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(: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)
|
.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
|
.returns("") # old version
|
||||||
|
|
||||||
run_command("boot", config: :with_assets).tap do |output|
|
run_command("boot", config: :with_assets).tap do |output|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class CliEnvTest < CliTestCase
|
|||||||
assert_match ".kamal/env/roles/app-workers.env", output
|
assert_match ".kamal/env/roles/app-workers.env", output
|
||||||
assert_match ".kamal/env/traefik/traefik.env", output
|
assert_match ".kamal/env/traefik/traefik.env", output
|
||||||
assert_match ".kamal/env/accessories/app-redis.env", output
|
assert_match ".kamal/env/accessories/app-redis.env", output
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -135,11 +135,11 @@ class CliMainTest < CliTestCase
|
|||||||
.with("kamal:cli:registry:login", [], invoke_options)
|
.with("kamal:cli:registry:login", [], invoke_options)
|
||||||
.raises(RuntimeError)
|
.raises(RuntimeError)
|
||||||
|
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
assert_raises(RuntimeError) do
|
assert_raises(RuntimeError) do
|
||||||
stderred { run_command("deploy") }
|
stderred { run_command("deploy") }
|
||||||
end
|
end
|
||||||
assert !KAMAL.holding_lock?
|
assert_not KAMAL.holding_lock?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "deploy with skipped hooks" do
|
test "deploy with skipped hooks" do
|
||||||
@@ -154,7 +154,7 @@ class CliMainTest < CliTestCase
|
|||||||
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
|
||||||
|
|
||||||
run_command("deploy", "--skip_hooks") do
|
run_command("deploy", "--skip_hooks") do
|
||||||
refute_match /Running the post-deploy hook.../, output
|
assert_no_match /Running the post-deploy hook.../, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ class CliMainTest < CliTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-version-to-rollback", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
|
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-version-to-rollback", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", raise_on_non_zero_exit: false)
|
||||||
.returns("corddirectory").at_least_once # health check
|
.returns("corddirectory").at_least_once # health check
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
|
||||||
|
|||||||
@@ -103,14 +103,14 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "execute in new container over ssh" do
|
test "execute in new container over ssh" do
|
||||||
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/accessories/app-mysql.env private.registry/mysql:8.0 mysql -u root|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/accessories/app-mysql.env private.registry/mysql:8.0 mysql -u root},
|
||||||
new_command(:mysql).execute_in_new_container_over_ssh("mysql", "-u", "root")
|
new_command(:mysql).execute_in_new_container_over_ssh("mysql", "-u", "root")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in existing container over ssh" do
|
test "execute in existing container over ssh" do
|
||||||
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
new_command(:mysql).stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do
|
||||||
assert_match %r|docker exec -it app-mysql mysql -u root|,
|
assert_match %r{docker exec -it app-mysql mysql -u root},
|
||||||
new_command(:mysql).execute_in_existing_container_over_ssh("mysql", "-u", "root")
|
new_command(:mysql).execute_in_existing_container_over_ssh("mysql", "-u", "root")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -191,18 +191,18 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "execute in new container over ssh" do
|
test "execute in new container over ssh" do
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/roles/app-web.env dhh/app:999 bin/rails c|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/roles/app-web.env dhh/app:999 bin/rails c},
|
||||||
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in new container with custom options over ssh" do
|
test "execute in new container with custom options over ssh" do
|
||||||
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
||||||
assert_match %r|docker run -it --rm --env-file .kamal/env/roles/app-web.env --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c|,
|
assert_match %r{docker run -it --rm --env-file .kamal/env/roles/app-web.env --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c},
|
||||||
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute in existing container over ssh" do
|
test "execute in existing container over ssh" do
|
||||||
assert_match %r|docker exec -it app-web-999 bin/rails c|,
|
assert_match %r{docker exec -it app-web-999 bin/rails c},
|
||||||
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
:mkdir, "-p", ".kamal/assets/volumes/app-web-999", ";",
|
:mkdir, "-p", ".kamal/assets/volumes/app-web-999", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-999", ";",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-999", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-998", "|| true", ";",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-999", ".kamal/assets/volumes/app-web-998", "|| true", ";",
|
||||||
:cp, "-rnT", ".kamal/assets/extracted/app-web-998", ".kamal/assets/volumes/app-web-999", "|| true",
|
:cp, "-rnT", ".kamal/assets/extracted/app-web-998", ".kamal/assets/volumes/app-web-999", "|| true"
|
||||||
], new_command(asset_path: "/public/assets").sync_asset_volumes(old_version: 998)
|
], new_command(asset_path: "/public/assets").sync_asset_volumes(old_version: 998)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "build with ssh agent socket" do
|
test "build with ssh agent socket" do
|
||||||
builder = new_builder_command(builder: { "ssh" => 'default=$SSH_AUTH_SOCK' })
|
builder = new_builder_command(builder: { "ssh" => "default=$SSH_AUTH_SOCK" })
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --ssh default=$SSH_AUTH_SOCK",
|
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --ssh default=$SSH_AUTH_SOCK",
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase
|
|||||||
test "traefik logs since 2h" do
|
test "traefik logs since 2h" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker logs traefik --since 2h --timestamps 2>&1",
|
"docker logs traefik --since 2h --timestamps 2>&1",
|
||||||
new_command.logs(since: '2h').join(" ")
|
new_command.logs(since: "2h").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "traefik logs last 10 lines" do
|
test "traefik logs last 10 lines" do
|
||||||
@@ -150,7 +150,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase
|
|||||||
test "traefik logs with grep hello!" do
|
test "traefik logs with grep hello!" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker logs traefik --timestamps 2>&1 | grep 'hello!'",
|
"docker logs traefik --timestamps 2>&1 | grep 'hello!'",
|
||||||
new_command.logs(grep: 'hello!').join(" ")
|
new_command.logs(grep: "hello!").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "traefik remove container" do
|
test "traefik remove container" do
|
||||||
@@ -174,7 +174,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase
|
|||||||
test "traefik follow logs with grep hello!" do
|
test "traefik follow logs with grep hello!" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"ssh -t root@1.1.1.1 -p 22 'docker logs traefik --timestamps --tail 10 --follow 2>&1 | grep \"hello!\"'",
|
"ssh -t root@1.1.1.1 -p 22 'docker logs traefik --timestamps --tail 10 --follow 2>&1 | grep \"hello!\"'",
|
||||||
new_command.follow_logs(host: @config[:servers].first, grep: 'hello!')
|
new_command.follow_logs(host: @config[:servers].first, grep: "hello!")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env_file" do
|
test "env_file" do
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
},
|
},
|
||||||
"secret" => [
|
"secret" => [
|
||||||
"MYSQL_ROOT_PASSWORD"
|
"MYSQL_ROOT_PASSWORD"
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
"files" => [
|
"files" => [
|
||||||
"config/mysql/my.cnf:/etc/mysql/my.cnf",
|
"config/mysql/my.cnf:/etc/mysql/my.cnf",
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "setting ssh params" do
|
test "setting ssh params" do
|
||||||
@deploy_with_builder_option[:builder] = { "ssh" => 'default=$SSH_AUTH_SOCK' }
|
@deploy_with_builder_option[:builder] = { "ssh" => "default=$SSH_AUTH_SOCK" }
|
||||||
|
|
||||||
assert_equal 'default=$SSH_AUTH_SOCK', @config_with_builder_option.builder.ssh
|
assert_equal "default=$SSH_AUTH_SOCK", @config_with_builder_option.builder.ssh
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
@deploy_with_roles[:servers]["workers"]["env"] = {
|
@deploy_with_roles[:servers]["workers"]["env"] = {
|
||||||
"clear" => {
|
"clear" => {
|
||||||
"REDIS_URL" => "redis://c/d",
|
"REDIS_URL" => "redis://c/d"
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ENV["REDIS_PASSWORD"] = "secret456"
|
ENV["REDIS_PASSWORD"] = "secret456"
|
||||||
@@ -214,7 +214,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "uses cord" do
|
test "uses cord" do
|
||||||
assert @config_with_roles.role(:web).uses_cord?
|
assert @config_with_roles.role(:web).uses_cord?
|
||||||
assert !@config_with_roles.role(:workers).uses_cord?
|
assert_not @config_with_roles.role(:workers).uses_cord?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cord host file" do
|
test "cord host file" do
|
||||||
@@ -238,8 +238,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_nil @config_with_roles.role(:workers).asset_volume_args
|
assert_nil @config_with_roles.role(:workers).asset_volume_args
|
||||||
assert_nil @config_with_roles.role(:web).asset_path
|
assert_nil @config_with_roles.role(:web).asset_path
|
||||||
assert_nil @config_with_roles.role(:workers).asset_path
|
assert_nil @config_with_roles.role(:workers).asset_path
|
||||||
assert !@config_with_roles.role(:web).assets?
|
assert_not @config_with_roles.role(:web).assets?
|
||||||
assert !@config_with_roles.role(:workers).assets?
|
assert_not @config_with_roles.role(:workers).assets?
|
||||||
|
|
||||||
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
||||||
c[:asset_path] = "foo"
|
c[:asset_path] = "foo"
|
||||||
@@ -249,7 +249,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:foo" ], config_with_assets.role(:web).asset_volume_args
|
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:foo" ], config_with_assets.role(:web).asset_volume_args
|
||||||
assert_nil config_with_assets.role(:workers).asset_volume_args
|
assert_nil config_with_assets.role(:workers).asset_volume_args
|
||||||
assert config_with_assets.role(:web).assets?
|
assert config_with_assets.role(:web).assets?
|
||||||
assert !config_with_assets.role(:workers).assets?
|
assert_not config_with_assets.role(:workers).assets?
|
||||||
|
|
||||||
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
config_with_assets = Kamal::Configuration.new(@deploy_with_roles.dup.tap { |c|
|
||||||
c[:servers]["web"] = { "hosts" => [ "1.1.1.1", "1.1.1.2" ], "asset_path" => "bar" }
|
c[:servers]["web"] = { "hosts" => [ "1.1.1.1", "1.1.1.2" ], "asset_path" => "bar" }
|
||||||
@@ -259,7 +259,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:bar" ], config_with_assets.role(:web).asset_volume_args
|
assert_equal [ "--volume", "$(pwd)/.kamal/assets/volumes/app-web-12345:bar" ], config_with_assets.role(:web).asset_volume_args
|
||||||
assert_nil config_with_assets.role(:workers).asset_volume_args
|
assert_nil config_with_assets.role(:workers).asset_volume_args
|
||||||
assert config_with_assets.role(:web).assets?
|
assert config_with_assets.role(:web).assets?
|
||||||
assert !config_with_assets.role(:workers).assets?
|
assert_not config_with_assets.role(:workers).assets?
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
ENV.delete("VERSION")
|
ENV.delete("VERSION")
|
||||||
|
|||||||
@@ -240,19 +240,19 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "to_h" do
|
test "to_h" do
|
||||||
expected_config = \
|
expected_config = \
|
||||||
{ :roles=>["web"],
|
{ roles: [ "web" ],
|
||||||
:hosts=>["1.1.1.1", "1.1.1.2"],
|
hosts: [ "1.1.1.1", "1.1.1.2" ],
|
||||||
:primary_host=>"1.1.1.1",
|
primary_host: "1.1.1.1",
|
||||||
:version=>"missing",
|
version: "missing",
|
||||||
:repository=>"dhh/app",
|
repository: "dhh/app",
|
||||||
:absolute_image=>"dhh/app:missing",
|
absolute_image: "dhh/app:missing",
|
||||||
:service_with_version=>"app-missing",
|
service_with_version: "app-missing",
|
||||||
:ssh_options=>{ :user=>"root", port: 22, log_level: :fatal, keepalive: true, keepalive_interval: 30 },
|
ssh_options: { user: "root", port: 22, log_level: :fatal, keepalive: true, keepalive_interval: 30 },
|
||||||
:sshkit=>{},
|
sshkit: {},
|
||||||
:volume_args=>["--volume", "/local/path:/container/path"],
|
volume_args: [ "--volume", "/local/path:/container/path" ],
|
||||||
:builder=>{},
|
builder: {},
|
||||||
:logging=>["--log-opt", "max-size=\"10m\""],
|
logging: [ "--log-opt", "max-size=\"10m\"" ],
|
||||||
:healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 }}
|
healthcheck: { "path"=>"/up", "port"=>3000, "max_attempts" => 7, "exposed_port" => 3999, "cord" => "/tmp/kamal-cord", "log_lines" => 50 } }
|
||||||
|
|
||||||
assert_equal expected_config, @config.to_h
|
assert_equal expected_config, @config.to_h
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class AccessoryTest < IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_accessory_not_running(name)
|
def assert_accessory_not_running(name)
|
||||||
refute_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
assert_no_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accessory_details(name)
|
def accessory_details(name)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class TraefikTest < IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_traefik_not_running
|
def assert_traefik_not_running
|
||||||
refute_match /traefik:v2.10 "\/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