Adds support for Docker Build Cloud
This commit is contained in:
@@ -2,7 +2,7 @@ require "active_support/core_ext/string/filters"
|
|||||||
|
|
||||||
class Kamal::Commands::Builder < Kamal::Commands::Base
|
class Kamal::Commands::Builder < Kamal::Commands::Base
|
||||||
delegate :create, :remove, :push, :clean, :pull, :info, :inspect_builder, :validate_image, :first_mirror, to: :target
|
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
|
include Clone
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
|
|||||||
else
|
else
|
||||||
remote
|
remote
|
||||||
end
|
end
|
||||||
|
elsif cloud?
|
||||||
|
cloud
|
||||||
else
|
else
|
||||||
local
|
local
|
||||||
end
|
end
|
||||||
@@ -34,6 +36,10 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
|
|||||||
@hybrid ||= Kamal::Commands::Builder::Hybrid.new(config)
|
@hybrid ||= Kamal::Commands::Builder::Hybrid.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cloud
|
||||||
|
@cloud ||= Kamal::Commands::Builder::Cloud.new(config)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def ensure_local_dependencies_installed
|
def ensure_local_dependencies_installed
|
||||||
if name.native?
|
if name.native?
|
||||||
|
|||||||
22
lib/kamal/commands/builder/cloud.rb
Normal file
22
lib/kamal/commands/builder/cloud.rb
Normal 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
|
||||||
@@ -53,6 +53,10 @@ class Kamal::Configuration::Builder
|
|||||||
!local_disabled? && (arches.empty? || local_arches.any?)
|
!local_disabled? && (arches.empty? || local_arches.any?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cloud?
|
||||||
|
driver.start_with? "cloud"
|
||||||
|
end
|
||||||
|
|
||||||
def cached?
|
def cached?
|
||||||
!!builder_config["cache"]
|
!!builder_config["cache"]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ builder:
|
|||||||
#
|
#
|
||||||
# The build driver to use, defaults to `docker-container`:
|
# The build driver to use, defaults to `docker-container`:
|
||||||
driver: docker
|
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
|
# Provenance
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -235,6 +235,12 @@ class CliBuildTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "create cloud" do
|
||||||
|
run_command("create", fixture: :with_cloud_builder).tap do |output|
|
||||||
|
assert_match /docker buildx create --driver cloud example_org\/cloud_builder/, output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "create with error" do
|
test "create with error" do
|
||||||
stub_setup
|
stub_setup
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
SSHKit::Backend::Abstract.any_instance.stubs(:execute)
|
||||||
@@ -252,6 +258,12 @@ class CliBuildTest < CliTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "remove cloud" do
|
||||||
|
run_command("remove", fixture: :with_cloud_builder).tap do |output|
|
||||||
|
assert_match /docker buildx rm cloud-example_org-cloud_builder/, output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "details" do
|
test "details" do
|
||||||
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||||
.with(:docker, :context, :ls, "&&", :docker, :buildx, :ls)
|
.with(:docker, :context, :ls, "&&", :docker, :buildx, :ls)
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ class CommandsBuilderTest < ActiveSupport::TestCase
|
|||||||
builder.push.join(" ")
|
builder.push.join(" ")
|
||||||
end
|
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
|
test "build args" do
|
||||||
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
|
||||||
assert_equal \
|
assert_equal \
|
||||||
|
|||||||
40
test/fixtures/deploy_with_cloud_builder.yml
vendored
Normal file
40
test/fixtures/deploy_with_cloud_builder.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
service: app
|
||||||
|
image: dhh/app
|
||||||
|
servers:
|
||||||
|
web:
|
||||||
|
- "1.1.1.1"
|
||||||
|
- "1.1.1.2"
|
||||||
|
workers:
|
||||||
|
- "1.1.1.3"
|
||||||
|
- "1.1.1.4"
|
||||||
|
registry:
|
||||||
|
username: user
|
||||||
|
password: pw
|
||||||
|
|
||||||
|
accessories:
|
||||||
|
mysql:
|
||||||
|
image: mysql:5.7
|
||||||
|
host: 1.1.1.3
|
||||||
|
port: 3306
|
||||||
|
env:
|
||||||
|
clear:
|
||||||
|
MYSQL_ROOT_HOST: '%'
|
||||||
|
secret:
|
||||||
|
- MYSQL_ROOT_PASSWORD
|
||||||
|
files:
|
||||||
|
- test/fixtures/files/my.cnf:/etc/mysql/my.cnf
|
||||||
|
directories:
|
||||||
|
- data:/var/lib/mysql
|
||||||
|
redis:
|
||||||
|
image: redis:latest
|
||||||
|
roles:
|
||||||
|
- web
|
||||||
|
port: 6379
|
||||||
|
directories:
|
||||||
|
- data:/data
|
||||||
|
|
||||||
|
readiness_delay: 0
|
||||||
|
|
||||||
|
builder:
|
||||||
|
arch: <%= Kamal::Utils.docker_arch == "arm64" ? "amd64" : "arm64" %>
|
||||||
|
driver: cloud example_org/cloud_builder
|
||||||
Reference in New Issue
Block a user