Skip to content

Commit

Permalink
Copy io.buildpacks.base.* labels on rebase
Browse files Browse the repository at this point in the history
For platforms running 0.12 and beyond, copy the io.buildpacks.base.* labels to the new image on rebase.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>
  • Loading branch information
jabrown85 committed Mar 30, 2023
1 parent bb85224 commit 68655c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rebaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ func (r *Rebaser) Rebase(workingImage imgutil.Image, newBaseImage imgutil.Image,
return RebaseReport{}, errors.Wrap(err, "set app image metadata label")
}

hasPrefix := func(l string) bool { return strings.HasPrefix(l, "io.buildpacks.stack.") }
hasPrefix := func(l string) bool {
if r.PlatformAPI.AtLeast("0.12") {
return strings.HasPrefix(l, "io.buildpacks.stack.") || strings.HasPrefix(l, "io.buildpacks.base.")
}
return strings.HasPrefix(l, "io.buildpacks.stack.")
}
if err := image.SyncLabels(newBaseImage, workingImage, hasPrefix); err != nil {
return RebaseReport{}, errors.Wrap(err, "set stack labels")
}
Expand Down
38 changes: 38 additions & 0 deletions rebaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,44 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
})
})

when("image has io.buildpacks.base.* labels", func() {
var tests = []struct {
label string
appImageValue string
runImageValue string
want string
}{
{"io.buildpacks.base.homepage", "v1", "v2", "v2"},
{"io.buildpacks.stack.added", "", "new", "new"},
{"io.buildpacks.base.removed", "old", "", ""},
}

it.Before(func() {
for _, l := range tests {
if l.runImageValue != "" {
h.AssertNil(t, fakeNewBaseImage.SetLabel(l.label, l.runImageValue))
}
if l.appImageValue != "" {
h.AssertNil(t, fakeAppImage.SetLabel(l.label, l.appImageValue))
}
}
})

it("syncs matching labels", func() {
_, err := rebaser.Rebase(fakeAppImage, fakeNewBaseImage, fakeAppImage.Name(), additionalNames)
h.AssertNil(t, err)

for _, test := range tests {
test := test
t.Run(test.label, func(t *testing.T) {
actual, err := fakeAppImage.Label(test.label)
h.AssertNil(t, err)
h.AssertEq(t, test.want, actual)
})
}
})
})

when("image has a digest identifier", func() {
var fakeRemoteDigest = "sha256:c27a27006b74a056bed5d9edcebc394783880abe8691a8c87c78b7cffa6fa5ad"

Expand Down

0 comments on commit 68655c8

Please sign in to comment.