add --target option for builder configuration

This commit is contained in:
Jason Nochlin
2024-04-27 10:24:34 -06:00
parent f48f528043
commit 947be0877f
3 changed files with 17 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
class BuilderError < StandardError; end class BuilderError < StandardError; end
delegate :argumentize, to: Kamal::Utils delegate :argumentize, to: Kamal::Utils
delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, :git_archive?, to: :builder_config delegate :args, :secrets, :dockerfile, :target, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, :git_archive?, to: :builder_config
def clean def clean
docker :image, :rm, "--force", config.absolute_image docker :image, :rm, "--force", config.absolute_image
@@ -24,7 +24,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
end end
def build_options def build_options
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_ssh ] [ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh ]
end end
def build_context def build_context
@@ -73,6 +73,10 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
end end
end end
def build_target
argumentize "--target", target if target.present?
end
def build_ssh def build_ssh
argumentize "--ssh", ssh if ssh.present? argumentize "--ssh", ssh if ssh.present?
end end

View File

@@ -38,6 +38,10 @@ class Kamal::Configuration::Builder
def dockerfile def dockerfile
@options["dockerfile"] || "Dockerfile" @options["dockerfile"] || "Dockerfile"
end end
def target
@options["target"]
end
def context def context
@options["context"] || (git_archive? ? "-" : ".") @options["context"] || (git_archive? ? "-" : ".")

View File

@@ -83,6 +83,13 @@ class CommandsBuilderTest < ActiveSupport::TestCase
end end
end end
test "build target" do
builder = new_builder_command(builder: { "target" => "prod" })
assert_equal \
"-t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile --target prod",
builder.target.build_options.join(" ")
end
test "build context" do test "build context" do
builder = new_builder_command(builder: { "context" => ".." }) builder = new_builder_command(builder: { "context" => ".." })
assert_equal \ assert_equal \