@@ -328,6 +328,64 @@ func (f Frontend) Call(ctx context.Context, cln *client.Client, val Value, opts
328328 return NewValue (ctx , fs )
329329}
330330
331+ type Cache struct {}
332+
333+ func (c Cache ) Call (ctx context.Context , cln * client.Client , val Value , opts Option , input Value , ref string ) (Value , error ) {
334+ named , err := reference .ParseNormalizedNamed (ref )
335+ if err != nil {
336+ return nil , errdefs .WithInvalidImageRef (err , Arg (ctx , 1 ), ref )
337+ }
338+ ref = reference .TagNameOnly (named ).String ()
339+
340+ resolver := ImageResolver (ctx )
341+ if resolver != nil {
342+ platform := DefaultPlatform (ctx )
343+ resolveOpt := llb.ResolveImageConfigOpt {
344+ Platform : & platform ,
345+ }
346+
347+ dgst , config , err := resolver .ResolveImageConfig (ctx , ref , resolveOpt )
348+ if err == nil {
349+ var imageOpts []llb.ImageOption
350+ imageOpts = append (imageOpts , llb .Platform (platform ))
351+ for _ , opt := range SourceMap (ctx ) {
352+ imageOpts = append (imageOpts , opt )
353+ }
354+
355+ canonical , err := reference .WithDigest (named , dgst )
356+ if err != nil {
357+ return nil , errdefs .WithInvalidImageRef (err , Arg (ctx , 1 ), ref )
358+ }
359+
360+ cacheVal , err := NewValue (ctx , llb .Image (canonical .String ()))
361+ if err != nil {
362+ return nil , Arg (ctx , 1 ).WithError (err )
363+ }
364+
365+ fs , err := cacheVal .Filesystem ()
366+ if err != nil {
367+ return nil , Arg (ctx , 1 ).WithError (err )
368+ }
369+
370+ fs .State , err = fs .State .WithImageConfig (config )
371+ if err != nil {
372+ return nil , Arg (ctx , 1 ).WithError (err )
373+ }
374+
375+ fs .Image = & solver.ImageSpec {}
376+ err = json .Unmarshal (config , fs .Image )
377+ if err != nil {
378+ return nil , Arg (ctx , 1 ).WithError (err )
379+ }
380+ return NewValue (ctx , fs )
381+ } else { // not found
382+ return (DockerPush {}).Call (ctx , cln , input , opts , ref )
383+ }
384+ }
385+
386+ return NewValue (ctx , input )
387+ }
388+
331389type Env struct {}
332390
333391func (e Env ) Call (ctx context.Context , cln * client.Client , val Value , opts Option , key , value string ) (Value , error ) {
0 commit comments