Skip to content

Commit

Permalink
Use correct run image label name for distro name/version
Browse files Browse the repository at this point in the history
The spec and docs say that the run image distro and version should be
specified via the Docker image labels `io.buildpacks.base.distro.name`
and `io.buildpacks.base.distro.version`.

See:
https://github.com/buildpacks/spec/blob/buildpack/v0.10/platform.md#target-data

However, until now the lifecycle implementation was checking for
label names that were missing the `.base` substring from the name.

This causes distro name/version `buildpack.toml` target detection
to fail, as well as the env vars `CNB_TARGET_DISTRO_NAME` and
`CNB_TARGET_DISTRO_VERSION` not to be set correctly in the
buildpack environment.

Fixes buildpacks#1324.
  • Loading branch information
edmorley committed Mar 27, 2024
1 parent 435d226 commit e105bb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions phase/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ func testAnalyzer(platformAPI string) func(t *testing.T, when spec.G, it spec.S)
h.AssertNil(t, previousImage.SetOSVersion("95"))
h.AssertNil(t, previousImage.SetArchitecture("Pentium"))
h.AssertNil(t, previousImage.SetVariant("MMX"))
h.AssertNil(t, previousImage.SetLabel("io.buildpacks.distro.name", "moobuntu"))
h.AssertNil(t, previousImage.SetLabel("io.buildpacks.distro.version", "Helpful Holstein"))
h.AssertNil(t, previousImage.SetLabel("io.buildpacks.base.distro.name", "moobuntu"))
h.AssertNil(t, previousImage.SetLabel("io.buildpacks.base.distro.version", "Helpful Holstein"))

md, err := analyzer.Analyze()
h.AssertNil(t, err)
Expand Down
12 changes: 6 additions & 6 deletions phase/rebaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,17 +771,17 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) {
h.AssertError(t, err, `unable to satisfy target os/arch constraints; new run image: {"os":"linux","arch":"amd64","arch-variant":"variant2"}, old run image: {"os":"linux","arch":"amd64","arch-variant":"variant1"}`)
})

it("errors and prevents the rebase from taking place when the io.buildpacks.distro.name are different", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.distro.name", "distro1"))
h.AssertNil(t, fakeNewBaseImage.SetLabel("io.buildpacks.distro.name", "distro2"))
it("errors and prevents the rebase from taking place when the io.buildpacks.base.distro.name are different", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.base.distro.name", "distro1"))
h.AssertNil(t, fakeNewBaseImage.SetLabel("io.buildpacks.base.distro.name", "distro2"))

_, err := rebaser.Rebase(fakeAppImage, fakeNewBaseImage, fakeAppImage.Name(), additionalNames)
h.AssertError(t, err, `unable to satisfy target os/arch constraints; new run image: {"os":"linux","arch":"amd64","distro":{"name":"distro2","version":""}}, old run image: {"os":"linux","arch":"amd64","distro":{"name":"distro1","version":""}}`)
})

it("errors and prevents the rebase from taking place when the io.buildpacks.distro.version are different", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.distro.version", "version1"))
h.AssertNil(t, fakeNewBaseImage.SetLabel("io.buildpacks.distro.version", "version2"))
it("errors and prevents the rebase from taking place when the io.buildpacks.base.distro.version are different", func() {
h.AssertNil(t, fakeAppImage.SetLabel("io.buildpacks.base.distro.version", "version1"))
h.AssertNil(t, fakeNewBaseImage.SetLabel("io.buildpacks.base.distro.version", "version2"))

_, err := rebaser.Rebase(fakeAppImage, fakeNewBaseImage, fakeAppImage.Name(), additionalNames)
h.AssertError(t, err, `unable to satisfy target os/arch constraints; new run image: {"os":"linux","arch":"amd64","distro":{"name":"","version":"version2"}}, old run image: {"os":"linux","arch":"amd64","distro":{"name":"","version":"version1"}}`)
Expand Down
4 changes: 2 additions & 2 deletions platform/run_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const (
// TargetLabel is the label containing the target ID.
TargetLabel = "io.buildpacks.base.id"
// OSDistroNameLabel is the label containing the OS distribution name.
OSDistroNameLabel = "io.buildpacks.distro.name"
OSDistroNameLabel = "io.buildpacks.base.distro.name"
// OSDistroVersionLabel is the label containing the OS distribution version.
OSDistroVersionLabel = "io.buildpacks.distro.version"
OSDistroVersionLabel = "io.buildpacks.base.distro.version"
)

func BestRunImageMirrorFor(targetRegistry string, runImageMD files.RunImageForExport, checkReadAccess CheckReadAccess) (string, error) {
Expand Down

0 comments on commit e105bb9

Please sign in to comment.