From 461466f35ed5c40dd7731b58c6c4b9e81e070fc3 Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Mon, 17 Apr 2023 22:44:43 +0200 Subject: [PATCH] Fix updating run image reference (#1067) * Fix updating run image reference We should use the reference that the extension wrote, as that is expected to be in the daemon (when building locally) `ref.Context().RepositoryStr()` strips the reference of the registry which may not be desired; we should trust the extension to write the correct reference instead. Signed-off-by: Natalie Arellano * Fix acceptance test by updating fixture Signed-off-by: Natalie Arellano * Update README Signed-off-by: Natalie Arellano * Use run image function instead of accessing the field directly Safer in the case the run image is nil Signed-off-by: Natalie Arellano * Change fixture to point to pullable image Signed-off-by: Natalie Arellano * When running pack acceptance, don't consider release candidates or pre-releases Signed-off-by: Natalie Arellano * Pin pack version for acceptance to v0.28.0 pack v0.29.0 accidentally declares support for platform API 0.12 and the acceptance tests aren't passing because `pack build` hasn't actually been updated with support for platform API 0.12 Signed-off-by: Natalie Arellano --------- Signed-off-by: Natalie Arellano --- .github/workflows/build.yml | 4 +-- README.md | 29 ++++++++++--------- acceptance/phase_test.go | 3 ++ acceptance/restorer_test.go | 2 ++ ...ome-extend-false-analyzed.toml.placeholder | 1 + ...some-extend-true-analyzed.toml.placeholder | 3 +- cmd/lifecycle/exporter.go | 8 ++--- cmd/lifecycle/restorer.go | 4 ++- platform/files.go | 7 +++++ 9 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00ee62076..50abc1295 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -262,7 +262,7 @@ jobs: - name: Run pack acceptance run: | cd pack - git checkout $(git describe --abbrev=0 --tags) # check out the latest tag + git checkout v0.28.0 # FIXME: let the pack version float again when pack 0.30.0-pre2 is out LIFECYCLE_PATH="../lifecycle-v${{ env.LIFECYCLE_VERSION }}+linux.x86-64.tgz" \ LIFECYCLE_IMAGE="buildpacksio/lifecycle:${{ env.LIFECYCLE_IMAGE_TAG }}" \ make acceptance @@ -333,7 +333,7 @@ jobs: - name: Run pack acceptance run: | cd pack - git checkout $(git describe --abbrev=0 --tags) # check out the latest tag + git checkout v0.28.0 # FIXME: let the pack version float again when pack 0.30.0-pre2 is out $env:LIFECYCLE_PATH="..\lifecycle-v${{ env.LIFECYCLE_VERSION }}+windows.x86-64.tgz" $env:LIFECYCLE_IMAGE="buildpacksio/lifecycle:${{ env.LIFECYCLE_IMAGE_TAG }}" make acceptance diff --git a/README.md b/README.md index 34bf7f25c..19e20de8d 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,20 @@ A reference implementation of the [Cloud Native Buildpacks specification](https://github.com/buildpacks/spec). ## Supported APIs -| Lifecycle Version | Platform APIs | Buildpack APIs | -|-------------------|----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------| -| 0.16.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9], [0.10][p/0.10], [0.11][p/0.11] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8], [0.9][b/0.9] | -| 0.15.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9], [0.10][p/0.10] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8], [0.9][b/0.9] | -| 0.14.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8] | -| 0.13.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7] | -| 0.12.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6] | -| 0.11.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6] | -| 0.10.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5] | -| 0.9.x | [0.3][p/0.3], [0.4][p/0.4] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4] | -| 0.8.x | [0.3][p/0.3] | [0.2][b/0.2] | -| 0.7.x | [0.2][p/0.2] | [0.2][b/0.2] | -| 0.6.x | [0.2][p/0.2] | [0.2][b/0.2] | +| Lifecycle Version | Platform APIs | Buildpack APIs | +|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------| +| 0.17.x* | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9], [0.10][p/0.10], [0.11][p/0.11], [0.12][p/0.12] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8], [0.9][b/0.9], [0.10][b/0.10] | +| 0.16.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9], [0.10][p/0.10], [0.11][p/0.11] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8], [0.9][b/0.9] | +| 0.15.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9], [0.10][p/0.10] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8], [0.9][b/0.9] | +| 0.14.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8], [0.9][p/0.9] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7], [0.8][b/0.8] | +| 0.13.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7], [0.8][p/0.8] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6], [0.7][b/0.7] | +| 0.12.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6], [0.7][p/0.7] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6] | +| 0.11.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5], [0.6][p/0.6] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5], [0.6][b/0.6] | +| 0.10.x | [0.3][p/0.3], [0.4][p/0.4], [0.5][p/0.5] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4], [0.5][b/0.5] | +| 0.9.x | [0.3][p/0.3], [0.4][p/0.4] | [0.2][b/0.2], [0.3][b/0.3], [0.4][b/0.4] | +| 0.8.x | [0.3][p/0.3] | [0.2][b/0.2] | +| 0.7.x | [0.2][p/0.2] | [0.2][b/0.2] | +| 0.6.x | [0.2][p/0.2] | [0.2][b/0.2] | [b/0.2]: https://github.com/buildpacks/spec/blob/buildpack/v0.2/buildpack.md [b/0.3]: https://github.com/buildpacks/spec/tree/buildpack/v0.3/buildpack.md @@ -31,6 +32,7 @@ A reference implementation of the [Cloud Native Buildpacks specification](https: [b/0.7]: https://github.com/buildpacks/spec/tree/buildpack/v0.7/buildpack.md [b/0.8]: https://github.com/buildpacks/spec/tree/buildpack/v0.8/buildpack.md [b/0.9]: https://github.com/buildpacks/spec/tree/buildpack/v0.9/buildpack.md +[b/0.10]: https://github.com/buildpacks/spec/tree/buildpack/v0.10/buildpack.md [p/0.2]: https://github.com/buildpacks/spec/blob/platform/v0.2/platform.md [p/0.3]: https://github.com/buildpacks/spec/blob/platform/v0.3/platform.md [p/0.4]: https://github.com/buildpacks/spec/blob/platform/v0.4/platform.md @@ -41,6 +43,7 @@ A reference implementation of the [Cloud Native Buildpacks specification](https: [p/0.9]: https://github.com/buildpacks/spec/blob/platform/v0.9/platform.md [p/0.10]: https://github.com/buildpacks/spec/blob/platform/v0.10/platform.md [p/0.11]: https://github.com/buildpacks/spec/blob/platform/v0.11/platform.md +[p/0.12]: https://github.com/buildpacks/spec/blob/platform/v0.12/platform.md \* denotes unreleased version diff --git a/acceptance/phase_test.go b/acceptance/phase_test.go index 9ae067253..47ffca5f2 100644 --- a/acceptance/phase_test.go +++ b/acceptance/phase_test.go @@ -450,6 +450,9 @@ func updateTOMLFixturesWithTestRegistry(t *testing.T, phaseTest *PhaseTest) { // analyzedMD := assertAnalyzedMetadata(t, pPath) if analyzedMD.RunImage != nil { analyzedMD.RunImage.Reference = phaseTest.targetRegistry.fixtures.ReadOnlyRunImage // don't override extend + if analyzedMD.RunImage.Image == "REPLACE" { + analyzedMD.RunImage.Image = phaseTest.targetRegistry.fixtures.ReadOnlyRunImage + } } h.AssertNil(t, encoding.WriteTOML(strings.TrimSuffix(pPath, ".placeholder"), analyzedMD)) } diff --git a/acceptance/restorer_test.go b/acceptance/restorer_test.go index f807b82e5..f9bffe417 100644 --- a/acceptance/restorer_test.go +++ b/acceptance/restorer_test.go @@ -241,6 +241,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-true-analyzed.toml"), cmd.DefaultLogger) h.AssertNil(t, err) h.AssertStringContains(t, analyzedMD.RunImage.Reference, restoreRegFixtures.ReadOnlyRunImage+"@sha256:") + h.AssertEq(t, analyzedMD.RunImage.Image, restoreRegFixtures.ReadOnlyRunImage) h.AssertEq(t, analyzedMD.RunImage.TargetMetadata.OS, "linux") t.Log("writes run image manifest and config to the kaniko cache") ref, err := name.ParseReference(analyzedMD.RunImage.Reference) @@ -275,6 +276,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-false-analyzed.toml"), cmd.DefaultLogger) h.AssertNil(t, err) h.AssertStringContains(t, analyzedMD.RunImage.Reference, restoreRegFixtures.ReadOnlyRunImage+"@sha256:") + h.AssertEq(t, analyzedMD.RunImage.Image, restoreRegFixtures.ReadOnlyRunImage) h.AssertEq(t, analyzedMD.RunImage.TargetMetadata.OS, "linux") t.Log("does not write run image manifest and config to the kaniko cache") fis, err := os.ReadDir(filepath.Join(copyDir, "kaniko")) diff --git a/acceptance/testdata/restorer/container/layers/some-extend-false-analyzed.toml.placeholder b/acceptance/testdata/restorer/container/layers/some-extend-false-analyzed.toml.placeholder index 04e2eadb9..3713c97ae 100644 --- a/acceptance/testdata/restorer/container/layers/some-extend-false-analyzed.toml.placeholder +++ b/acceptance/testdata/restorer/container/layers/some-extend-false-analyzed.toml.placeholder @@ -1,2 +1,3 @@ [run-image] reference = "REPLACE" + image = "REPLACE" diff --git a/acceptance/testdata/restorer/container/layers/some-extend-true-analyzed.toml.placeholder b/acceptance/testdata/restorer/container/layers/some-extend-true-analyzed.toml.placeholder index 505ea0a64..7ca5eea9a 100644 --- a/acceptance/testdata/restorer/container/layers/some-extend-true-analyzed.toml.placeholder +++ b/acceptance/testdata/restorer/container/layers/some-extend-true-analyzed.toml.placeholder @@ -1,3 +1,4 @@ [run-image] reference = "REPLACE" - extend = true \ No newline at end of file + extend = true + image = "REPLACE" diff --git a/cmd/lifecycle/exporter.go b/cmd/lifecycle/exporter.go index 4b9d5d52a..7c1e40a93 100644 --- a/cmd/lifecycle/exporter.go +++ b/cmd/lifecycle/exporter.go @@ -240,12 +240,8 @@ func (e *exportCmd) initDaemonAppImage(analyzedMD platform.AnalyzedMetadata) (im // and writes a digest reference to analyzed.toml. // For remote images, this works perfectly well. // However for local images, the daemon can't find the image when the reference contains a digest, - // so we convert the run image reference back into a name reference by removing the digest. - ref, err := name.ParseReference(e.RunImageRef) - if err != nil { - return nil, "", cmd.FailErr(err, "get run image reference") - } - e.RunImageRef = ref.Context().RepositoryStr() + // so we use image name from analyzed.toml which is the reference written by the extension. + e.RunImageRef = analyzedMD.RunImageImage() } var opts = []local.ImageOption{ diff --git a/cmd/lifecycle/restorer.go b/cmd/lifecycle/restorer.go index 967869fc8..2522b8f2b 100644 --- a/cmd/lifecycle/restorer.go +++ b/cmd/lifecycle/restorer.go @@ -97,7 +97,7 @@ func (r *restoreCmd) Exec() error { } if r.supportsRunImageExtension() && needsPulling(analyzedMD.RunImage) { cmd.DefaultLogger.Debugf("Pulling run image metadata...") - runImageRef := analyzedMD.RunImage.Image + runImageRef := analyzedMD.RunImageImage() if runImageRef == "" { runImageRef = analyzedMD.RunImage.Reference // older platforms don't populate Image } @@ -115,6 +115,7 @@ func (r *restoreCmd) Exec() error { } analyzedMD.RunImage = &platform.RunImage{ Reference: digestRef, + Image: analyzedMD.RunImageImage(), Extend: true, TargetMetadata: targetData, } @@ -134,6 +135,7 @@ func (r *restoreCmd) Exec() error { } analyzedMD.RunImage = &platform.RunImage{ Reference: digestRef, + Image: analyzedMD.RunImageImage(), Extend: analyzedMD.RunImage.Extend, TargetMetadata: targetData, } diff --git a/platform/files.go b/platform/files.go index 144be0a71..c017d757e 100644 --- a/platform/files.go +++ b/platform/files.go @@ -37,6 +37,13 @@ func (amd AnalyzedMetadata) PreviousImageRef() string { return amd.PreviousImage.Reference } +func (amd AnalyzedMetadata) RunImageImage() string { + if amd.RunImage == nil { + return "" + } + return amd.RunImage.Image +} + func (amd AnalyzedMetadata) RunImageRef() string { if amd.RunImage == nil { return ""