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