@@ -122,27 +122,26 @@ func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error
122122 }
123123
124124 opts := controllerapi.BuildOptions {
125- Allow : o .allow ,
126- Annotations : o .annotations ,
127- BuildArgs : buildArgs ,
128- CgroupParent : o .cgroupParent ,
129- ContextPath : o .contextPath ,
130- DockerfileName : o .dockerfileName ,
131- ExtraHosts : o .extraHosts ,
132- Labels : labels ,
133- NetworkMode : o .networkMode ,
134- NoCacheFilter : o .noCacheFilter ,
135- Platforms : o .platforms ,
136- ShmSize : int64 (o .shmSize ),
137- Tags : o .tags ,
138- Target : o .target ,
139- Ulimits : dockerUlimitToControllerUlimit (o .ulimits ),
140- Builder : o .builder ,
141- NoCache : o .noCache ,
142- Pull : o .pull ,
143- ExportPush : o .exportPush ,
144- ExportLoad : o .exportLoad ,
145- WithProvenanceResponse : len (o .metadataFile ) > 0 ,
125+ Allow : o .allow ,
126+ Annotations : o .annotations ,
127+ BuildArgs : buildArgs ,
128+ CgroupParent : o .cgroupParent ,
129+ ContextPath : o .contextPath ,
130+ DockerfileName : o .dockerfileName ,
131+ ExtraHosts : o .extraHosts ,
132+ Labels : labels ,
133+ NetworkMode : o .networkMode ,
134+ NoCacheFilter : o .noCacheFilter ,
135+ Platforms : o .platforms ,
136+ ShmSize : int64 (o .shmSize ),
137+ Tags : o .tags ,
138+ Target : o .target ,
139+ Ulimits : dockerUlimitToControllerUlimit (o .ulimits ),
140+ Builder : o .builder ,
141+ NoCache : o .noCache ,
142+ Pull : o .pull ,
143+ ExportPush : o .exportPush ,
144+ ExportLoad : o .exportLoad ,
146145 }
147146
148147 // TODO: extract env var parsing to a method easily usable by library consumers
@@ -207,6 +206,8 @@ func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error
207206 return nil , err
208207 }
209208
209+ opts .WithProvenanceResponse = opts .PrintFunc == nil && len (o .metadataFile ) > 0
210+
210211 return & opts , nil
211212}
212213
@@ -365,15 +366,14 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
365366 return errors .Wrap (err , "writing image ID file" )
366367 }
367368 }
368- if options .metadataFile != "" {
369- if err := writeMetadataFile (options .metadataFile , decodeExporterResponse (resp .ExporterResponse )); err != nil {
370- return err
371- }
372- }
373369 if opts .PrintFunc != nil {
374370 if err := printResult (opts .PrintFunc , resp .ExporterResponse ); err != nil {
375371 return err
376372 }
373+ } else if options .metadataFile != "" {
374+ if err := writeMetadataFile (options .metadataFile , decodeExporterResponse (resp .ExporterResponse )); err != nil {
375+ return err
376+ }
377377 }
378378 return nil
379379}
0 commit comments