From 6efcd74c6b8a139c21d7e65fdc008f60980c3265 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 6 Aug 2019 17:42:46 -0700 Subject: [PATCH] builder-next: ensure timestamps set for metadata commands Signed-off-by: Tonis Tiigi (cherry picked from commit 1a2bd3cf7dab6f4e2e96a44fe2084bc06044802b) --- builder/builder-next/exporter/writer.go | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/builder/builder-next/exporter/writer.go b/builder/builder-next/exporter/writer.go index dff8a7ed27..b0f51c6ff5 100644 --- a/builder/builder-next/exporter/writer.go +++ b/builder/builder-next/exporter/writer.go @@ -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 }