imagetools: set default repo ref on creation if nil

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/1441/head
CrazyMax 2 years ago
parent 3ed2783f34
commit 4788eb24ab
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -90,21 +90,24 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
} }
for i, s := range srcs { for i, s := range srcs {
if s.Ref == nil && s.Desc.MediaType == "" && s.Desc.Digest != "" { if s.Ref == nil {
if defaultRepo == nil { if defaultRepo == nil {
return errors.Errorf("multiple repositories specified, cannot infer repository for %q", args[i]) return errors.Errorf("multiple repositories specified, cannot infer repository for %q", args[i])
} }
n, err := reference.ParseNormalizedNamed(*defaultRepo) n, err := reference.ParseNormalizedNamed(*defaultRepo)
if err != nil { if err != nil {
return err return err
} }
r, err := reference.WithDigest(n, s.Desc.Digest) if s.Desc.MediaType == "" && s.Desc.Digest != "" {
if err != nil { r, err := reference.WithDigest(n, s.Desc.Digest)
return err if err != nil {
return err
}
srcs[i].Ref = r
sourceRefs = true
} else {
srcs[i].Ref = reference.TagNameOnly(n)
} }
srcs[i].Ref = r
sourceRefs = true
} }
} }

Loading…
Cancel
Save