NormalizeName normalizes the provided name according to the conventions by Podman and Buildah. If tag and digest are missing, the "latest" tag will be used. If it's a short name, it will be prefixed with "localhost/". References to docker.io are normalized according to the Docker conventions. For
(name string)
| 53 | // References to docker.io are normalized according to the Docker conventions. |
| 54 | // For instance, "docker.io/foo" turns into "docker.io/library/foo". |
| 55 | func NormalizeName(name string) (reference.Named, error) { |
| 56 | // NOTE: this code is in symmetrie with containers/image/pkg/shortnames. |
| 57 | ref, err := reference.Parse(name) |
| 58 | if err != nil { |
| 59 | return nil, errors.Wrapf(err, "error normalizing name %q", name) |
| 60 | } |
| 61 | |
| 62 | named, ok := ref.(reference.Named) |
| 63 | if !ok { |
| 64 | return nil, errors.Errorf("%q is not a named reference", name) |
| 65 | } |
| 66 | |
| 67 | // Enforce "localhost" if needed. |
| 68 | registry := reference.Domain(named) |
| 69 | if !(strings.ContainsAny(registry, ".:") || registry == "localhost") { |
| 70 | name = toLocalImageName(ref.String()) |
| 71 | } |
| 72 | |
| 73 | // Another parse which also makes sure that docker.io references are |
| 74 | // correctly normalized (e.g., docker.io/alpine to |
| 75 | // docker.io/library/alpine). |
| 76 | named, err = reference.ParseNormalizedNamed(name) |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | |
| 81 | if _, hasTag := named.(reference.NamedTagged); hasTag { |
| 82 | // Strip off the tag of a tagged and digested reference. |
| 83 | named, err = normalizeTaggedDigestedNamed(named) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | return named, nil |
| 88 | } |
| 89 | if _, hasDigest := named.(reference.Digested); hasDigest { |
| 90 | return named, nil |
| 91 | } |
| 92 | |
| 93 | // Make sure to tag "latest". |
| 94 | return reference.TagNameOnly(named), nil |
| 95 | } |
| 96 | |
| 97 | // prefix the specified name with "localhost/". |
| 98 | func toLocalImageName(name string) string { |
searching dependent graphs…