Skip to content

feat: Support mapping the vendor cache from workspace #92

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

Merged
merged 5 commits into from
Jul 8, 2021

Conversation

russell
Copy link
Contributor

@russell russell commented Mar 18, 2021

It's pretty common for ruby projects to vendor their dependencies this
is to help speedup install time and is probably more useful for hybrid
projects rather than pure bazel ones that can use bazel caches.
Needless to say it's still an important feature that will make CI
faster in cases where there is no cache.

This uses some ticks saw in the nodejs rules, they use a similar mechanism to mount the node_modules into the workspace. https://bazelbuild.github.io/rules_nodejs/dependencies.html#using-bazel-managed-dependencies

for example to use this you would be required to declare it like this

workspace(
    name = "my_wksp",
    managed_directories = {"@bundle": ["vendor"]},
)

ruby_bundle(
    name = "bundle",
    bundler_version = "2.1.2",
    excludes = {
        "mini_portile": ["test/**/*"],
    },
    vendor_cache = True,
    gemfile = "//:Gemfile",
    gemfile_lock = "//:Gemfile.lock",
)

This would mount the bundle workspace directory into the run time environment, and allow bundler to use it

I'm just going to make this as a draft, but i would like feedback about if this is a reasonable approach, and if we should add tests for this case?

fixes: #62

@kigster
Copy link
Contributor

kigster commented Mar 18, 2021

I like this. I suggest looking through the tests under examples/simple and adding a mini repo with vendored deps.

It's pretty common for ruby projects to vendor their dependencies this
is to help speedup install time and is probably more useful for hybrid
projects rather than pure bazel ones that can use bazel caches.
Needless to say it's still an important feature that will make CI
faster in cases where there is no cache.
@russell russell force-pushed the rsim.add-vendor-cache branch from 2d1811c to 7ae6b39 Compare March 19, 2021 05:56
@russell russell marked this pull request as ready for review March 20, 2021 14:43
@russell russell requested review from kigster and yugui as code owners March 20, 2021 14:43
Copy link
Contributor

@kigster kigster left a comment

Choose a reason for hiding this comment

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

I love this! Great idea and thank you for adding a working example.

One question: it is my understanding that *.gem file is just an archive with gem sources. However when the Bundler installs the gem, those that have native C-extensions will be built. Can this result in a case if eg Mac OSX binaries being "vendored" for a Linux runtime? Or are we simply talking about the sources in the *.gem files?

@russell
Copy link
Contributor Author

russell commented Mar 28, 2021

I love this! Great idea and thank you for adding a working example.

One question: it is my understanding that *.gem file is just an archive with gem sources. However when the Bundler installs the gem, those that have native C-extensions will be built. Can this result in a case if eg Mac OSX binaries being "vendored" for a Linux runtime? Or are we simply talking about the sources in the *.gem files?

You can choose, the flag's your looking for are force_ruby_platform or cache_all_platforms. It' up you the developer if you want to vendor the prebuilt binary, but doing that will require you to add all the other platforms to your lock file. using commands like bundle lock --add-platform x86_64-darwin-19 and bundle lock --add-platform x86_64-linux.

Either way things don't fail if a gem is missing from the bundle that will only happen if you run bundle install --local otherwise bunder can still pull gems from remote sources I believe. The whole point of vendoring is that it's faster than downloading the same list of gems in ephemeral environments

Copy link
Contributor

@kigster kigster left a comment

Choose a reason for hiding this comment

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

This is very good, thank you for your contribution!

@kigster
Copy link
Contributor

kigster commented Jul 8, 2021

Need to make sure that the test suite is passing.

@kigster
Copy link
Contributor

kigster commented Jul 8, 2021

Well, since it's passing!

Congrats, and thank you once again 👍🏼

@kigster kigster merged commit 943b6a6 into bazelruby:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ruby_bundle should support local gems
2 participants