Skip to content

Commit

Permalink
Merge pull request #269 from buildpacks/fix/rebase-history
Browse files Browse the repository at this point in the history
Ensure we always normalize history before saving
  • Loading branch information
natalieparellano authored Apr 22, 2024
2 parents bef4977 + abe3e07 commit 30b0025
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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

0 comments on commit 30b0025

Please sign in to comment.