From 3f3b24d2f93821959d64792f996089ea3c9d3f40 Mon Sep 17 00:00:00 2001 From: Juan Bustamante Date: Mon, 20 May 2024 15:51:28 -0500 Subject: [PATCH] allowing to create a builder with other architecture available for lifecycle Signed-off-by: Juan Bustamante --- internal/builder/lifecycle.go | 5 +++++ pkg/client/create_builder.go | 13 +++++++++---- pkg/image/fetcher.go | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/builder/lifecycle.go b/internal/builder/lifecycle.go index 92c860ae9..4f2d4df94 100644 --- a/internal/builder/lifecycle.go +++ b/internal/builder/lifecycle.go @@ -120,3 +120,8 @@ func (l *lifecycle) binaries() []string { } return binaries } + +// SupportedLinuxArchitecture returns true for each binary architecture available at https://github.com/buildpacks/lifecycle/releases/ +func SupportedLinuxArchitecture(arch string) bool { + return arch == "arm64" || arch == "ppc64le" || arch == "s390x" +} diff --git a/pkg/client/create_builder.go b/pkg/client/create_builder.go index 6c4cb2d16..d2b184f01 100644 --- a/pkg/client/create_builder.go +++ b/pkg/client/create_builder.go @@ -254,14 +254,14 @@ func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleCon return nil, errors.Wrapf(err, "%s must be a valid semver", style.Symbol("lifecycle.version")) } - uri = uriFromLifecycleVersion(*v, os, architecture) + uri = c.uriFromLifecycleVersion(*v, os, architecture) case config.URI != "": uri, err = paths.FilePathToURI(config.URI, relativeBaseDir) if err != nil { return nil, err } default: - uri = uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion), os, architecture) + uri = c.uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion), os, architecture) } blob, err := c.downloader.Download(ctx, uri) @@ -405,15 +405,20 @@ func validateModule(kind string, module buildpack.BuildModule, source, expectedI return nil } -func uriFromLifecycleVersion(version semver.Version, os string, architecture string) string { +func (c *Client) uriFromLifecycleVersion(version semver.Version, os string, architecture string) string { arch := "x86-64" if os == "windows" { return fmt.Sprintf("https://github.com/buildpacks/lifecycle/releases/download/v%s/lifecycle-v%s+windows.%s.tgz", version.String(), version.String(), arch) } - if architecture == "arm64" { + if builder.SupportedLinuxArchitecture(architecture) { arch = architecture + } else { + // TODO: Do we want to fail in this case instead of a warning? + // I added the warning to help the buildpack authors understand if they builder ended up with a wrong + // lifecycle binary. + c.logger.Warnf("trying to download a lifecycle binary for an unsupported architecture: %s, using default %s", style.Symbol(architecture), style.Symbol(arch)) } return fmt.Sprintf("https://github.com/buildpacks/lifecycle/releases/download/v%s/lifecycle-v%s+linux.%s.tgz", version.String(), version.String(), arch) diff --git a/pkg/image/fetcher.go b/pkg/image/fetcher.go index c51f3fcb5..efa4bc995 100644 --- a/pkg/image/fetcher.go +++ b/pkg/image/fetcher.go @@ -197,6 +197,7 @@ func (f *Fetcher) fetchRemoteImage(name string, target *dist.Target) (imgutil.Im f.logger.Warnf("trying to fetch an image with more than one OS distribution, using %s", style.Symbol(target.Distributions[0].Version)) } } + f.logger.Debugf("Fetching image %s with platform %v", style.Symbol(name), platform) image, err = remote.NewImage(name, f.keychain, remote.FromBaseImage(name), remote.WithDefaultPlatform(platform)) }