Skip to content

Commit

Permalink
Do not forget CreatedBy in mutate.Canonical (#978)
Browse files Browse the repository at this point in the history
* Add check for missing CreatedBy in canonical image

* Remember CreatedBy in mutate.Canonical

* Format comparison

* fix
  • Loading branch information
hermanbanken committed Nov 9, 2021
1 parent 4580921 commit 3cd0cb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/v1/mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/v1/mutate/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3cd0cb5

Please sign in to comment.