mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
Merge pull request #3049 from tonistiigi/history-inspect-index
history: allow index based inspect of builds
This commit is contained in:
commit
e19c729d3e
@ -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)
|
recs, err := queryRecords(ctx, opts.ref, nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -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)
|
return errors.Errorf("no record found for ref %q", opts.ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rec *historyRecord
|
||||||
if opts.ref == "" {
|
if opts.ref == "" {
|
||||||
slices.SortFunc(recs, func(a, b historyRecord) int {
|
slices.SortFunc(recs, func(a, b historyRecord) int {
|
||||||
return b.CreatedAt.AsTime().Compare(a.CreatedAt.AsTime())
|
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)
|
c, err := rec.node.Driver.Client(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user