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

Fix bundle install running twice when you change your Gemfile #8

Closed
nickjj opened this issue Feb 24, 2021 · 4 comments
Closed

Fix bundle install running twice when you change your Gemfile #8

nickjj opened this issue Feb 24, 2021 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@nickjj
Copy link
Owner

nickjj commented Feb 24, 2021

This stems from having to generate webpacker packs for our test environment which means our webpacker image needs the complete Rails app available since the tests themselves end up running in the webpacker container. That's why it runs twice. Once for that and then again for the regular web image.

I know this kind of stinks because running bundle install takes a long time with Docker since if you change 1 dependency all dependencies need to be re-installed since that's how Docker layers work, and with this current set up we get dinged twice.

If we don't use a multi-stage build then our final Docker image is going to be over double in size since it'll include the entire Node runtime + all of the package.json libraries which isn't good.

Also we would still get hit with other delays, because if everything is in 1 image we have to individually run yarn install and bundle install, which means if you did yarn first it would then invalidate Docker's cache for bundle which means every time we change our package.json file our gems would get re-installed too. So moving to 1 image isn't ideal either.

I'm open for ideas on how to solve this.

@nickjj nickjj added enhancement New feature or request help wanted Extra attention is needed labels Feb 24, 2021
@smshuja
Copy link

smshuja commented May 29, 2021

How about copying bundler dependencies from webpacker like you do for public assets?

something like this would work? I mean once its copied, running bundle install again should be pretty fast.

COPY --chown=ruby:ruby --from=webpacker /app/vendor/bundle /vendor

@nickjj
Copy link
Owner Author

nickjj commented May 29, 2021

Hey, that's a good idea.

I don't think we would even need to run it again if we copy over /usr/local/bundle. Do you see a reason why we would have to?

I tested it here and the COPY step took a second to copy the files and afterwards the project was able to be upped successfully and the tests are passing.

I ran both a run bundle:install and run bundle:update. Also manually upped the project and ran run cmd bundle install which finished very quickly. In all cases the correct thing happened and it was fast.

@smshuja
Copy link

smshuja commented May 30, 2021

Thats great. On our project though (not using docker yet), when I restore the bundler dependencies in semaphoreci, it doesn't seem to work without running the command again, must be some other issue.

@nickjj
Copy link
Owner Author

nickjj commented May 30, 2021

I wonder if that's because they're using a different CPU architecture or distro where it's not as simple as copying files over and new files need to be created from scratch but most of it works so it's still fast?

I just pushed it (without running it twice), let's see what happens. If it turns out to be broken in some case it can always be patched to add in the 2nd run. If you want to test out the master branch that would be much appreciated.

Here is the commit: 7b08daf

@nickjj nickjj closed this as completed May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants