@@ -20,10 +20,11 @@ import (
2020)
2121
2222type exportOptions struct {
23- builder string
24- refs []string
25- output string
26- all bool
23+ builder string
24+ refs []string
25+ output string
26+ all bool
27+ finalize bool
2728}
2829
2930func runExport (ctx context.Context , dockerCli command.Cli , opts exportOptions ) error {
@@ -62,6 +63,26 @@ func runExport(ctx context.Context, dockerCli command.Cli, opts exportOptions) e
6263 return errors .Errorf ("no record found for ref %q" , ref )
6364 }
6465
66+ if opts .finalize {
67+ var finalized bool
68+ for _ , rec := range recs {
69+ if rec .Trace == nil {
70+ finalized = true
71+ if err := finalizeRecord (ctx , rec .Ref , nodes ); err != nil {
72+ return err
73+ }
74+ }
75+ }
76+ if finalized {
77+ recs , err = queryRecords (ctx , ref , nodes , & queryOptions {
78+ CompletedOnly : true ,
79+ })
80+ if err != nil {
81+ return err
82+ }
83+ }
84+ }
85+
6586 if ref == "" {
6687 slices .SortFunc (recs , func (a , b historyRecord ) int {
6788 return b .CreatedAt .AsTime ().Compare (a .CreatedAt .AsTime ())
@@ -154,7 +175,8 @@ func exportCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
154175
155176 flags := cmd .Flags ()
156177 flags .StringVarP (& options .output , "output" , "o" , "" , "Output file path" )
157- flags .BoolVar (& options .all , "all" , false , "Export all records for the builder" )
178+ flags .BoolVar (& options .all , "all" , false , "Export all build records for the builder" )
179+ flags .BoolVar (& options .finalize , "finalize" , false , "Ensure build records are finalized before exporting" )
158180
159181 return cmd
160182}
0 commit comments