Merge pull request #39683 from tonistiigi/builder-metadata-timestamps
builder-next: ensure timestamps set for metadata commands
This commit is contained in:
commit
e4611b3e07
1 changed files with 31 additions and 0 deletions
|
@ -137,6 +137,37 @@ func normalizeLayersAndHistory(diffs []digest.Digest, history []ocispec.History,
|
|||
history[i] = h
|
||||
}
|
||||
|
||||
// Find the first new layer time. Otherwise, the history item for a first
|
||||
// metadata command would be the creation time of a base image layer.
|
||||
// If there is no such then the last layer with timestamp.
|
||||
var created *time.Time
|
||||
var noCreatedTime bool
|
||||
for _, h := range history {
|
||||
if h.Created != nil {
|
||||
created = h.Created
|
||||
if noCreatedTime {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
noCreatedTime = true
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in created times for all history items to be either the first new
|
||||
// layer time or the previous layer.
|
||||
noCreatedTime = false
|
||||
for i, h := range history {
|
||||
if h.Created != nil {
|
||||
if noCreatedTime {
|
||||
created = h.Created
|
||||
}
|
||||
} else {
|
||||
noCreatedTime = true
|
||||
h.Created = created
|
||||
}
|
||||
history[i] = h
|
||||
}
|
||||
|
||||
return diffs, history
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue