Skip to content

Commit

Permalink
fix: default registry name
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrabovcin committed Feb 19, 2024
1 parent 4e6dcd7 commit 6382181
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/actions/copacetic-action/pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions .github/actions/copacetic-action/pkg/registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

0 comments on commit 6382181

Please sign in to comment.