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

prebuild assets location resolution at runtime #3304

Closed
longlho opened this issue Jul 24, 2022 · 14 comments
Closed

prebuild assets location resolution at runtime #3304

longlho opened this issue Jul 24, 2022 · 14 comments
Labels

Comments

@longlho
Copy link

longlho commented Jul 24, 2022

Question about an existing feature

What are you trying to achieve?

I'm trying to integrate sharp in our bazel build which is hermetic and uses sandbox for everything. Effectively what I'm looking for is:

  • Download libvips to a specific location (sandboxed)
  • Download sharp bindings to a specific location (sandboxed)
  • Ability to tell sharp to resolve bindings + libvips from those 2 locations at runtime.

Is there a way to do that?

When you searched for similar issues, what did you find that might be related?

#3270
#2741

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

Please provide sample image(s) that help explain this question

@lovell
Copy link
Owner

lovell commented Jul 24, 2022

@longlho
Copy link
Author

longlho commented Jul 24, 2022

Yup I did but my understanding is i have to set them during "npm install" and not after?

@lovell
Copy link
Owner

lovell commented Jul 24, 2022

Would symlinks suffice? You'd need to link the node_modules/sharp/build and node_modules/sharp/vendor directories to the decompressed contents of their respective tarballs.

@longlho
Copy link
Author

longlho commented Jul 24, 2022

Unfortunately no because the build sandbox is readonly :(

@lovell
Copy link
Owner

lovell commented Jul 24, 2022

Have you considered installing libvips from package manager (or from source)?

@longlho
Copy link
Author

longlho commented Jul 24, 2022

Yup I've kinda tried but bazel manages all external dependencies and is very explicit (e.g download this file from this host with this checksum) and trying to re-compile is pretty hard. I also cannot install it to a global location because it's non-hermetic. Or maybe I'm misunderstanding your suggestion?

@lovell
Copy link
Owner

lovell commented Jul 24, 2022

Did you see the example provided by Bazel at https://github.com/bazelbuild/rules_nodejs/tree/stable/e2e/nodejs_image ?

@longlho
Copy link
Author

longlho commented Jul 24, 2022

Yup pulling in Docker is definitely an option I was just wondering if it can be done w/o it :) I'd love to understand the complexity of making those deps runtime as well.

@lovell
Copy link
Owner

lovell commented Jul 24, 2022

There's another example at https://github.com/aspect-build/rules_js/tree/main/e2e/npm_link_package if you hadn't seen it.

@longlho
Copy link
Author

longlho commented Jul 24, 2022

Yup rules_js is in beta and requires a decent LOE to migrate. It's in our roadmap but at least not until it's stabler.

@lovell
Copy link
Owner

lovell commented Sep 5, 2022

@longlho Were you able to make any progress with this?

@lovell
Copy link
Owner

lovell commented Nov 14, 2022

Closing due to inactivity but please feel free to reopen with more details if further help is required.

In summary, from what I've seen, https://github.com/aspect-build/rules_js offers the best approach, and even uses sharp as an example in its tests.

@lovell lovell closed this as completed Nov 14, 2022
@fmnxl
Copy link

fmnxl commented Aug 8, 2023

Just documenting this in case someone is having the same issue on Nix, since like Bazel it also works with a strict sandbox. I'm building a Next.js app which is packaged with Nix's buildNpmPackage.

Include nativeBuildInputs = [ pkgs.pkg-config ]; buildInputs = [ pkgs.vips ]; in your builder of choice, it would make a global (as far as the build phase is concerned) installation of libvips available. I'm using pkgs.buildNpmPackage, so my config is:

pkgs.buildNpmPackage rec {
  pname = "my-project";
  version = "0.0.1";

  src = pkgs.lib.cleanSource ./.;

  npmDepsHash = "some hash";
  npmPackFlags = [ "--ignore-scripts" ];

  nativeBuildInputs = [
    pkgs.python3 # needed by buildNpmPackage
    pkgs.pkg-config
  ];
  buildInputs = [
    pkgs.vips
  ];
  PKG_CONFIG_PATH = pkgs.pkg-config;
}

@lovell
Copy link
Owner

lovell commented Aug 9, 2023

Anyone interested in sandboxed builds should probably subscribe to #3750 for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants