From 5a09aa12ba97f92fff56b871690a15e10f9bec6c Mon Sep 17 00:00:00 2001 From: dhh Date: Wed, 10 Jan 2024 13:00:48 -0800 Subject: [PATCH] Allow local builds using a different arch than native --- lib/kamal/commands/builder/multiarch.rb | 10 +++++++++- test/commands/builder_test.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/kamal/commands/builder/multiarch.rb b/lib/kamal/commands/builder/multiarch.rb index 458c4ac6..2f9e4d19 100644 --- a/lib/kamal/commands/builder/multiarch.rb +++ b/lib/kamal/commands/builder/multiarch.rb @@ -10,7 +10,7 @@ def remove def push docker :buildx, :build, "--push", - "--platform", "linux/amd64,linux/arm64", + "--platform", platform_names, "--builder", builder_name, *build_options, build_context @@ -26,4 +26,12 @@ def info def builder_name "kamal-#{config.service}-multiarch" end + + def platform_names + if local_arch + "linux/#{local_arch}" + else + "linux/amd64,linux/arm64" + end + end end diff --git a/test/commands/builder_test.rb b/test/commands/builder_test.rb index c0256113..22ed8575 100644 --- a/test/commands/builder_test.rb +++ b/test/commands/builder_test.rb @@ -37,6 +37,14 @@ class CommandsBuilderTest < ActiveSupport::TestCase builder.push.join(" ") end + test "target multiarch local when arch is set" do + builder = new_builder_command(builder: { "local" => { "arch" => "amd64" } }) + assert_equal "multiarch", builder.name + assert_equal \ + "docker buildx build --push --platform linux/amd64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile .", + builder.push.join(" ") + end + test "target native remote when only remote is set" do builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } }) assert_equal "native/remote", builder.name