Skip to content

Add NodeJSRuntimeInfo provider - #863

Closed
Globegitter wants to merge 20 commits into
bazel-contrib:masterfrom
Globegitter:sources-provider
Closed

Globegitter wants to merge 20 commits into
bazel-contrib:masterfrom
Globegitter:sources-provider

Conversation

@Globegitter

@Globegitter Globegitter commented Jun 13, 2019 •

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

When using nodejs_image of rules_docker there currently was no way for it to put the npm modules and source files into different layers so even if just changes are being made to the source files incremental rebuilds will have to repack all of node_modules which can be quite slow. In our app a rebuild could take up to 10s.

What is the new behavior?

We now expose a provider that other rules can access the needed nodejs_binary runfiles separately, split by its toolchain (i.e. the node binary), node_modules, source files and all other necessary/implicit runfiles. This would allow for `nodejs_image´ to create dedicated layers and in my tests it brought incremental builds, where just source files changed, down to ~3s.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This replaces #283 as it has gotten stale by now but also updates the provider to be compatible with the upcoming toolchain support.

@alexeagle

Copy link
Copy Markdown
Collaborator

Cool, I agree we should fix this
One nit: we should have a plan for where Providers are loaded from. Things in /internal should be private API where I think rule authors should probably use all the Providers so they should be public API?
We can discuss in the meeting today how many files they should go in.

@Globegitter

Copy link
Copy Markdown
Author

Ah just saw that comment now, so missed out on talking with @gregmagolan about that. But yes it would be good to find some more public place for these. We also depend on the NodeModuleSources provider in some internal rules.

I also started to adding starlark unit tests, which I think are the perfect way to test this. Just need to finish them up and make sure they also pass on windows.

@Globegitter
Globegitter marked this pull request as ready for review June 14, 2019 12:34
@Globegitter

Copy link
Copy Markdown
Author

I am a fan of these starlark unit-tests. They uncovered some inefficiencies - that we where including all node_modules in sources as well. So we where passing some files around twice. That should be fixed now. Just hoping it will not break anything else.

@alexeagle

Copy link
Copy Markdown
Collaborator

some broken logic doing path.join somewhere...
Cannot find module '/home/circleci/.cache/bazel/_bazel_circleci/02fc451c9ce3986cffaddce25971cb5b/sandbox/processwrapper-sandbox/82/execroot/build_bazel_rules_nodejs/bazel-out/k8-fastbuild/bin/internal/e2e/rollup/test.runfiles/npm/node_modules/home/circleci/.cache/bazel/_bazel_circleci/02fc451c9ce3986cffaddce25971cb5b/sandbox/processwrapper-sandbox/82/execroot/build_bazel_rules_nodejs/bazel-out/k8-fastbuild/bin/internal/e2e/rollup/test.runfiles/build_bazel_rules_nodejs/internal/e2e/rollup/bundle.min.js'

@Globegitter

Copy link
Copy Markdown
Author

Hmm yeah I will investigate.

@Globegitter

Copy link
Copy Markdown
Author

@alexeagle Found a fix and also cleaned up the way runfiles are created and added a test to make sure we have the same contents as before. So this PR is also coming with some slight performance improvements, at least theoretical ones.

@Globegitter

Copy link
Copy Markdown
Author

Ok still some of the tests failing - will investigate.

@Globegitter

Copy link
Copy Markdown
Author

So, should be all fixed now @alexeagle

Globegitter pushed a commit to Globegitter/rules_docker that referenced this pull request Jul 16, 2019
The layers never really worked properly as all the nodejs_binary runfiles, including node_modules and the nodejs binary, where still being put into the top-layer anyway. Now that rules_nodejs are supporting toolchain we could fix that partially by also requiring the toolchain, but that would still not fix node_modules. For that we would need a provider from nodejs_binary, which is proposed here: bazel-contrib/rules_nodejs#863

So we should fix this once it is really possible from the rules_nodejs side.
@Globegitter

Copy link
Copy Markdown
Author

Now that we have toolchain support in we can actually update this provider to include the real toolchain. Will do so shortly.

nlopezgi pushed a commit to bazelbuild/rules_docker that referenced this pull request Jul 16, 2019
The layers never really worked properly as all the nodejs_binary runfiles, including node_modules and the nodejs binary, where still being put into the top-layer anyway. Now that rules_nodejs are supporting toolchain we could fix that partially by also requiring the toolchain, but that would still not fix node_modules. For that we would need a provider from nodejs_binary, which is proposed here: bazel-contrib/rules_nodejs#863

So we should fix this once it is really possible from the rules_nodejs side.
@alexeagle

Copy link
Copy Markdown
Collaborator

I think maybe bazelbuild/rules_docker#1346 made this obsolete? We now get node_modules in a lower layer of the docker image?

@alexeagle alexeagle added the Can Close? We will close this in 30 days if there is no further activity label Jul 17, 2020
@github-actions

Copy link
Copy Markdown
Contributor

This PR was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

@github-actions github-actions Bot closed this Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Can Close? We will close this in 30 days if there is no further activity cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants