From 5f9f70b1a03c48f43337daa9a708ea627ca413b6 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Tue, 8 Oct 2024 10:28:54 -0400 Subject: [PATCH 1/7] Update to be able to run on 3.4 with frozen strings --- .github/workflows/ci.yml | 6 ++++++ lib/kamal/commands/base.rb | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4fa1e801..187cb4753 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4.0-preview2" gemfile: - Gemfile - gemfiles/rails_edge.gemfile @@ -41,6 +42,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Remove gemfile.lock + run: rm Gemfile.lock + - name: Install Ruby uses: ruby/setup-ruby@v1 with: @@ -49,3 +53,5 @@ jobs: - name: Run tests run: bin/test + env: + RUBYOPT: ${{ matrix.ruby-version == '3.4.0-preview2' && '--enable=frozen-string-literal' || '' }} diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index 7521780ad..94a04a39c 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -11,13 +11,13 @@ def initialize(config) end def run_over_ssh(*command, host:) - "ssh".tap do |cmd| + "ssh".then do |cmd| if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump) - cmd << " -J #{config.ssh.proxy.jump_proxies}" + cmd = "#{cmd} -J #{config.ssh.proxy.jump_proxies}" elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command) - cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'" + cmd = "#{cmd} -o ProxyCommand='#{config.ssh.proxy.command_line_template}'" end - cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" + "#{cmd} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" end end From e8cdf52a1576fb9fa3cf02cbde77ba09a2559d60 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 9 Oct 2024 09:18:25 -0400 Subject: [PATCH 2/7] Extract conditional into method --- lib/kamal/commands/base.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index 94a04a39c..f3decdb69 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -11,14 +11,7 @@ def initialize(config) end def run_over_ssh(*command, host:) - "ssh".then do |cmd| - if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump) - cmd = "#{cmd} -J #{config.ssh.proxy.jump_proxies}" - elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command) - cmd = "#{cmd} -o ProxyCommand='#{config.ssh.proxy.command_line_template}'" - end - "#{cmd} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" - end + "ssh #{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" end def container_id_for(container_name:, only_running: false) @@ -92,5 +85,13 @@ def grep(*args) def tags(**details) Kamal::Tags.from_config(config, **details) end + + def ssh_proxy_args + if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump) + "-J #{config.ssh.proxy.jump_proxies}" + elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command) + "-o ProxyCommand='#{config.ssh.proxy.command_line_template}'" + end + end end end From 48869af8c9566dbca20e2ce22afd3cb87fe9b1ca Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 9 Oct 2024 09:31:00 -0400 Subject: [PATCH 3/7] Use case statement to clean things up --- lib/kamal/commands/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index f3decdb69..d3ca96185 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -87,9 +87,9 @@ def tags(**details) end def ssh_proxy_args - if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump) - "-J #{config.ssh.proxy.jump_proxies}" - elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command) + case config.ssh.proxy + when Net::SSH::Proxy::Jump then "-J #{config.ssh.proxy.jump_proxies}" + when Net::SSH::Proxy::Command "-o ProxyCommand='#{config.ssh.proxy.command_line_template}'" end end From 294020a8a3f6c1d29ff09a505218c6f11a6b3b88 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 9 Oct 2024 09:32:19 -0400 Subject: [PATCH 4/7] squish --- lib/kamal/commands/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index d3ca96185..0db2ebf85 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -11,7 +11,7 @@ def initialize(config) end def run_over_ssh(*command, host:) - "ssh #{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" + "ssh #{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'".squish end def container_id_for(container_name:, only_running: false) From 58a2320da9a342f6b20fb0129bb0261c98e0c500 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 9 Oct 2024 20:37:58 -0400 Subject: [PATCH 5/7] Update lib/kamal/commands/base.rb Co-authored-by: Sijawusz Pur Rahnama --- lib/kamal/commands/base.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index 0db2ebf85..62ccbe648 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -88,7 +88,8 @@ def tags(**details) def ssh_proxy_args case config.ssh.proxy - when Net::SSH::Proxy::Jump then "-J #{config.ssh.proxy.jump_proxies}" + when Net::SSH::Proxy::Jump + "-J #{config.ssh.proxy.jump_proxies}" when Net::SSH::Proxy::Command "-o ProxyCommand='#{config.ssh.proxy.command_line_template}'" end From 9724ddacb5caa69108657ecf7c84fbbce82bbf75 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 9 Oct 2024 20:41:10 -0400 Subject: [PATCH 6/7] Apply suggestions from code review Spacing --- lib/kamal/commands/base.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index 62ccbe648..0cb72632f 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -11,7 +11,7 @@ def initialize(config) end def run_over_ssh(*command, host:) - "ssh #{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'".squish + "ssh#{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'".squish end def container_id_for(container_name:, only_running: false) @@ -89,9 +89,9 @@ def tags(**details) def ssh_proxy_args case config.ssh.proxy when Net::SSH::Proxy::Jump - "-J #{config.ssh.proxy.jump_proxies}" + " -J #{config.ssh.proxy.jump_proxies}" when Net::SSH::Proxy::Command - "-o ProxyCommand='#{config.ssh.proxy.command_line_template}'" + " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'" end end end From 71dbeb676a8a437d49306a2ab670ed58d1535521 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 9 Oct 2024 20:49:44 -0400 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Sijawusz Pur Rahnama --- .github/workflows/ci.yml | 2 +- lib/kamal/commands/base.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 187cb4753..839bc4e65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,4 +54,4 @@ jobs: - name: Run tests run: bin/test env: - RUBYOPT: ${{ matrix.ruby-version == '3.4.0-preview2' && '--enable=frozen-string-literal' || '' }} + RUBYOPT: ${{ startsWith(matrix.ruby-version, '3.4.') && '--enable=frozen-string-literal' || '' }} diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index 0cb72632f..c0eac91cc 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -11,7 +11,7 @@ def initialize(config) end def run_over_ssh(*command, host:) - "ssh#{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'".squish + "ssh#{ssh_proxy_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'" end def container_id_for(container_name:, only_running: false)