Move native remote to just remote

It's just a remote builder, that will build whichever platform is asked
for, so let's remove the "native" part.

We'll also remove the service name from the builder name, so multiple
services can share the same builder.
This commit is contained in:
Donal McBreen
2024-06-06 10:11:03 +01:00
parent 2a4a8ac859
commit 6cedec68e3
4 changed files with 17 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
when config.builder.local? && config.builder.remote? when config.builder.local? && config.builder.remote?
multiarch_remote multiarch_remote
when config.builder.remote? when config.builder.remote?
native_remote remote
else else
local local
end end
@@ -29,8 +29,8 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
@native ||= Kamal::Commands::Builder::Native.new(config) @native ||= Kamal::Commands::Builder::Native.new(config)
end end
def native_remote def remote
@native ||= Kamal::Commands::Builder::Native::Remote.new(config) @remote ||= Kamal::Commands::Builder::Remote.new(config)
end end
def local def local

View File

@@ -1,4 +1,4 @@
class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Native class Kamal::Commands::Builder::Remote < Kamal::Commands::Builder::Base
def create def create
chain \ chain \
create_context, create_context,
@@ -27,7 +27,7 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
end end
def context_hosts def context_hosts
context_host(builder_name_with_arch) context_host(builder_name)
end end
def config_context_hosts def config_context_hosts
@@ -37,11 +37,7 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
private private
def builder_name def builder_name
"kamal-#{config.service}-native-remote" "kamal-remote-#{remote_arch}"
end
def builder_name_with_arch
"#{builder_name}-#{remote_arch}"
end end
def platform def platform
@@ -49,16 +45,15 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
end end
def create_context def create_context
docker :context, :create, docker :context, :create, builder_name, "--description", "'#{builder_name} host'", "--docker", "'host=#{remote_host}'"
builder_name_with_arch, "--description", "'#{builder_name} #{remote_arch} native host'", "--docker", "'host=#{remote_host}'"
end end
def remove_context def remove_context
docker :context, :rm, builder_name_with_arch docker :context, :rm, builder_name
end end
def create_buildx def create_buildx
docker :buildx, :create, "--name", builder_name, builder_name_with_arch, "--platform", platform docker :buildx, :create, "--name", builder_name, builder_name, "--platform", platform
end end
def remove_buildx def remove_buildx

View File

@@ -213,16 +213,16 @@ class CliBuildTest < CliTestCase
test "create remote" do test "create remote" do
run_command("create", fixture: :with_remote_builder).tap do |output| run_command("create", fixture: :with_remote_builder).tap do |output|
assert_match "Running /usr/bin/env true on 1.1.1.5", output assert_match "Running /usr/bin/env true on 1.1.1.5", output
assert_match "docker context create kamal-app-native-remote-amd64 --description 'kamal-app-native-remote amd64 native host' --docker 'host=ssh://app@1.1.1.5'", output assert_match "docker context create kamal-remote-amd64 --description 'kamal-remote-amd64 host' --docker 'host=ssh://app@1.1.1.5'", output
assert_match "docker buildx create --name kamal-app-native-remote kamal-app-native-remote-amd64 --platform linux/amd64", output assert_match "docker buildx create --name kamal-remote-amd64 kamal-remote-amd64 --platform linux/amd64", output
end end
end end
test "create remote with custom ports" do test "create remote with custom ports" do
run_command("create", fixture: :with_remote_builder_and_custom_ports).tap do |output| run_command("create", fixture: :with_remote_builder_and_custom_ports).tap do |output|
assert_match "Running /usr/bin/env true on 1.1.1.5", output assert_match "Running /usr/bin/env true on 1.1.1.5", output
assert_match "docker context create kamal-app-native-remote-amd64 --description 'kamal-app-native-remote amd64 native host' --docker 'host=ssh://app@1.1.1.5:2122'", output assert_match "docker context create kamal-remote-amd64 --description 'kamal-remote-amd64 host' --docker 'host=ssh://app@1.1.1.5:2122'", output
assert_match "docker buildx create --name kamal-app-native-remote kamal-app-native-remote-amd64 --platform linux/amd64", output assert_match "docker buildx create --name kamal-remote-amd64 kamal-remote-amd64 --platform linux/amd64", output
end end
end end

View File

@@ -47,9 +47,9 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "target native remote when only remote is set" do test "target native remote when only remote is set" do
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } })
assert_equal "native/remote", builder.name assert_equal "remote", builder.name
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -154,7 +154,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "remote context build" do test "remote context build" do
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "context" => "./foo" }) builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "context" => "./foo" })
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo", "docker buildx build --push --platform linux/amd64 --builder kamal-remote-amd64 -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ./foo",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -178,7 +178,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "native remote context hosts" do test "native remote context hosts" do
command = new_builder_command(builder: { "remote" => { "arch" => "amd64", "host" => "ssh://host" } }) command = new_builder_command(builder: { "remote" => { "arch" => "amd64", "host" => "ssh://host" } })
assert_equal "docker context inspect kamal-app-native-remote-amd64 --format '{{.Endpoints.docker.Host}}'", command.context_hosts.join(" ") assert_equal "docker context inspect kamal-remote-amd64 --format '{{.Endpoints.docker.Host}}'", command.context_hosts.join(" ")
assert_equal [ "ssh://host" ], command.config_context_hosts assert_equal [ "ssh://host" ], command.config_context_hosts
end end