lib/kamal/commands/builder/base.rb in kamal-1.9.2 vs lib/kamal/commands/builder/base.rb in kamal-2.0.0.alpha
- old
+ new
@@ -1,22 +1,43 @@
-
class Kamal::Commands::Builder::Base < Kamal::Commands::Base
class BuilderError < StandardError; end
ENDPOINT_DOCKER_HOST_INSPECT = "'{{.Endpoints.docker.Host}}'"
delegate :argumentize, to: Kamal::Utils
- delegate :args, :secrets, :dockerfile, :target, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, to: :builder_config
+ delegate \
+ :args, :secrets, :dockerfile, :target, :arches, :local_arches, :remote_arches, :remote,
+ :cache_from, :cache_to, :ssh, :driver, :docker_driver?,
+ to: :builder_config
def clean
docker :image, :rm, "--force", config.absolute_image
end
+ def push
+ docker :buildx, :build,
+ "--push",
+ *platform_options(arches),
+ *([ "--builder", builder_name ] unless docker_driver?),
+ *build_options,
+ build_context
+ end
+
def pull
docker :pull, config.absolute_image
end
+ def info
+ combine \
+ docker(:context, :ls),
+ docker(:buildx, :ls)
+ end
+
+ def buildx_inspect
+ docker :buildx, :inspect, builder_name unless docker_driver?
+ end
+
def build_options
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh ]
end
def build_context
@@ -30,18 +51,10 @@
[ :grep, "-x", config.service ],
"(echo \"Image #{config.absolute_image} is missing the 'service' label\" && exit 1)"
)
end
- def context_hosts
- :true
- end
-
- def config_context_hosts
- []
- end
-
def first_mirror
docker(:info, "--format '{{index .RegistryConfig.Mirrors 0}}'")
end
private
@@ -88,7 +101,11 @@
config.builder
end
def context_host(builder_name)
docker :context, :inspect, builder_name, "--format", ENDPOINT_DOCKER_HOST_INSPECT
+ end
+
+ def platform_options(arches)
+ argumentize "--platform", arches.map { |arch| "linux/#{arch}" }.join(",") if arches.any?
end
end