From f099422a8b3738989510d45d499c84b51414cd7f Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:39:42 +0000 Subject: [PATCH] Use correct run image label name for distro name/version 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 #1324. Signed-off-by: Ed Morley <501702+edmorley@users.noreply.github.com> --- phase/analyzer_test.go | 4 ++-- phase/rebaser_test.go | 12 ++++++------ platform/run_image.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/phase/analyzer_test.go b/phase/analyzer_test.go index cfa165f37..71f965f0a 100644 --- a/phase/analyzer_test.go +++ b/phase/analyzer_test.go @@ -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) diff --git a/phase/rebaser_test.go b/phase/rebaser_test.go index 8791f56d5..0931b8fa7 100644 --- a/phase/rebaser_test.go +++ b/phase/rebaser_test.go @@ -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"}}`) diff --git a/platform/run_image.go b/platform/run_image.go index edba84b85..a750aaf81 100644 --- a/platform/run_image.go +++ b/platform/run_image.go @@ -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) {