From 3cd0cb5ce7af01f097ca5abcc6bb5fa871d98d13 Mon Sep 17 00:00:00 2001 From: Herman Date: Tue, 9 Nov 2021 22:23:29 +0100 Subject: [PATCH] Do not forget CreatedBy in mutate.Canonical (#978) * Add check for missing CreatedBy in canonical image * Remember CreatedBy in mutate.Canonical * Format comparison * fix --- pkg/v1/mutate/mutate.go | 7 ++++++- pkg/v1/mutate/mutate_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/v1/mutate/mutate.go b/pkg/v1/mutate/mutate.go index 6faaec53f..d88ecbfb7 100644 --- a/pkg/v1/mutate/mutate.go +++ b/pkg/v1/mutate/mutate.go @@ -371,8 +371,13 @@ func Time(img v1.Image, t time.Time) (v1.Image, error) { // Strip away timestamps from the config file cfg.Created = v1.Time{Time: t} - for _, h := range cfg.History { + for i, h := range cfg.History { h.Created = v1.Time{Time: t} + h.CreatedBy = ocf.History[i].CreatedBy + h.Comment = ocf.History[i].Comment + h.EmptyLayer = ocf.History[i].EmptyLayer + // Explicitly ignore Author field; which hinders reproducibility + cfg.History[i] = h } return ConfigFile(newImage, cfg) diff --git a/pkg/v1/mutate/mutate_test.go b/pkg/v1/mutate/mutate_test.go index f71573516..40dfb2f03 100644 --- a/pkg/v1/mutate/mutate_test.go +++ b/pkg/v1/mutate/mutate_test.go @@ -503,6 +503,13 @@ func TestCanonical(t *testing.T) { if err != nil { t.Fatal(err) } + for _, h := range cf.History { + want := "bazel build ..." + got := h.CreatedBy + if want != got { + t.Errorf("%q != %q", want, got) + } + } var want, got string want = cf.Architecture got = sourceCf.Architecture