Allow disabling of local builds

To disable local builds set:
```
builder:
   local: false
   remote: ssh://docker@docker-builder
```
This commit is contained in:
Donal McBreen
2024-09-03 14:33:25 +01:00
parent 9b9e60ec7f
commit a2549b1f60
5 changed files with 40 additions and 2 deletions

View File

@@ -37,6 +37,14 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder.push.join(" ")
end
test "remote build if remote is set and local disabled" do
builder = new_builder_command(builder: { "arch" => [ "amd64", "arm64" ], "remote" => "ssh://app@127.0.0.1", "cache" => { "type" => "gha" }, "local" => false })
assert_equal "remote", builder.name
assert_equal \
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-remote-ssh---app-127-0-0-1 -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
builder.push.join(" ")
end
test "target remote when remote set and arch is non local" do
builder = new_builder_command(builder: { "arch" => [ "#{remote_arch}" ], "remote" => "ssh://app@host", "cache" => { "type" => "gha" } })
assert_equal "remote", builder.name

View File

@@ -132,6 +132,23 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
assert_equal "default=$SSH_AUTH_SOCK", config.builder.ssh
end
test "local disabled but no remote set" do
@deploy[:builder]["local"] = false
assert_raises(Kamal::ConfigurationError) do
config.builder
end
end
test "local disabled all arches are remote" do
@deploy[:builder]["local"] = false
@deploy[:builder]["remote"] = "ssh://root@192.168.0.1"
@deploy[:builder]["arch"] = [ "amd64", "arm64" ]
assert_equal [], config.builder.local_arches
assert_equal [ "amd64", "arm64" ], config.builder.remote_arches
end
private
def config
Kamal::Configuration.new(@deploy)