Skip to content

Commit

Permalink
Merge pull request #3049 from tonistiigi/history-inspect-index
Browse files Browse the repository at this point in the history
history: allow index based inspect of builds
  • Loading branch information
tonistiigi authored Mar 6, 2025
2 parents aefa49c + 058c098 commit e19c729
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions commands/history/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
}
}

var offset *int
if strings.HasPrefix(opts.ref, "^") {
off, err := strconv.Atoi(opts.ref[1:])
if err != nil {
return errors.Wrapf(err, "invalid offset %q", opts.ref)
}
offset = &off
opts.ref = ""
}

recs, err := queryRecords(ctx, opts.ref, nodes)
if err != nil {
return err
Expand All @@ -185,14 +195,26 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
return errors.Errorf("no record found for ref %q", opts.ref)
}

var rec *historyRecord
if opts.ref == "" {
slices.SortFunc(recs, func(a, b historyRecord) int {
return b.CreatedAt.AsTime().Compare(a.CreatedAt.AsTime())
})
for _, r := range recs {
if offset != nil {
if *offset > 0 {
*offset--
continue
}
}
rec = &r
break
}
if offset != nil && *offset > 0 {
return errors.Errorf("no completed build found with offset %d", *offset)
}
}

rec := &recs[0]

c, err := rec.node.Driver.Client(ctx)
if err != nil {
return err
Expand Down

0 comments on commit e19c729

Please sign in to comment.