Rip out context_hosts checks
The remote host is now encoded in the builder name so we don't need to check it. We'll just do an inspect to confirm the builder exists.
This commit is contained in:
@@ -30,18 +30,9 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
||||
say "Building with uncommitted changes:\n #{uncommitted_changes}", :yellow
|
||||
end
|
||||
|
||||
# Get the command here to ensure the Dir.chdir doesn't interfere with it
|
||||
push = KAMAL.builder.push
|
||||
|
||||
run_locally do
|
||||
begin
|
||||
context_hosts = capture_with_info(*KAMAL.builder.context_hosts).split("\n")
|
||||
|
||||
if context_hosts != KAMAL.builder.config_context_hosts
|
||||
warn "Context hosts have changed, so re-creating builder, was: #{context_hosts.join(", ")}], now: #{KAMAL.builder.config_context_hosts.join(", ")}"
|
||||
cli.remove
|
||||
cli.create
|
||||
end
|
||||
execute *KAMAL.builder.buildx_inspect
|
||||
rescue SSHKit::Command::Failed => e
|
||||
if e.message =~ /(context not found|no builder|does not exist)/
|
||||
warn "Missing compatible builder, so creating a new one first"
|
||||
@@ -51,6 +42,9 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Get the command here to ensure the Dir.chdir doesn't interfere with it
|
||||
push = KAMAL.builder.push
|
||||
|
||||
KAMAL.with_verbosity(:debug) do
|
||||
Dir.chdir(KAMAL.config.builder.build_directory) { execute *push }
|
||||
end
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
require "active_support/core_ext/string/filters"
|
||||
|
||||
class Kamal::Commands::Builder < Kamal::Commands::Base
|
||||
delegate :create, :remove, :push, :clean, :pull, :info, :context_hosts, :config_context_hosts, :validate_image,
|
||||
:first_mirror, to: :target
|
||||
delegate :create, :remove, :push, :clean, :pull, :info, :buildx_inspect, :validate_image, :first_mirror, to: :target
|
||||
|
||||
include Clone
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
class BuilderError < StandardError; end
|
||||
|
||||
@@ -14,10 +13,29 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
docker :image, :rm, "--force", config.absolute_image
|
||||
end
|
||||
|
||||
def push
|
||||
docker :buildx, :build,
|
||||
"--push",
|
||||
*platform_options,
|
||||
"--builder", builder_name,
|
||||
*build_options,
|
||||
build_context
|
||||
end
|
||||
|
||||
def pull
|
||||
docker :pull, config.absolute_image
|
||||
end
|
||||
|
||||
def info
|
||||
combine \
|
||||
docker(:context, :ls),
|
||||
docker(:buildx, :ls)
|
||||
end
|
||||
|
||||
def buildx_inspect
|
||||
docker :buildx, :inspect, builder_name
|
||||
end
|
||||
|
||||
def build_options
|
||||
[ *build_tags, *build_cache, *build_labels, *build_args, *build_secrets, *build_dockerfile, *build_target, *build_ssh ]
|
||||
end
|
||||
@@ -35,14 +53,6 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
||||
)
|
||||
end
|
||||
|
||||
def context_hosts
|
||||
:true
|
||||
end
|
||||
|
||||
def config_context_hosts
|
||||
[]
|
||||
end
|
||||
|
||||
def first_mirror
|
||||
docker(:info, "--format '{{index .RegistryConfig.Mirrors 0}}'")
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Kamal::Commands::Builder::Hybrid < Kamal::Commands::Builder::Base
|
||||
class Kamal::Commands::Builder::Hybrid < Kamal::Commands::Builder::Remote
|
||||
def create
|
||||
combine \
|
||||
create_local_buildx,
|
||||
@@ -6,18 +6,9 @@ class Kamal::Commands::Builder::Hybrid < Kamal::Commands::Builder::Base
|
||||
append_remote_buildx
|
||||
end
|
||||
|
||||
def context_hosts
|
||||
chain \
|
||||
context_host(builder_name)
|
||||
end
|
||||
|
||||
def config_context_hosts
|
||||
[ remote_host ].compact
|
||||
end
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-hybrid-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}-#{local_arch}-#{remote_arch}"
|
||||
"kamal-hybrid-#{local_arch}-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
end
|
||||
|
||||
def create_local_buildx
|
||||
@@ -28,7 +19,7 @@ class Kamal::Commands::Builder::Hybrid < Kamal::Commands::Builder::Base
|
||||
docker :buildx, :create, "--append", "--name", builder_name, builder_name, "--platform", "linux/#{remote_arch}"
|
||||
end
|
||||
|
||||
def platform_options
|
||||
[ "--platform", "linux/#{local_arch},linux/#{remote_arch}" ]
|
||||
def platform
|
||||
"linux/#{local_arch},linux/#{remote_arch}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,25 +7,6 @@ class Kamal::Commands::Builder::Local < Kamal::Commands::Builder::Base
|
||||
docker :buildx, :rm, builder_name
|
||||
end
|
||||
|
||||
def info
|
||||
combine \
|
||||
docker(:context, :ls),
|
||||
docker(:buildx, :ls)
|
||||
end
|
||||
|
||||
def push
|
||||
docker :buildx, :build,
|
||||
"--push",
|
||||
*platform_options,
|
||||
"--builder", builder_name,
|
||||
*build_options,
|
||||
build_context
|
||||
end
|
||||
|
||||
def context_hosts
|
||||
docker :buildx, :inspect, builder_name, "> /dev/null"
|
||||
end
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-local"
|
||||
|
||||
@@ -26,18 +26,9 @@ class Kamal::Commands::Builder::Remote < Kamal::Commands::Builder::Base
|
||||
build_context
|
||||
end
|
||||
|
||||
def context_hosts
|
||||
context_host(builder_name)
|
||||
end
|
||||
|
||||
def config_context_hosts
|
||||
[ remote_host ]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def builder_name
|
||||
"kamal-remote-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}-#{remote_arch}"
|
||||
"kamal-remote-#{remote_arch}-#{remote_host.gsub(/[^a-z0-9_-]/, "-")}"
|
||||
end
|
||||
|
||||
def create_remote_context
|
||||
@@ -57,6 +48,10 @@ class Kamal::Commands::Builder::Remote < Kamal::Commands::Builder::Base
|
||||
end
|
||||
|
||||
def platform_options
|
||||
[ "--platform", "linux/#{remote_arch}" ]
|
||||
[ "--platform", platform ]
|
||||
end
|
||||
|
||||
def platform
|
||||
"linux/#{remote_arch}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user