Catch up with main
This commit is contained in:
@@ -4,28 +4,12 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@deploy = {
|
||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
|
||||
servers: [ "1.1.1.1" ]
|
||||
builder: { "arch" => "amd64" }, servers: [ "1.1.1.1" ]
|
||||
}
|
||||
|
||||
@deploy_with_builder_option = {
|
||||
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
|
||||
servers: [ "1.1.1.1" ],
|
||||
builder: {}
|
||||
}
|
||||
end
|
||||
|
||||
test "multiarch?" do
|
||||
assert_equal true, config.builder.multiarch?
|
||||
end
|
||||
|
||||
test "setting multiarch to false" do
|
||||
@deploy_with_builder_option[:builder] = { "multiarch" => false }
|
||||
|
||||
assert_equal false, config_with_builder_option.builder.multiarch?
|
||||
end
|
||||
|
||||
test "local?" do
|
||||
assert_equal false, config.builder.local?
|
||||
assert_equal true, config.builder.local?
|
||||
end
|
||||
|
||||
test "remote?" do
|
||||
@@ -37,41 +21,33 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "pack? with pack builder" do
|
||||
@deploy[:builder] = { "pack" => { "builder" => "heroku/builder:24" } }
|
||||
@deploy[:builder] = { "arch" => "arm64", "pack" => { "builder" => "heroku/builder:24" } }
|
||||
|
||||
assert config.builder.pack?
|
||||
end
|
||||
|
||||
test "pack details" do
|
||||
@deploy[:builder] = { "pack" => { "arch" => "amd64", "builder" => "heroku/builder:24", "buildpacks" => [ "heroku/ruby", "heroku/procfile" ] } }
|
||||
@deploy[:builder] = { "arch" => "amd64", "pack" => { "builder" => "heroku/builder:24", "buildpacks" => [ "heroku/ruby", "heroku/procfile" ] } }
|
||||
|
||||
assert_equal "amd64", config.builder.pack_arch
|
||||
assert_equal "heroku/builder:24", config.builder.pack_builder
|
||||
assert_equal [ "heroku/ruby", "heroku/procfile" ], config.builder.pack_buildpacks
|
||||
end
|
||||
|
||||
test "remote_arch" do
|
||||
assert_nil config.builder.remote_arch
|
||||
end
|
||||
|
||||
test "remote_host" do
|
||||
assert_nil config.builder.remote_host
|
||||
test "remote" do
|
||||
assert_nil config.builder.remote
|
||||
end
|
||||
|
||||
test "setting both local and remote configs" do
|
||||
@deploy_with_builder_option[:builder] = {
|
||||
"local" => { "arch" => "arm64", "host" => "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock" },
|
||||
"remote" => { "arch" => "amd64", "host" => "ssh://root@192.168.0.1" }
|
||||
@deploy[:builder] = {
|
||||
"arch" => [ "amd64", "arm64" ],
|
||||
"remote" => "ssh://root@192.168.0.1"
|
||||
}
|
||||
|
||||
assert_equal true, config_with_builder_option.builder.local?
|
||||
assert_equal true, config_with_builder_option.builder.remote?
|
||||
assert_equal true, config.builder.local?
|
||||
assert_equal true, config.builder.remote?
|
||||
|
||||
assert_equal "amd64", config_with_builder_option.builder.remote_arch
|
||||
assert_equal "ssh://root@192.168.0.1", config_with_builder_option.builder.remote_host
|
||||
|
||||
assert_equal "arm64", config_with_builder_option.builder.local_arch
|
||||
assert_equal "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock", config_with_builder_option.builder.local_host
|
||||
assert_equal [ "amd64", "arm64" ], config.builder.arches
|
||||
assert_equal "ssh://root@192.168.0.1", config.builder.remote
|
||||
end
|
||||
|
||||
test "cached?" do
|
||||
@@ -79,10 +55,10 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "invalid cache type specified" do
|
||||
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "invalid" } }
|
||||
@deploy[:builder]["cache"] = { "type" => "invalid" }
|
||||
|
||||
assert_raises(Kamal::ConfigurationError) do
|
||||
config_with_builder_option.builder
|
||||
config.builder
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,32 +71,32 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting gha cache" do
|
||||
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "gha", "options" => "mode=max" } }
|
||||
@deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "gha", "options" => "mode=max" } }
|
||||
|
||||
assert_equal "type=gha", config_with_builder_option.builder.cache_from
|
||||
assert_equal "type=gha,mode=max", config_with_builder_option.builder.cache_to
|
||||
assert_equal "type=gha", config.builder.cache_from
|
||||
assert_equal "type=gha,mode=max", config.builder.cache_to
|
||||
end
|
||||
|
||||
test "setting registry cache" do
|
||||
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
|
||||
@deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
|
||||
|
||||
assert_equal "type=registry,ref=dhh/app-build-cache", config_with_builder_option.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", config_with_builder_option.builder.cache_to
|
||||
assert_equal "type=registry,ref=dhh/app-build-cache", config.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", config.builder.cache_to
|
||||
end
|
||||
|
||||
test "setting registry cache when using a custom registry" do
|
||||
@deploy_with_builder_option[:registry]["server"] = "registry.example.com"
|
||||
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
|
||||
@deploy[:registry]["server"] = "registry.example.com"
|
||||
@deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
|
||||
|
||||
assert_equal "type=registry,ref=registry.example.com/dhh/app-build-cache", config_with_builder_option.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=registry.example.com/dhh/app-build-cache", config_with_builder_option.builder.cache_to
|
||||
assert_equal "type=registry,ref=registry.example.com/dhh/app-build-cache", config.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=registry.example.com/dhh/app-build-cache", config.builder.cache_to
|
||||
end
|
||||
|
||||
test "setting registry cache with image" do
|
||||
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "image" => "kamal", "options" => "mode=max" } }
|
||||
@deploy[:builder] = { "arch" => "amd64", "cache" => { "type" => "registry", "image" => "kamal", "options" => "mode=max" } }
|
||||
|
||||
assert_equal "type=registry,ref=kamal", config_with_builder_option.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,ref=kamal", config_with_builder_option.builder.cache_to
|
||||
assert_equal "type=registry,ref=kamal", config.builder.cache_from
|
||||
assert_equal "type=registry,mode=max,ref=kamal", config.builder.cache_to
|
||||
end
|
||||
|
||||
test "args" do
|
||||
@@ -128,9 +104,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting args" do
|
||||
@deploy_with_builder_option[:builder] = { "args" => { "key" => "value" } }
|
||||
@deploy[:builder]["args"] = { "key" => "value" }
|
||||
|
||||
assert_equal({ "key" => "value" }, config_with_builder_option.builder.args)
|
||||
assert_equal({ "key" => "value" }, config.builder.args)
|
||||
end
|
||||
|
||||
test "secrets" do
|
||||
@@ -138,9 +114,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting secrets" do
|
||||
@deploy_with_builder_option[:builder] = { "secrets" => [ "GITHUB_TOKEN" ] }
|
||||
@deploy[:builder]["secrets"] = [ "GITHUB_TOKEN" ]
|
||||
|
||||
assert_equal [ "GITHUB_TOKEN" ], config_with_builder_option.builder.secrets
|
||||
assert_equal [ "GITHUB_TOKEN" ], config.builder.secrets
|
||||
end
|
||||
|
||||
test "dockerfile" do
|
||||
@@ -148,9 +124,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting dockerfile" do
|
||||
@deploy_with_builder_option[:builder] = { "dockerfile" => "Dockerfile.dev" }
|
||||
@deploy[:builder]["dockerfile"] = "Dockerfile.dev"
|
||||
|
||||
assert_equal "Dockerfile.dev", config_with_builder_option.builder.dockerfile
|
||||
assert_equal "Dockerfile.dev", config.builder.dockerfile
|
||||
end
|
||||
|
||||
test "context" do
|
||||
@@ -158,9 +134,9 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting context" do
|
||||
@deploy_with_builder_option[:builder] = { "context" => ".." }
|
||||
@deploy[:builder]["context"] = ".."
|
||||
|
||||
assert_equal "..", config_with_builder_option.builder.context
|
||||
assert_equal "..", config.builder.context
|
||||
end
|
||||
|
||||
test "ssh" do
|
||||
@@ -168,17 +144,30 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "setting ssh params" do
|
||||
@deploy_with_builder_option[:builder] = { "ssh" => "default=$SSH_AUTH_SOCK" }
|
||||
@deploy[:builder]["ssh"] = "default=$SSH_AUTH_SOCK"
|
||||
|
||||
assert_equal "default=$SSH_AUTH_SOCK", config_with_builder_option.builder.ssh
|
||||
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)
|
||||
end
|
||||
|
||||
def config_with_builder_option
|
||||
Kamal::Configuration.new(@deploy_with_builder_option)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user