Adds support for Docker Build Cloud

This commit is contained in:
Matthew Jones
2025-01-14 10:17:56 -07:00
parent 1547089da0
commit b420b2613d
7 changed files with 96 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ require "active_support/core_ext/string/filters"
class Kamal::Commands::Builder < Kamal::Commands::Base
delegate :create, :remove, :push, :clean, :pull, :info, :inspect_builder, :validate_image, :first_mirror, to: :target
delegate :local?, :remote?, to: "config.builder"
delegate :local?, :remote?, :cloud?, to: "config.builder"
include Clone
@@ -17,6 +17,8 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
else
remote
end
elsif cloud?
cloud
else
local
end
@@ -34,6 +36,10 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
@hybrid ||= Kamal::Commands::Builder::Hybrid.new(config)
end
def cloud
@cloud ||= Kamal::Commands::Builder::Cloud.new(config)
end
def ensure_local_dependencies_installed
if name.native?

View File

@@ -0,0 +1,22 @@
class Kamal::Commands::Builder::Cloud < Kamal::Commands::Builder::Base
# Expects `driver` to be of format "cloud docker-org-name/builder-name"
def create
docker :buildx, :create, "--driver", driver
end
def remove
docker :buildx, :rm, builder_name
end
private
def builder_name
driver.gsub(/[ \/]/, "-")
end
def inspect_buildx
pipe \
docker(:buildx, :inspect, builder_name),
grep("-q", "Endpoint:.*cloud://.*")
end
end

View File

@@ -53,6 +53,10 @@ class Kamal::Configuration::Builder
!local_disabled? && (arches.empty? || local_arches.any?)
end
def cloud?
driver.start_with? "cloud"
end
def cached?
!!builder_config["cache"]
end

View File

@@ -102,6 +102,9 @@ builder:
#
# The build driver to use, defaults to `docker-container`:
driver: docker
#
# If you want to use Docker Build Cloud (https://www.docker.com/products/build-cloud/), you can set the driver to:
driver: cloud org-name/builder-name
# Provenance
#