diff --git a/lib/kamal/commands/builder/base.rb b/lib/kamal/commands/builder/base.rb index 19d44935e..a3db7185d 100644 --- a/lib/kamal/commands/builder/base.rb +++ b/lib/kamal/commands/builder/base.rb @@ -3,7 +3,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base class BuilderError < StandardError; end delegate :argumentize, to: Kamal::Utils - delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, to: :builder_config + delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, to: :builder_config def clean docker :image, :rm, "--force", config.absolute_image @@ -14,7 +14,7 @@ def pull end def build_options - [ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile ] + [ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_ssh ] end def build_context @@ -54,6 +54,10 @@ def build_dockerfile end end + def build_ssh + argumentize "--ssh", ssh if ssh.present? + end + def builder_config config.builder end diff --git a/lib/kamal/configuration/builder.rb b/lib/kamal/configuration/builder.rb index c7d81922a..9daa31381 100644 --- a/lib/kamal/configuration/builder.rb +++ b/lib/kamal/configuration/builder.rb @@ -81,6 +81,10 @@ def cache_to end end + def ssh + @options["ssh"] + end + private def valid? if @options["cache"] && @options["cache"]["type"] diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index 1cc5939b1..a21ae4509 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -103,6 +103,14 @@ class CommandsBuilderTest < ActiveSupport::TestCase builder.push.join(" ") end + test "build with ssh agent socket" do + builder = new_builder_command(builder: { "ssh" => 'default=$SSH_AUTH_SOCK' }) + + assert_equal \ + "-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --ssh default=$SSH_AUTH_SOCK", + builder.target.build_options.join(" ") + end + private def new_builder_command(additional_config = {}) Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.merge(additional_config), version: "123")) diff --git a/test/configuration/builder_test.rb b/test/configuration/builder_test.rb index da30d9156..02c1d8db3 100644 --- a/test/configuration/builder_test.rb +++ b/test/configuration/builder_test.rb @@ -148,4 +148,14 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase assert_equal "..", @config_with_builder_option.builder.context end + + test "ssh" do + assert_empty @config.builder.ssh + end + + test "setting ssh params" do + @deploy_with_builder_option[:builder] = { "ssh" => 'default=$SSH_AUTH_SOCK' } + + assert_equal 'default=$SSH_AUTH_SOCK', @config_with_builder_option.builder.ssh + end end