Building directly from a checkout will pull in uncommitted files to or more sneakily files that are git ignored, but not docker ignored. To avoid this, we'll add an option to build from a git archive of HEAD instead. Docker doesn't provide a way to build directly from a git repo, so instead we create a tarball of the current HEAD with git archive and pipe it into the build command. When building from a git archive, we'll still display the warning about uncommitted changes, but we won't add the `_uncommitted_...` suffix to the container name as they won't be included in the build. Perhaps this should be the default, but we'll leave that decision for now.
60 lines
1.2 KiB
Ruby
60 lines
1.2 KiB
Ruby
class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Native
|
|
def create
|
|
chain \
|
|
create_context,
|
|
create_buildx
|
|
end
|
|
|
|
def remove
|
|
chain \
|
|
remove_context,
|
|
remove_buildx
|
|
end
|
|
|
|
def info
|
|
chain \
|
|
docker(:context, :ls),
|
|
docker(:buildx, :ls)
|
|
end
|
|
|
|
|
|
private
|
|
def builder_name
|
|
"kamal-#{config.service}-native-remote"
|
|
end
|
|
|
|
def builder_name_with_arch
|
|
"#{builder_name}-#{remote_arch}"
|
|
end
|
|
|
|
def platform
|
|
"linux/#{remote_arch}"
|
|
end
|
|
|
|
def create_context
|
|
docker :context, :create,
|
|
builder_name_with_arch, "--description", "'#{builder_name} #{remote_arch} native host'", "--docker", "'host=#{remote_host}'"
|
|
end
|
|
|
|
def remove_context
|
|
docker :context, :rm, builder_name_with_arch
|
|
end
|
|
|
|
def create_buildx
|
|
docker :buildx, :create, "--name", builder_name, builder_name_with_arch, "--platform", platform
|
|
end
|
|
|
|
def remove_buildx
|
|
docker :buildx, :rm, builder_name
|
|
end
|
|
|
|
def build_and_push
|
|
docker :buildx, :build,
|
|
"--push",
|
|
"--platform", platform,
|
|
"--builder", builder_name,
|
|
*build_options,
|
|
build_context
|
|
end
|
|
end
|