Skip to content

Commit

Permalink
allowing to create a builder with other architecture available for li…
Browse files Browse the repository at this point in the history
…fecycle

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed May 20, 2024
1 parent 87e4101 commit 3f3b24d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions internal/builder/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
13 changes: 9 additions & 4 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/image/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 3f3b24d

Please sign in to comment.