Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable architecture specific dependencies #622

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

c0d1ngm0nk3y
Copy link
Contributor

fixes #618

Summary

When looking for an dependency, the architecture is taken into account. The default architecture (if not provided by a dependency is "amd64" to ensure backwards compatibility. The architecture to look for is taken from the system or an env variable BP_ARCH to enable unit testing.

Use Cases

Dependencies for several architectures (e.g. "arm" and "amd64")

Checklist

  • I have viewed, signed, and submitted the Contributor License Agreement.
  • I have linked issue(s) that this PR should close using keywords or the Github UI (See docs)
  • I have added an integration test, if necessary.
  • I have reviewed the styleguide for guidance on my code quality.
  • I'm happy with the commit history on this PR (I have rebased/squashed as needed).

@c0d1ngm0nk3y c0d1ngm0nk3y requested a review from a team as a code owner December 20, 2024 15:28
@c0d1ngm0nk3y
Copy link
Contributor Author

@paketo-buildpacks/tooling-maintainers Could someone have a look? That is a prerequisite for supporting multiarch in paketo-buildpacks/nodejs.

@ForestEckhardt ForestEckhardt added the semver:minor A change requiring a minor version bump label Jan 23, 2025
@ForestEckhardt
Copy link
Contributor

Could you please rebase this PR so I can merge it in!

@@ -74,6 +74,9 @@ type Dependency struct {
// StripComponents behaves like the --strip-components flag on tar command
// removing the first n levels from the final decompression destination.
StripComponents int `toml:"strip-components"`

// ARCH is the architecture of this dependency
Arch string `toml:"arch"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several platforms, for example, pack cli has plenty of them when it comes to build and image https://github.com/buildpacks/pack/blob/5cca9c51a61cf1bb8b0b6ba479bbbf10a65f0377/internal/target/platform.go#L31-L47 For nodejs we have a subset of them https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list which I think it would be good to start with. So my suggestion on this one would be to also add another variable called OS or operating-system which will indicate the operating system of the dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no expert on the whole multiarch thing, but operating-system would be wrong, wouldn't it? The operating system is for all dependencies linux - it is the same run image after all. We "only" have to differ dependencies for the architecture of the image. So I thing anything other than Arch would be quite confusing, don't you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that we might need to support generating images for macos, but currently there is no such use case so makes sense to not over-complicate it. LGTM

e.id,
e.version,
e.stack,
e.arch,
strings.Join(e.supportedVersions, ", "),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same on this one we should add the os attribute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we dont use the os, this comment does not apply.

@@ -115,6 +116,12 @@ strip-components = 1
service = postal.NewService(transport).
WithDependencyMappingResolver(mappingResolver).
WithDependencyMirrorResolver(mirrorResolver)

Expect(os.Setenv("BP_ARCH", "amd64")).To(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this one, instead of having BP_ARCH and BP_OS, we could rename the BP_ARCH to something like BP_PLATFORM or BP_TARGET, which will include both architecture and operating system, similar to what pack cli does with the targets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we dont use the os, this comment does not apply.

return systemArch == dep.Arch
}

func archFromSystem() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of clean code, one function should only do one thing, I would remove from this function, the two things that is doing 1. looking if the environment variable exists 2. fetching the system architecture. Changing that function to fetching only the architecture does not make sense as there is already a function for that. Therefore, I would suggest to move this logic out in to the Parent function (Resolve) as I think this is totally normal as there is already logic for validating other things like (dependency version and stacks). Althouh, if you decide to fetch the platform, then it would be good to wrap these two lines in a function called getSystemPlatform as it will be more than one line (one for fetching the GOARCH and one for fetching the GOOS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we dont want to default into the system that the user is using as pack currently fallbacks to linux/amd64, so I would choose this platform as default, in order to avoid any errors from macos users that currently building applications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we dont want to default into the system

I might be completely wrong, but that is not what is done. It looks up the architecture of the runtime, meaning the buildpack that actually called getDependency(). So no other architecture could even work. The BP_ARCH is only needed for unit tests.

I tried to keep everything as similar to libak as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so seems that it is not breaking the default behavior. LGTM

@c0d1ngm0nk3y
Copy link
Contributor Author

Could you please rebase this PR so I can merge it in!

I will update, but wait a bit with the merge so that @pacostas can respond to the comments.

@pacostas
Copy link
Contributor

Could you please rebase this PR so I can merge it in!

I will update, but wait a bit with the merge so that @pacostas can respond to the comments.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:minor A change requiring a minor version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support architecture for dependencies
3 participants