From e7ac73be5afd149ae6d540e65070692c0e6f091f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 4 Feb 2023 10:14:31 +0100 Subject: [PATCH] Join in run_over_ssh instead of all over --- lib/mrsk/commands/accessory.rb | 4 ++-- lib/mrsk/commands/app.rb | 16 +++++++++------- lib/mrsk/commands/base.rb | 4 ++-- test/commands/accessory_test.rb | 4 ++-- test/commands/app_test.rb | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/mrsk/commands/accessory.rb b/lib/mrsk/commands/accessory.rb index 0e9c5c12..be7d59b5 100644 --- a/lib/mrsk/commands/accessory.rb +++ b/lib/mrsk/commands/accessory.rb @@ -64,11 +64,11 @@ class Mrsk::Commands::Accessory < Mrsk::Commands::Base end def execute_in_existing_container_over_ssh(*command) - run_over_ssh execute_in_existing_container(*command, interactive: true).join(" ") + run_over_ssh execute_in_existing_container(*command, interactive: true) end def execute_in_new_container_over_ssh(*command) - run_over_ssh execute_in_new_container(*command, interactive: true).join(" ") + run_over_ssh execute_in_new_container(*command, interactive: true) end def run_over_ssh(command) diff --git a/lib/mrsk/commands/app.rb b/lib/mrsk/commands/app.rb index ae4fce97..7dd66503 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -35,11 +35,13 @@ class Mrsk::Commands::App < Mrsk::Commands::Base end def follow_logs(host:, grep: nil) - run_over_ssh pipe( - current_container_id, - "xargs docker logs -t -n 10 -f 2>&1", - (%(grep "#{grep}") if grep) - ).join(" "), host: host + run_over_ssh \ + pipe( + current_container_id, + "xargs docker logs -t -n 10 -f 2>&1", + (%(grep "#{grep}") if grep) + ), + host: host end @@ -62,11 +64,11 @@ class Mrsk::Commands::App < Mrsk::Commands::Base end def execute_in_existing_container_over_ssh(*command, host:) - run_over_ssh execute_in_existing_container(*command, interactive: true).join(" "), host: host + run_over_ssh execute_in_existing_container(*command, interactive: true), host: host end def execute_in_new_container_over_ssh(*command, host:) - run_over_ssh execute_in_new_container(*command, interactive: true).join(" "), host: host + run_over_ssh execute_in_new_container(*command, interactive: true), host: host end diff --git a/lib/mrsk/commands/base.rb b/lib/mrsk/commands/base.rb index 9c0bd1c7..7b7d644c 100644 --- a/lib/mrsk/commands/base.rb +++ b/lib/mrsk/commands/base.rb @@ -8,8 +8,8 @@ module Mrsk::Commands @config = config end - def run_over_ssh(command, host:) - "ssh -t #{config.ssh_user}@#{host} '#{command}'" + def run_over_ssh(*command, host:) + "ssh -t #{config.ssh_user}@#{host} '#{command.join(" ")}'" end private diff --git a/test/commands/accessory_test.rb b/test/commands/accessory_test.rb index 8a68cbb7..60add274 100644 --- a/test/commands/accessory_test.rb +++ b/test/commands/accessory_test.rb @@ -81,14 +81,14 @@ class CommandsAccessoryTest < ActiveSupport::TestCase end test "execute in new container over ssh" do - @mysql.stub(:run_over_ssh, ->(cmd) { cmd }) do + @mysql.stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do assert_match %r|docker run -it --rm -e MYSQL_ROOT_PASSWORD=secret123 -e MYSQL_ROOT_HOST=% mysql:8.0 mysql -u root|, @mysql.execute_in_new_container_over_ssh("mysql", "-u", "root") end end test "execute in existing container over ssh" do - @mysql.stub(:run_over_ssh, ->(cmd) { cmd }) do + @mysql.stub(:run_over_ssh, ->(cmd) { cmd.join(" ") }) do assert_match %r|docker exec -it app-mysql mysql -u root|, @mysql.execute_in_existing_container_over_ssh("mysql", "-u", "root") end diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 2cbc0eec..b39a3781 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -38,14 +38,14 @@ class CommandsAppTest < ActiveSupport::TestCase end test "execute in new container over ssh" do - @app.stub(:run_over_ssh, ->(cmd, host:) { cmd }) do + @app.stub(:run_over_ssh, ->(cmd, host:) { cmd.join(" ") }) do assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=456 dhh/app:missing bin/rails c|, @app.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1") end end test "execute in existing container over ssh" do - @app.stub(:run_over_ssh, ->(cmd, host:) { cmd }) do + @app.stub(:run_over_ssh, ->(cmd, host:) { cmd.join(" ") }) do assert_match %r|docker exec -it app-missing bin/rails c|, @app.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1") end