@@ -367,20 +367,23 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
367367 return errors .Wrap (err , "writing image ID file" )
368368 }
369369 }
370+ if options .metadataFile != "" {
371+ dt := decodeExporterResponse (resp .ExporterResponse )
372+ if opts .PrintFunc == nil {
373+ if warnings := printer .Warnings (); len (warnings ) > 0 && confutil .MetadataWarningsEnabled () {
374+ dt ["buildx.build.warnings" ] = warnings
375+ }
376+ }
377+ if err := writeMetadataFile (options .metadataFile , dt ); err != nil {
378+ return err
379+ }
380+ }
370381 if opts .PrintFunc != nil {
371382 if exitcode , err := printResult (dockerCli .Out (), opts .PrintFunc , resp .ExporterResponse ); err != nil {
372383 return err
373384 } else if exitcode != 0 {
374385 os .Exit (exitcode )
375386 }
376- } else if options .metadataFile != "" {
377- dt := decodeExporterResponse (resp .ExporterResponse )
378- if warnings := printer .Warnings (); len (warnings ) > 0 && confutil .MetadataWarningsEnabled () {
379- dt ["buildx.build.warnings" ] = warnings
380- }
381- if err := writeMetadataFile (options .metadataFile , dt ); err != nil {
382- return err
383- }
384387 }
385388 return nil
386389}
@@ -733,10 +736,16 @@ func writeMetadataFile(filename string, dt interface{}) error {
733736func decodeExporterResponse (exporterResponse map [string ]string ) map [string ]interface {} {
734737 out := make (map [string ]interface {})
735738 for k , v := range exporterResponse {
736- dt , err := base64 .StdEncoding .DecodeString (v )
737- if err != nil {
738- out [k ] = v
739- continue
739+ var dt []byte
740+ var err error
741+ if k == "result.json" {
742+ dt = []byte (v )
743+ } else {
744+ dt , err = base64 .StdEncoding .DecodeString (v )
745+ if err != nil {
746+ out [k ] = v
747+ continue
748+ }
740749 }
741750 var raw map [string ]interface {}
742751 if err = json .Unmarshal (dt , & raw ); err != nil || len (raw ) == 0 {
0 commit comments