Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e19c729

Browse files
authoredMar 6, 2025··
Merge pull request #3049 from tonistiigi/history-inspect-index
history: allow index based inspect of builds
2 parents aefa49c + 058c098 commit e19c729

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed
 

‎commands/history/inspect.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
173173
}
174174
}
175175

176+
var offset *int
177+
if strings.HasPrefix(opts.ref, "^") {
178+
off, err := strconv.Atoi(opts.ref[1:])
179+
if err != nil {
180+
return errors.Wrapf(err, "invalid offset %q", opts.ref)
181+
}
182+
offset = &off
183+
opts.ref = ""
184+
}
185+
176186
recs, err := queryRecords(ctx, opts.ref, nodes)
177187
if err != nil {
178188
return err
@@ -185,14 +195,26 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
185195
return errors.Errorf("no record found for ref %q", opts.ref)
186196
}
187197

198+
var rec *historyRecord
188199
if opts.ref == "" {
189200
slices.SortFunc(recs, func(a, b historyRecord) int {
190201
return b.CreatedAt.AsTime().Compare(a.CreatedAt.AsTime())
191202
})
203+
for _, r := range recs {
204+
if offset != nil {
205+
if *offset > 0 {
206+
*offset--
207+
continue
208+
}
209+
}
210+
rec = &r
211+
break
212+
}
213+
if offset != nil && *offset > 0 {
214+
return errors.Errorf("no completed build found with offset %d", *offset)
215+
}
192216
}
193217

194-
rec := &recs[0]
195-
196218
c, err := rec.node.Driver.Client(ctx)
197219
if err != nil {
198220
return err

0 commit comments

Comments
 (0)
Please sign in to comment.