Allow custom user and port for builder host

When ssh options are set, they overwrite username and password passed as ssh builder uri. Passing part of uri for ssh-kit is fine, as it then properly extracts username and password and forwards it as host.ssh_options (in which case it's no longer empty)
This commit is contained in:
Maciej Litwiniuk
2023-12-26 17:24:47 +01:00
parent 31669d4dce
commit 2f912367ac
4 changed files with 60 additions and 3 deletions

View File

@@ -114,8 +114,11 @@ class Kamal::Cli::Build < Kamal::Cli::Base
def connect_to_remote_host(remote_host)
remote_uri = URI.parse(remote_host)
if remote_uri.scheme == "ssh"
options = { user: remote_uri.user, port: remote_uri.port }.compact
on(remote_uri.host, options) do
host = SSHKit::Host.new(
hostname: remote_uri.host,
ssh_options: { user: remote_uri.user, port: remote_uri.port }.compact
)
on(host, options) do
execute "true"
end
end

View File

@@ -80,7 +80,8 @@ class SSHKit::Backend::Netssh
module LimitConcurrentStartsInstance
private
def with_ssh(&block)
host.ssh_options = self.class.config.ssh_options.merge(host.ssh_options || {})
host.ssh_options = (host.ssh_options || {}).merge({ port: host.port, user: host.user }.compact)
host.ssh_options = self.class.config.ssh_options.merge(host.ssh_options)
self.class.pool.with(
method(:start_with_concurrency_limit),
String(host.hostname),