Docker does not respect the .dockerignore file when building from a tar. Instead by default we'll make a local clone into a tmp directory and build from there. Subsequent builds will reset the clone to match the checkout. Compared to building directly in the repo, we'll have reproducible builds. Compared to using a git archive: 1. .dockerignore is respected 2. We'll have faster builds - docker can be smarter about caching the build context on subsequent builds from a directory To build from the repo directly, set the build context to "." in the config. If there are uncommitted changes, we'll warn about them either being included or ignored depending on whether we build from the clone.
38 lines
697 B
Ruby
38 lines
697 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
|
|
|
|
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
|