Load the hosts from the contexts before trying to build. If there is no context, we'll create one. If there is one but the hosts don't match we'll re-create. Where we just have a local context, there won't be any hosts but we still inspect the builder to check that it exists.
42 lines
782 B
Ruby
42 lines
782 B
Ruby
class Kamal::Commands::Builder::Multiarch < Kamal::Commands::Builder::Base
|
|
def create
|
|
docker :buildx, :create, "--use", "--name", builder_name
|
|
end
|
|
|
|
def remove
|
|
docker :buildx, :rm, builder_name
|
|
end
|
|
|
|
def info
|
|
combine \
|
|
docker(:context, :ls),
|
|
docker(:buildx, :ls)
|
|
end
|
|
|
|
def push
|
|
docker :buildx, :build,
|
|
"--push",
|
|
"--platform", platform_names,
|
|
"--builder", builder_name,
|
|
*build_options,
|
|
build_context
|
|
end
|
|
|
|
def context_hosts
|
|
docker :buildx, :inspect, builder_name, "> /dev/null"
|
|
end
|
|
|
|
private
|
|
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
|