Parse registry urls from image names
This commit is contained in:
parent
016129b5ed
commit
a8d7407093
18
main.go
18
main.go
@ -17,8 +17,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// registryBaseURL is the base URL of the docker registry
|
||||
registryBaseURL = "https://registry.hub.docker.com"
|
||||
// defaultRegistryBaseURL is the base URL of the docker registry
|
||||
defaultRegistryBaseURL = "https://hub.docker.com"
|
||||
// maxPages is the max number of pages to fetch from docker registry results
|
||||
maxPages = 10
|
||||
|
||||
@ -31,6 +31,7 @@ var (
|
||||
// ImageTag is wraps an image and tag values for a container
|
||||
type ImageTag struct {
|
||||
ImageTag string
|
||||
Registry string
|
||||
Image string
|
||||
TagDesc string
|
||||
Version string
|
||||
@ -75,8 +76,14 @@ func ParseImageTag(imageTag string) (ImageTag, error) {
|
||||
|
||||
// Extract image name with repo
|
||||
image := results[1]
|
||||
if !strings.Contains(image, "/") {
|
||||
registry := ""
|
||||
switch strings.Count(image, "/") {
|
||||
case 0:
|
||||
image = "library/" + image
|
||||
case 2:
|
||||
parts := strings.Split(image, "/")
|
||||
registry = parts[0]
|
||||
image = strings.Join(parts[1:], "/")
|
||||
}
|
||||
|
||||
// Extract version number
|
||||
@ -95,6 +102,7 @@ func ParseImageTag(imageTag string) (ImageTag, error) {
|
||||
return ImageTag{
|
||||
ImageTag: imageTag,
|
||||
Image: image,
|
||||
Registry: registry,
|
||||
Version: version,
|
||||
VersionParts: versionParts,
|
||||
TagDesc: results[4],
|
||||
@ -132,6 +140,10 @@ func listTags(current ImageTag) ([]ImageTag, error) {
|
||||
}
|
||||
}
|
||||
|
||||
registryBaseURL := defaultRegistryBaseURL
|
||||
if current.Registry != "" {
|
||||
registryBaseURL = fmt.Sprintf("https://%s", current.Registry)
|
||||
}
|
||||
url := fmt.Sprintf("%s/v2/repositories/%s/tags", registryBaseURL, current.Image)
|
||||
pageCount := 0
|
||||
var response tagsResponse
|
||||
|
Loading…
Reference in New Issue
Block a user