Skip to content

Commit

Permalink
Merge pull request #640 from basecamp/local-different-arch
Browse files Browse the repository at this point in the history
Allow local builds using a different arch than native
  • Loading branch information
dhh authored Jan 10, 2024
2 parents aca7796 + 5a09aa1 commit aea5548
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/kamal/commands/builder/multiarch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 8 additions & 0 deletions test/commands/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aea5548

Please sign in to comment.