diff --git a/lib/kamal/commands/builder/pack.rb b/lib/kamal/commands/builder/pack.rb index cdd0e1a7..df9e6d19 100644 --- a/lib/kamal/commands/builder/pack.rb +++ b/lib/kamal/commands/builder/pack.rb @@ -9,6 +9,7 @@ class Kamal::Commands::Builder::Pack < Kamal::Commands::Builder::Base "-t", config.absolute_image, "-t", config.latest_image, "--env", "BP_IMAGE_LABELS=service=#{config.service}", + *argumentize("--env", args), *argumentize("--env", secrets, sensitive: true), "--path", build_context), docker(:push, config.absolute_image), diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index 7102c672..96e3e75e 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -69,6 +69,24 @@ class CommandsBuilderTest < ActiveSupport::TestCase builder.push.join(" ") end + test "pack build args passed as env" do + builder = new_builder_command(image: "dhh/app", builder: { "args" => { "a" => 1, "b" => 2 }, "arch" => "amd64", "pack" => { "builder" => "heroku/builder:24", "buildpacks" => [ "heroku/ruby", "heroku/procfile" ] } }) + + assert_equal \ + "pack build dhh/app --platform linux/amd64 --builder heroku/builder:24 --buildpack heroku/ruby --buildpack heroku/procfile --buildpack paketo-buildpacks/image-labels -t dhh/app:123 -t dhh/app:latest --env BP_IMAGE_LABELS=service=app --env a=\"1\" --env b=\"2\" --path . && docker push dhh/app:123 && docker push dhh/app:latest", + builder.push.join(" ") + end + + test "pack build secrets as env" do + with_test_secrets("secrets" => "token_a=foo\ntoken_b=bar") do + builder = new_builder_command(image: "dhh/app", builder: { "secrets" => [ "token_a", "token_b" ], "arch" => "amd64", "pack" => { "builder" => "heroku/builder:24", "buildpacks" => [ "heroku/ruby", "heroku/procfile" ] } }) + + assert_equal \ + "pack build dhh/app --platform linux/amd64 --builder heroku/builder:24 --buildpack heroku/ruby --buildpack heroku/procfile --buildpack paketo-buildpacks/image-labels -t dhh/app:123 -t dhh/app:latest --env BP_IMAGE_LABELS=service=app --env token_a=\"foo\" --env token_b=\"bar\" --path . && docker push dhh/app:123 && docker push dhh/app:latest", + builder.push.join(" ") + end + end + test "build args" do builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } }) assert_equal \