diff --git a/.github/actions/copacetic-action/pkg/registry/registry.go b/.github/actions/copacetic-action/pkg/registry/registry.go index a079ec9..9c4e2fa 100644 --- a/.github/actions/copacetic-action/pkg/registry/registry.go +++ b/.github/actions/copacetic-action/pkg/registry/registry.go @@ -109,12 +109,17 @@ func (r *ghcrRegistry) isNotFoundError(err error) bool { // ImageRef returns reference of patched image in the cache registry. func (r *ghcrRegistry) ImageRef(sourceImageRef, tag string) (string, error) { - ref, err := name.ParseReference(sourceImageRef, name.WithDefaultRegistry("")) + ref, err := name.ParseReference(sourceImageRef, name.WithDefaultRegistry("docker.io")) if err != nil { return "", err } - return fmt.Sprintf("%s/%s/%s", ghcrDomain, r.organization, ref.Context().Tag(tag)), nil + taggedRef := ref.Context().Tag(tag).String() + if strings.HasPrefix(taggedRef, "index.docker.io") { + taggedRef = strings.TrimPrefix(taggedRef, "index.") + } + + return fmt.Sprintf("%s/%s/%s", ghcrDomain, r.organization, taggedRef), nil } // OriginalImageRef returns name of imageRef from which was the given imageRef built. diff --git a/.github/actions/copacetic-action/pkg/registry/registry_test.go b/.github/actions/copacetic-action/pkg/registry/registry_test.go index 69b4419..f5041e3 100644 --- a/.github/actions/copacetic-action/pkg/registry/registry_test.go +++ b/.github/actions/copacetic-action/pkg/registry/registry_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRegistryOriginalImageRef(t *testing.T) { +func TestRegistry_OriginalImageRef(t *testing.T) { registry := NewGHCR("d2iq-labs") testCases := []struct { @@ -31,9 +31,16 @@ func TestRegistryOriginalImageRef(t *testing.T) { } } -func TestRegistryListTags(t *testing.T) { +func TestRegistry_ListTags(t *testing.T) { r := NewGHCR("d2iq-labs") tags, err := r.ListTags(context.Background(), "registry.k8s.io/sig-storage/local-volume-provisioner:v2.5.0") assert.ErrorIs(t, err, ErrImageNotFound) assert.Empty(t, tags) } + +func TestRegistry_ImageRef(t *testing.T) { + r := NewGHCR("d2iq-labs") + imageRef, err := r.ImageRef("docker.io/alpine/alpine", "v1-d2iq.0") + assert.NoError(t, err) + assert.Equal(t, "ghcr.io/d2iq-labs/docker.io/alpine/alpine:v1-d2iq.0", imageRef) +}