Skip to content

Commit

Permalink
feat(docker): Add support for docker.io prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 9, 2024
1 parent 8d63daf commit 8c1856f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions internal/docker/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Registry interface {
Name() string
Names() []string

ApiUrl() string
TokenUrl(repo string) string
Expand Down Expand Up @@ -41,8 +41,10 @@ var ErrInvalidRegistry = errors.New("no registry for repo")

func FindRegistry(repo string) (Registry, error) {
for _, registry := range registries {
if strings.HasPrefix(repo, registry.Name()) {
return registry, nil
for _, name := range registry.Names() {
if strings.HasPrefix(repo, name) {
return registry, nil
}
}
}
return nil, fmt.Errorf("%w: %s", ErrInvalidRegistry, repo)
Expand Down
5 changes: 3 additions & 2 deletions internal/docker/registry_dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func init() {

type DockerHub struct{}

func (d DockerHub) Name() string {
return ""
func (d DockerHub) Names() []string {
return []string{"", "docker.io"}
}

func (d DockerHub) ApiUrl() string {
Expand All @@ -46,6 +46,7 @@ func (d DockerHub) Transport(_ context.Context, repo string) (http.RoundTripper,
}

func (d DockerHub) NormalizeRepo(repo string) string {
repo = strings.TrimPrefix(repo, "docker.io/")
if !strings.Contains(repo, "/") {
return "library/" + repo
}
Expand Down
4 changes: 2 additions & 2 deletions internal/docker/registry_ghcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ type Ghcr struct {
refreshedAt time.Time
}

func (g Ghcr) Name() string {
return "ghcr.io"
func (g Ghcr) Names() []string {
return []string{"ghcr.io"}
}

func (g Ghcr) ApiUrl() string {
Expand Down

0 comments on commit 8c1856f

Please sign in to comment.