Skip to content

Commit

Permalink
Adds support for Docker Build Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbjones committed Jan 14, 2025
1 parent 1547089 commit 821ba25
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/kamal/commands/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

Expand All @@ -17,6 +17,8 @@ def target
else
remote
end
elsif cloud?
cloud
else
local
end
Expand All @@ -34,6 +36,10 @@ def hybrid
@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?
Expand Down
8 changes: 8 additions & 0 deletions lib/kamal/commands/builder/cloud.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Kamal::Commands::Builder::Cloud < Kamal::Commands::Builder::Base
private
def builder_name
# Expected format: "cloud docker-org-name/builder-name"
docker_cloud_build_parts = driver.sub(/^cloud /, "").split("/")
"cloud-#{docker_cloud_build_parts[0]}-#{docker_cloud_build_parts[1]}"
end
end
6 changes: 5 additions & 1 deletion lib/kamal/configuration/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def local?
!local_disabled? && (arches.empty? || local_arches.any?)
end

def cloud?
driver.start_with? "cloud"
end

def cached?
!!builder_config["cache"]
end
Expand Down Expand Up @@ -137,7 +141,7 @@ def build_directory
end

def docker_driver?
driver == "docker"
driver == "docker" || driver == "cloud"
end

private
Expand Down
3 changes: 3 additions & 0 deletions lib/kamal/configuration/docs/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
8 changes: 8 additions & 0 deletions test/commands/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder.push.join(" ")
end

test "cloud builder" do
builder = new_builder_command(builder: { "arch" => [ "#{local_arch}" ], "driver" => "cloud docker-org-name/builder-name" })
assert_equal "cloud", builder.name
assert_equal \
"docker buildx build --push --platform linux/#{local_arch} --builder cloud-docker-org-name-builder-name -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile .",
builder.push.join(" ")
end

test "build args" do
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
assert_equal \
Expand Down

0 comments on commit 821ba25

Please sign in to comment.