Skip to content

Commit

Permalink
Merge pull request #620 from mlitwiniuk/allow_custom_ports_for_ssh
Browse files Browse the repository at this point in the history
Allow custom user and port for builder host
  • Loading branch information
djmb authored May 21, 2024
2 parents 9700e2b + 1e296c4 commit a83df9e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/kamal/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ def verify_local_dependencies
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
Expand Down
8 changes: 8 additions & 0 deletions test/cli/build_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ class CliBuildTest < CliTestCase
end
end

test "create remote with custom ports" do
run_command("create", fixture: :with_remote_builder_and_custom_ports).tap do |output|
assert_match "Running /usr/bin/env true on 1.1.1.5", output
assert_match "docker context create kamal-app-native-remote-amd64 --description 'kamal-app-native-remote amd64 native host' --docker 'host=ssh://app@1.1.1.5:2122'", output
assert_match "docker buildx create --name kamal-app-native-remote kamal-app-native-remote-amd64 --platform linux/amd64", output
end
end

test "create with error" do
stub_setup
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
Expand Down
45 changes: 45 additions & 0 deletions test/fixtures/deploy_with_remote_builder_and_custom_ports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
service: app
image: dhh/app
servers:
web:
- "1.1.1.1"
- "1.1.1.2"
workers:
- "1.1.1.3"
- "1.1.1.4"
registry:
username: user
password: pw

accessories:
mysql:
image: mysql:5.7
host: 1.1.1.3
port: 3306
env:
clear:
MYSQL_ROOT_HOST: '%'
secret:
- MYSQL_ROOT_PASSWORD
files:
- test/fixtures/files/my.cnf:/etc/mysql/my.cnf
directories:
- data:/var/lib/mysql
redis:
image: redis:latest
roles:
- web
port: 6379
directories:
- data:/data

readiness_delay: 0

ssh:
user: root
port: 22

builder:
remote:
arch: amd64
host: ssh://app@1.1.1.5:2122

0 comments on commit a83df9e

Please sign in to comment.