Skip to content

Commit 1a2bd3c

Browse files
committed
builder-next: ensure timestamps set for metadata commands
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent ecdb0b2 commit 1a2bd3c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

builder/builder-next/exporter/writer.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,37 @@ func normalizeLayersAndHistory(diffs []digest.Digest, history []ocispec.History,
137137
history[i] = h
138138
}
139139

140+
// Find the first new layer time. Otherwise, the history item for a first
141+
// metadata command would be the creation time of a base image layer.
142+
// If there is no such then the last layer with timestamp.
143+
var created *time.Time
144+
var noCreatedTime bool
145+
for _, h := range history {
146+
if h.Created != nil {
147+
created = h.Created
148+
if noCreatedTime {
149+
break
150+
}
151+
} else {
152+
noCreatedTime = true
153+
}
154+
}
155+
156+
// Fill in created times for all history items to be either the first new
157+
// layer time or the previous layer.
158+
noCreatedTime = false
159+
for i, h := range history {
160+
if h.Created != nil {
161+
if noCreatedTime {
162+
created = h.Created
163+
}
164+
} else {
165+
noCreatedTime = true
166+
h.Created = created
167+
}
168+
history[i] = h
169+
}
170+
140171
return diffs, history
141172
}
142173

0 commit comments

Comments
 (0)