Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (c *Client) createBaseBuilder(ctx context.Context, opts CreateBuilderOption
return nil, errors.Wrap(err, "invalid build-image")
}

architecture, err := baseImage.Architecture()
if err != nil {
return nil, errors.Wrap(err, "lookup image Architecture")
}

os, err := baseImage.OS()
if err != nil {
return nil, errors.Wrap(err, "lookup image OS")
Expand All @@ -149,7 +154,7 @@ func (c *Client) createBaseBuilder(ctx context.Context, opts CreateBuilderOption
)
}

lifecycle, err := c.fetchLifecycle(ctx, opts.Config.Lifecycle, opts.RelativeBaseDir, os)
lifecycle, err := c.fetchLifecycle(ctx, opts.Config.Lifecycle, opts.RelativeBaseDir, os, architecture)
if err != nil {
return nil, errors.Wrap(err, "fetch lifecycle")
}
Expand All @@ -159,7 +164,7 @@ func (c *Client) createBaseBuilder(ctx context.Context, opts CreateBuilderOption
return bldr, nil
}

func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleConfig, relativeBaseDir, os string) (builder.Lifecycle, error) {
func (c *Client) fetchLifecycle(ctx context.Context, config pubbldr.LifecycleConfig, relativeBaseDir, os string, architecture string) (builder.Lifecycle, error) {
if config.Version != "" && config.URI != "" {
return nil, errors.Errorf(
"%s can only declare %s or %s, not both",
Expand All @@ -176,14 +181,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)
uri = 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)
uri = uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion), os, architecture)
}

blob, err := c.downloader.Download(ctx, uri)
Expand Down Expand Up @@ -263,10 +268,16 @@ func validateBuildpack(bp buildpack.Buildpack, source, expectedID, expectedBPVer
return nil
}

func uriFromLifecycleVersion(version semver.Version, os string) string {
func 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.x86-64.tgz", version.String(), version.String())
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" {
arch = architecture
}

return fmt.Sprintf("https://github.com/buildpacks/lifecycle/releases/download/v%s/lifecycle-v%s+linux.x86-64.tgz", version.String(), version.String())
return fmt.Sprintf("https://github.com/buildpacks/lifecycle/releases/download/v%s/lifecycle-v%s+linux.%s.tgz", version.String(), version.String(), arch)
}
40 changes: 40 additions & 0 deletions pkg/client/create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,24 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
})

it("should download from predetermined uri for arm64", func() {
prepareFetcherWithBuildImage()
prepareFetcherWithRunImages()
opts.Config.Lifecycle.URI = ""
opts.Config.Lifecycle.Version = "3.4.5"
h.AssertNil(t, fakeBuildImage.SetArchitecture("arm64"))

mockDownloader.EXPECT().Download(
gomock.Any(),
"https://github.com/buildpacks/lifecycle/releases/download/v3.4.5/lifecycle-v3.4.5+linux.arm64.tgz",
).Return(
blob.NewBlob(filepath.Join("testdata", "lifecycle", "platform-0.4")), nil,
)

err := subject.CreateBuilder(context.TODO(), opts)
h.AssertNil(t, err)
})

when("windows", func() {
it("should download from predetermined uri", func() {
packClientWithExperimental, err := client.NewClient(
Expand Down Expand Up @@ -495,6 +513,28 @@ func testCreateBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)
})

it("should download default lifecycle on arm64", func() {
prepareFetcherWithBuildImage()
prepareFetcherWithRunImages()
opts.Config.Lifecycle.URI = ""
opts.Config.Lifecycle.Version = ""
h.AssertNil(t, fakeBuildImage.SetArchitecture("arm64"))

mockDownloader.EXPECT().Download(
gomock.Any(),
fmt.Sprintf(
"https://github.com/buildpacks/lifecycle/releases/download/v%s/lifecycle-v%s+linux.arm64.tgz",
builder.DefaultLifecycleVersion,
builder.DefaultLifecycleVersion,
),
).Return(
blob.NewBlob(filepath.Join("testdata", "lifecycle", "platform-0.4")), nil,
)

err := subject.CreateBuilder(context.TODO(), opts)
h.AssertNil(t, err)
})

when("windows", func() {
it("should download default lifecycle", func() {
packClientWithExperimental, err := client.NewClient(
Expand Down