@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/containerd/containerd/v2/core/remotes"
1212 "github.com/containerd/platforms"
13- "github.com/distribution/reference"
1413 "github.com/docker/buildx/builder"
1514 "github.com/docker/buildx/util/buildflags"
1615 "github.com/docker/buildx/util/cobrautil/completion"
@@ -60,7 +59,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
6059
6160 args = append (fileArgs , args ... )
6261
63- tags , err := parseRefs (in .tags )
62+ tags , err := parseLocations (in .tags )
6463 if err != nil {
6564 return err
6665 }
@@ -102,10 +101,16 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
102101 return errors .Errorf ("no repositories specified, please set a reference in tag or source" )
103102 }
104103
105- var defaultRepo * string
104+ var defaultRepo * imagetools. Location
106105 if len (repos ) == 1 {
107- for repo := range repos {
108- defaultRepo = & repo
106+ for _ , src := range srcs {
107+ if src .Ref != nil {
108+ defaultRepo = src .Ref
109+ break
110+ }
111+ }
112+ if defaultRepo == nil && len (tags ) > 0 {
113+ defaultRepo = tags [0 ]
109114 }
110115 }
111116
@@ -114,19 +119,19 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
114119 if defaultRepo == nil {
115120 return errors .Errorf ("multiple repositories specified, cannot infer repository for %q" , args [i ])
116121 }
117- n , err := reference .ParseNormalizedNamed (* defaultRepo )
118- if err != nil {
119- return err
120- }
121122 if s .Desc .MediaType == "" && s .Desc .Digest != "" {
122- r , err := reference .WithDigest (n , s .Desc .Digest )
123+ r , err := defaultRepo .WithDigest (s .Desc .Digest )
123124 if err != nil {
124125 return err
125126 }
126127 srcs [i ].Ref = r
127128 sourceRefs = true
128129 } else {
129- srcs [i ].Ref = reference .TagNameOnly (n )
130+ r , err := defaultRepo .TagNameOnly ()
131+ if err != nil {
132+ return err
133+ }
134+ srcs [i ].Ref = r
130135 }
131136 }
132137 }
@@ -209,7 +214,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
209214 eg , _ := errgroup .WithContext (ctx )
210215 pw := progress .WithPrefix (printer , "internal" , true )
211216
212- tagsByRepo := map [string ][]reference. Named {}
217+ tagsByRepo := map [string ][]* imagetools. Location {}
213218 for _ , t := range tags {
214219 repo := t .Name ()
215220 tagsByRepo [repo ] = append (tagsByRepo [repo ], t )
@@ -224,10 +229,14 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
224229 for _ , desc := range manifests {
225230 eg2 .Go (func () error {
226231 sub .Log (1 , fmt .Appendf (nil , "copying %s from %s to %s\n " , desc .Digest .String (), desc .Source .Ref .String (), repo ))
227- return r .Copy (ctx , & imagetools.Source {
232+ err := r .Copy (ctx , & imagetools.Source {
228233 Ref : desc .Source .Ref ,
229234 Desc : desc .Descriptor ,
230235 }, seed )
236+ if err != nil {
237+ return errors .Wrapf (err , "copy %s from %s to %s" , desc .Digest .String (), desc .Source .Ref .String (), seed .String ())
238+ }
239+ return nil
231240 })
232241 }
233242 if err := eg2 .Wait (); err != nil {
@@ -236,7 +245,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
236245 for _ , t := range repoTags {
237246 sub .Log (1 , fmt .Appendf (nil , "pushing %s to %s\n " , desc .Digest .String (), t .String ()))
238247 if err := r .Push (ctx , t , desc , dt ); err != nil {
239- return err
248+ return errors . Wrapf ( err , "publish %s to %s" , desc . Digest . String (), t . String ())
240249 }
241250 }
242251 return nil
@@ -302,10 +311,10 @@ func withMediaTypeKeyPrefix(ctx context.Context) context.Context {
302311 return ctx
303312}
304313
305- func parseRefs (in []string ) ([]reference. Named , error ) {
306- refs := make ([]reference. Named , len (in ))
314+ func parseLocations (in []string ) ([]* imagetools. Location , error ) {
315+ refs := make ([]* imagetools. Location , len (in ))
307316 for i , in := range in {
308- n , err := reference . ParseNormalizedNamed (in )
317+ n , err := imagetools . ParseLocation (in )
309318 if err != nil {
310319 return nil , err
311320 }
@@ -327,10 +336,10 @@ func parseSource(in string) (*imagetools.Source, error) {
327336 return nil , err
328337 }
329338
330- ref , err := reference . ParseNormalizedNamed (in )
339+ loc , err := imagetools . ParseLocation (in )
331340 if err == nil {
332341 return & imagetools.Source {
333- Ref : ref ,
342+ Ref : loc ,
334343 }, nil
335344 } else if ! strings .HasPrefix (in , "{" ) {
336345 return nil , err
0 commit comments