Allow the driver to be set
This commit is contained in:
committed by
Donal McBreen
parent
bd1726f305
commit
cffb6c3d7e
@@ -6,7 +6,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
delegate :argumentize, to: Kamal::Utils
|
||||
delegate \
|
||||
:args, :secrets, :dockerfile, :target, :local_arch, :remote_arch, :remote_host,
|
||||
:cache_from, :cache_to, :multiarch?, :ssh,
|
||||
:cache_from, :cache_to, :multiarch?, :ssh, :driver, :docker_driver?,
|
||||
to: :builder_config
|
||||
|
||||
def clean
|
||||
@@ -17,7 +17,7 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
docker :build,
|
||||
"--push",
|
||||
*platform_options,
|
||||
"--builder", builder_name,
|
||||
*([ "--builder", builder_name ] unless docker_driver?),
|
||||
*build_options,
|
||||
build_context
|
||||
end
|
||||
|
||||
@@ -8,11 +8,11 @@ class Kamal::Commands::Builder::Hybrid < Kamal::Commands::Builder::Remote
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-hybrid-#{local_arch}-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
"kamal-hybrid-#{driver}-#{local_arch}-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
end
|
||||
|
||||
def create_local_buildx
|
||||
docker :buildx, :create, "--name", builder_name, "--platform", "linux/#{local_arch}", "--driver=docker-container"
|
||||
docker :buildx, :create, "--name", builder_name, "--platform", "linux/#{local_arch}", "--driver=#{driver}"
|
||||
end
|
||||
|
||||
def append_remote_buildx
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
class Kamal::Commands::Builder::Local < Kamal::Commands::Builder::Base
|
||||
def create
|
||||
docker :buildx, :create, "--name", builder_name, "--driver=docker-container"
|
||||
docker :buildx, :create, "--name", builder_name, "--driver=#{driver}" unless docker_driver?
|
||||
end
|
||||
|
||||
def remove
|
||||
docker :buildx, :rm, builder_name
|
||||
docker :buildx, :rm, builder_name unless docker_driver?
|
||||
end
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-local"
|
||||
"kamal-local-#{driver}"
|
||||
end
|
||||
|
||||
def platform_options
|
||||
|
||||
@@ -28,7 +28,7 @@ class Kamal::Commands::Builder::Remote < Kamal::Commands::Builder::Base
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-remote-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
"kamal-remote-#{driver}-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
end
|
||||
|
||||
def create_remote_context
|
||||
|
||||
@@ -55,6 +55,10 @@ class Kamal::Configuration::Builder
|
||||
builder_config["context"] || "."
|
||||
end
|
||||
|
||||
def driver
|
||||
builder_config.fetch("driver", "docker-container")
|
||||
end
|
||||
|
||||
def local_arch
|
||||
builder_config["local"]["arch"] if local?
|
||||
end
|
||||
@@ -110,6 +114,10 @@ class Kamal::Configuration::Builder
|
||||
end
|
||||
end
|
||||
|
||||
def docker_driver?
|
||||
driver == "docker"
|
||||
end
|
||||
|
||||
private
|
||||
def valid?
|
||||
if multiarch?
|
||||
@@ -121,6 +129,10 @@ class Kamal::Configuration::Builder
|
||||
raise ArgumentError, "Invalid builder configuration: remote configuration, arch required" unless remote_arch
|
||||
raise ArgumentError, "Invalid builder configuration: remote configuration, arch required" unless remote_host
|
||||
end
|
||||
|
||||
if docker_driver?
|
||||
raise ArgumentError, "Invalid builder configuration: the docker driver does not support multiarch builds"
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Invalid builder configuration: multiarch must be enabled for local configuration" if local?
|
||||
raise ArgumentError, "Invalid builder configuration: multiarch must be enabled for remote configuration" if remote?
|
||||
@@ -128,6 +140,7 @@ class Kamal::Configuration::Builder
|
||||
|
||||
if @options["cache"] && @options["cache"]["type"]
|
||||
raise ArgumentError, "Invalid cache type: #{@options["cache"]["type"]}" unless [ "gha", "registry" ].include?(@options["cache"]["type"])
|
||||
raise ArgumentError, "The docker driver does not support caching" if docker_driver?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ builder:
|
||||
# Enables multiarch builds, defaults to `true`
|
||||
multiarch: false
|
||||
|
||||
# Driver
|
||||
#
|
||||
# The build driver to use, defaults to `docker-container`
|
||||
driver: docker
|
||||
|
||||
# Local configuration
|
||||
#
|
||||
# The build configuration for local builds, only used if multiarch is enabled (the default)
|
||||
|
||||
@@ -24,6 +24,7 @@ registry:
|
||||
password: root
|
||||
builder:
|
||||
multiarch: false
|
||||
driver: docker
|
||||
args:
|
||||
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
||||
healthcheck:
|
||||
|
||||
@@ -18,6 +18,7 @@ registry:
|
||||
password: root
|
||||
builder:
|
||||
multiarch: false
|
||||
driver: docker
|
||||
args:
|
||||
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
||||
healthcheck:
|
||||
|
||||
Reference in New Issue
Block a user