Skip to content

Commit

Permalink
Use docker info to get arch
Browse files Browse the repository at this point in the history
  • Loading branch information
djmb committed Aug 28, 2024
1 parent 4e37ffd commit ce5b6cc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/kamal/configuration/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def arches

def local_arches
@local_arches ||= if remote
uname_m = `uname -m`.strip
local_arch = uname_m == "x86_64" ? "amd64" : uname_m
arches & [ local_arch ]
arches & [ Kamal::Utils.docker_arch ]
else
arches
end
Expand Down
12 changes: 12 additions & 0 deletions lib/kamal/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ def filter_specific_items(filters, items)
def stable_sort!(elements, &block)
elements.sort_by!.with_index { |element, index| [ block.call(element), index ] }
end

def docker_arch
arch = `docker info --format '{{.Architecture}}'`.strip
case arch
when /aarch64/
"arm64"
when /x86_64/
"amd64"
else
arch
end
end
end
4 changes: 2 additions & 2 deletions test/commands/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def build_directory
end

def local_arch
`uname -m`.strip == "x86_64" ? "amd64" : "arm64"
Kamal::Utils.docker_arch
end

def remote_arch
`uname -m`.strip == "x86_64" ? "arm64" : "amd64"
Kamal::Utils.docker_arch == "arm64" ? "amd64" : "arm64"
end
end
2 changes: 1 addition & 1 deletion test/fixtures/deploy_with_remote_builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ builder:
readiness_delay: 0

builder:
arch: <%= `uname -m`.strip == "x86_64" ? "arm64" : "amd64" %>
arch: <%= Kamal::Utils.docker_arch == "arm64" ? "amd64" : "arm64" %>
remote: ssh://app@1.1.1.5
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ ssh:
port: 22

builder:
arch: <%= `uname -m`.strip == "x86_64" ? "arm64" : "amd64" %>
arch: <%= Kamal::Utils.docker_arch == "arm64" ? "amd64" : "arm64" %>
remote: ssh://app@1.1.1.5:2122
2 changes: 1 addition & 1 deletion test/integration/docker/deployer/app/config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ registry:
password: root
builder:
driver: docker
arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %>
arch: <%= Kamal::Utils.docker_arch %>
args:
COMMIT_SHA: <%= `git rev-parse HEAD` %>
healthcheck:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ registry:
password: root
builder:
driver: docker
arch: <%= uname_m = `uname -m`; uname_m == "x86_64" ? "amd64" : uname_m %>
arch: <%= Kamal::Utils.docker_arch %>
args:
COMMIT_SHA: <%= `git rev-parse HEAD` %>
healthcheck:
Expand Down

0 comments on commit ce5b6cc

Please sign in to comment.