-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Make lockfiles generated on macOS include a lock for Linux by default #5700
Conversation
This is very much a new idea and I might be wrong, but should we print a message when we do this? “Automatically adding linux-x86 to the lockfile for future deployments.” or something? Also, what if I deploy to linux-arm machines and I don’t want to automatically lock to linux-x86? Can we provide an option to disable this, or configure the platform that is always automatically added? |
Yeah, I figured the desire to disable this could come up but then I thought that this doesn't really affect end users in any way, every thing should work just as it worked before, so I'm not sure anybody will want to disable this or configure it in any way. The only reason would be "lockfile aesthetics"? Anyways, I'm not opposed to adding a configuration to toggle this off. I wouldn't like to allow configuring the specific extra platform because Linux is the 99% case and because there's a bit of confusion regarding platforms in the codebase and I'm really not sure how this will behave for other platforms (in particular Windows and Java). I would like to figure things out before committing to adding things, but this seems like a handy, mostly transparent, improvement. Basically, it's just running |
Regarding the message, I think it goes together with configuring this. If we add a configuration option, then logging something definitely makes sense. But if not, I wouldn't log anything because then maybe someone will want to disable it just because they saw the message 😆. Also, something that makes me hesitate allowing this to be configured is that my initial plan was to "just add all platforms where the resolution is valid". So allowing this to be configured feels like an opposite direction. Finally, if we configure this, I think there's two options:
|
Well, after a bit more thought, users are probably going to request this anyways, and making this a configuration that defaults to linux seems simple enough. Plus logging a message like the one you mentioned makes things also clear for users. Plus @schneems already suggested exactly this solution at #4269 (comment). So I think let's implement both of your suggestions @indirect. |
Sorry for too many message but also I just noticed that I did a bit of diagonal reading of your first message and missed this part 😳
So definitely this is not just lockfile aesthetics and makes sense to allow configuring it 👍. I will work on it! |
> what if I deploy to linux-arm machines
So definitely this is not just lockfile aesthetics and makes sense to
allow configuring it 👍. I will work on it!
also `x86_64-linux-musl`!
|
@deivid-rodriguez If you think it makes sense, that sounds good to me. :) |
As others have pointed out, there's a question of which Linux. I don't understand why I still also don't see why the local developer machine's architecture should have any bearing on lock file whatsoever since it says nothing about anywhere else that the gems might be installed and the whole point of a Gemfile is to be a platform-independent way to specify required Ruby gem versions, but that's another debate. |
I have no idea where you got the idea that the entire point of a Gemfile is to be platform independent, but for the record: it is not. Gemfiles are usually able to be applied to multiple platforms, but sometimes they can’t be. The generic ruby platform is often workable, but sometimes isn’t. The lockfile in particular cannot provide Bundler’s basic guarantee of “the same code” as soon as two platforms are involved—Heroku has never actually “just worked” this entire time, it has just been true that the most common case didn’t run into any of the cross platform issues. |
(Bundler creating an additional lock resolution for each platform is the only solution we have for this set of problems, and it is why we now have multiple platforms in the lockfile.) |
The time RubyGems allowed versions of gems precompiled for specific architectures, the lockfile stopped being platform independent (and also stopped working at all in some cases). I know you @pond did not run into these issues, but that doesn't mean everything worked perfectly. Anyways, adding back the "ruby" platform as a fallback for this case is an option. We would have to warn (and recommend adding the specific platform instead) when this "generic" platform gets actually used for materializing the lockfile into actual gems. This is because by doing this we would lose the guarantee mentioned by @indirect that in frozen mode the same lockfile always deploys the exact same set of gems. But at least things would "work" again by default. These two solutions are not mutually exclusive, but the current one is on the one hand, simpler to implement, and on the other hand, it already covers the most common cases. So I'd go with this one for now and see how it goes, and whether we should also add the "fallback platform" to cover more cases by default. |
Well, OK; that's surprising. I had this idea that Ruby and its gems were meant to run on more than one operating system and architecture. The only mechanism in this ecosystem that lets us specify exact versions of gems and their dependencies is Bundler. If
So as a suggestion or discussion point - can we have Bundler write the (EDIT: @deivid-rodriguez's follow up hadn't shown when I reloaded the page for this issue in my browser, but after submitting this answer it showed up - GitHub's page cacheing can be weird. I see that it's being considered as a "maybe" - cool!). After all, what's the lockfile for?
...though of course:
|
(Also as a note, the engagement on this discussion by the community & maintainers is excellent & helps everyone understand what's being done, and why, a lot more; it'll help in future too as this thread can be pointed to; so, thanks for that!) |
Yes, if you specified exact requirements for ALL of your dependencies (including all transitive dependencies), and if the Gemfile DSL was fully complete and allowed you to specific the platforms your application should work on. I guess you can imagine why nobody would do this (even if we made it possible by expanding the Gemfile DSL).
Well, not only that. The The above is in addition to the resolution not guaranteed to be correct if specific platforms are not recorded in the Anyways, with this feature you should be able to specify not only |
Updated name to make it slightly clearer that we will resolve and lock for linux, but we have no idea if your bundle will work on linux. 😅 |
Thanks @indirect :) |
9eee887
to
13a1b0d
Compare
13a1b0d
to
724ac22
Compare
3d0d2ad
to
f96564a
Compare
050dce7
to
556f1e4
Compare
0bdf970
to
9c2c5e7
Compare
This is ready for a review now! |
Just to clarify what I ended up implementing here. I did not make this specific to Linux/macOS, but to any "ruby platforms" (not Windows, not Java). So, for fresh lockfiles, we now resolve for the running platform, and if it's a "ruby platform", we'll also lock any other "ruby platforms" that are compatible with the resolution that we found. |
This is a step forward towards eventually including metadata in the lockfile.
Since we started locking the specific platform in the lockfile, that has created an annoying situation for users that don't develop on Linux. They will create a lockfile on their machines, locking their local platform, for example, darwin. But then that lockfile won't work automatically when deploying to Heroku for example, because the lockfile is frozen and the Linux platform is not included. There's the chance though that resolving against two platforms (Linux + the local platform) won't succeed while resolving for just the current platform will. So, instead, we check other platform specific variants available for the resolution we initially found, and lock those platforms and specs too if they satisfy the resolution. This is only done when generating new lockfiles from scratch, existing lockfiles should keep working as before, and it's only done for "ruby platforms", i.e., not Java or Windows which have their own complexities, and so are excluded. With this change, we expect that MacOS users can bundle locally and deploy to Heroku without needing to do anything special.
9c2c5e7
to
5f24f06
Compare
Thank you! This solves one of our regular first-deploy issues! ❤️ |
rubygems/rubygems#5700 This reverts commit c28f1ee.
What was the end-user or developer problem that led to this PR?
Locking only the specific platform in lockfiles causes issues in CI platforms or Heroku, that run on Linux. This issue only appeared after we started locking the specific platform in the lockfile. Previously, although platform specific resolution would not always be correct, the general case would just work because platform specific variants where chosen at install time (they were not recorded in the lockfile at all).
What is your fix for the problem, implemented in this PR?
My fix is to, after resolving for the current platform like we do now, check whether the resolution found is also compatible with Linux (the 99% case), and if so, add the linux platform and linux specific variants to the lockfile.
This way, new lockfiles generated on Darwin should just work on Linux.
For example, for the following
Gemfile
,running
bundle install
on my MacOS laptop results ingenerating the following
Gemfile.lock
file, that should just work on LinuxCloses #4269.
Closes #5338.
Make sure the following tasks are checked