watchtower/pkg/registry/helpers/helpers.go
dependabot[bot] 1754dd185d
chore(deps): bump github.com/docker/distribution from 2.8.2+incompatible to 2.8.3+incompatible (#1780)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: nils måsén <nils@piksel.se>
2023-10-04 12:17:38 +02:00

28 lines
665 B
Go

package helpers
import (
"github.com/distribution/reference"
)
// domains for Docker Hub, the default registry
const (
DefaultRegistryDomain = "docker.io"
DefaultRegistryHost = "index.docker.io"
LegacyDefaultRegistryDomain = "index.docker.io"
)
// GetRegistryAddress parses an image name
// and returns the address of the specified registry
func GetRegistryAddress(imageRef string) (string, error) {
normalizedRef, err := reference.ParseNormalizedNamed(imageRef)
if err != nil {
return "", err
}
address := reference.Domain(normalizedRef)
if address == DefaultRegistryDomain {
address = DefaultRegistryHost
}
return address, nil
}