2020-12-06 13:21:04 +01:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import (
|
2023-10-04 12:03:02 +02:00
|
|
|
"github.com/distribution/reference"
|
2020-12-06 13:21:04 +01:00
|
|
|
)
|
|
|
|
|
2023-04-12 17:15:12 +02:00
|
|
|
// domains for Docker Hub, the default registry
|
|
|
|
const (
|
|
|
|
DefaultRegistryDomain = "docker.io"
|
|
|
|
DefaultRegistryHost = "index.docker.io"
|
|
|
|
LegacyDefaultRegistryDomain = "index.docker.io"
|
|
|
|
)
|
2020-12-06 13:21:04 +01:00
|
|
|
|
2023-04-12 17:15:12 +02:00
|
|
|
// GetRegistryAddress parses an image name
|
|
|
|
// and returns the address of the specified registry
|
|
|
|
func GetRegistryAddress(imageRef string) (string, error) {
|
|
|
|
normalizedRef, err := reference.ParseNormalizedNamed(imageRef)
|
2020-12-06 13:21:04 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2023-04-12 17:15:12 +02:00
|
|
|
address := reference.Domain(normalizedRef)
|
2020-12-06 13:21:04 +01:00
|
|
|
|
2023-04-12 17:15:12 +02:00
|
|
|
if address == DefaultRegistryDomain {
|
|
|
|
address = DefaultRegistryHost
|
2020-12-06 13:21:04 +01:00
|
|
|
}
|
2023-04-12 17:15:12 +02:00
|
|
|
return address, nil
|
2020-12-06 13:21:04 +01:00
|
|
|
}
|