diff --git a/lib/kamal/commands/builder/base.rb b/lib/kamal/commands/builder/base.rb index 8d0d629b..8f68b334 100644 --- a/lib/kamal/commands/builder/base.rb +++ b/lib/kamal/commands/builder/base.rb @@ -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 diff --git a/lib/kamal/commands/builder/hybrid.rb b/lib/kamal/commands/builder/hybrid.rb index ac1d2e6c..f8d873dd 100644 --- a/lib/kamal/commands/builder/hybrid.rb +++ b/lib/kamal/commands/builder/hybrid.rb @@ -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 diff --git a/lib/kamal/commands/builder/local.rb b/lib/kamal/commands/builder/local.rb index 955143e0..64b933ae 100644 --- a/lib/kamal/commands/builder/local.rb +++ b/lib/kamal/commands/builder/local.rb @@ -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 diff --git a/lib/kamal/commands/builder/remote.rb b/lib/kamal/commands/builder/remote.rb index f59071fd..3196a6e9 100644 --- a/lib/kamal/commands/builder/remote.rb +++ b/lib/kamal/commands/builder/remote.rb @@ -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 diff --git a/lib/kamal/configuration/builder.rb b/lib/kamal/configuration/builder.rb index a6440dd1..6229a518 100644 --- a/lib/kamal/configuration/builder.rb +++ b/lib/kamal/configuration/builder.rb @@ -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 diff --git a/lib/kamal/configuration/docs/builder.yml b/lib/kamal/configuration/docs/builder.yml index 5dc200bc..9695a468 100644 --- a/lib/kamal/configuration/docs/builder.yml +++ b/lib/kamal/configuration/docs/builder.yml @@ -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) diff --git a/test/integration/docker/deployer/app/config/deploy.yml b/test/integration/docker/deployer/app/config/deploy.yml index 397a49ca..72d09d91 100644 --- a/test/integration/docker/deployer/app/config/deploy.yml +++ b/test/integration/docker/deployer/app/config/deploy.yml @@ -24,6 +24,7 @@ registry: password: root builder: multiarch: false + driver: docker args: COMMIT_SHA: <%= `git rev-parse HEAD` %> healthcheck: diff --git a/test/integration/docker/deployer/app_with_roles/config/deploy.yml b/test/integration/docker/deployer/app_with_roles/config/deploy.yml index 7133c023..b3ccefa7 100644 --- a/test/integration/docker/deployer/app_with_roles/config/deploy.yml +++ b/test/integration/docker/deployer/app_with_roles/config/deploy.yml @@ -18,6 +18,7 @@ registry: password: root builder: multiarch: false + driver: docker args: COMMIT_SHA: <%= `git rev-parse HEAD` %> healthcheck: