Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we always normalize history before saving #269

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cnb_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,15 @@ func (i *CNBImageCore) SetCreatedAtAndHistory() error {
if i.preserveHistory {
// set created at for each history
err = i.MutateConfigFile(func(c *v1.ConfigFile) {
c.History = NormalizedHistory(c.History, len(c.RootFS.DiffIDs))
for j := range c.History {
c.History[j].Created = v1.Time{Time: i.createdAt}
}
})
} else {
// zero history
err = i.MutateConfigFile(func(c *v1.ConfigFile) {
c.History = NormalizedHistory(c.History, len(c.RootFS.DiffIDs))
for j := range c.History {
c.History[j] = v1.History{Created: v1.Time{Time: i.createdAt}}
}
Expand Down
9 changes: 9 additions & 0 deletions remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,14 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
newBaseImg, err := remote.NewImage(newBase, authn.DefaultKeychain, remote.FromBaseImage(newBase))
h.AssertNil(t, err)

h.AssertNil(t, newBaseImg.MutateConfigFile(func(c *v1.ConfigFile) {
c.History = []v1.History{
{CreatedBy: "/new-base.txt"},
{CreatedBy: "FOOBAR", EmptyLayer: true}, // add empty layer history
{CreatedBy: "/otherfile.txt"},
}
})) // don't save the image, as that will strip the empty layer history

err = img.Rebase(oldTopLayerDiffID, newBaseImg)
h.AssertNil(t, err)
h.AssertNil(t, img.Save())
Expand All @@ -1288,6 +1296,7 @@ func testImage(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, rebasedImgConfig.OS, newBaseConfig.OS)
h.AssertEq(t, rebasedImgConfig.OSVersion, newBaseConfig.OSVersion)
h.AssertEq(t, rebasedImgConfig.Architecture, newBaseConfig.Architecture)
h.AssertEq(t, len(rebasedImgConfig.History), len(rebasedImgConfig.RootFS.DiffIDs))
})
})
})
Expand Down
Loading