Skip to content

Commit

Permalink
Merge pull request #417 from manastyretskyi/main
Browse files Browse the repository at this point in the history
Fix builder registry cache when using default registry
  • Loading branch information
djmb authored Aug 17, 2023
2 parents e7bc74d + f68a334 commit e2c3709
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/mrsk/configuration/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,23 @@ def cache_image
@options["cache"]&.fetch("image", nil) || "#{@image}-build-cache"
end

def cache_image_ref
[ @server, cache_image ].compact.join("/")
end

def cache_from_config_for_gha
"type=gha"
end

def cache_from_config_for_registry
[ "type=registry", "ref=#{@server}/#{cache_image}" ].compact.join(",")
[ "type=registry", "ref=#{cache_image_ref}" ].compact.join(",")
end

def cache_to_config_for_gha
[ "type=gha", @options["cache"]&.fetch("options", nil)].compact.join(",")
end

def cache_to_config_for_registry
[ "type=registry", @options["cache"]&.fetch("options", nil), "ref=#{@server}/#{cache_image}" ].compact.join(",")
[ "type=registry", @options["cache"]&.fetch("options", nil), "ref=#{cache_image_ref}" ].compact.join(",")
end
end
16 changes: 12 additions & 4 deletions test/configuration/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,23 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
test "setting registry cache" do
@deploy_with_builder_option[:builder] = { "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_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
end

test "setting registry cache when using a custom registry" do
@config_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" } }

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
end

test "setting registry cache with image" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "image" => "mrsk", "options" => "mode=max" } }

assert_equal "type=registry,ref=/mrsk", @config_with_builder_option.builder.cache_from
assert_equal "type=registry,mode=max,ref=/mrsk", @config_with_builder_option.builder.cache_to
assert_equal "type=registry,ref=mrsk", @config_with_builder_option.builder.cache_from
assert_equal "type=registry,mode=max,ref=mrsk", @config_with_builder_option.builder.cache_to
end

test "args" do
Expand Down

0 comments on commit e2c3709

Please sign in to comment.