Rado
Rado

Reputation: 8963

Always "bundle install" before "bundle exec"?

What is the best practice to ensure that dependencies are installed on a build node for any build of a gem?

bundle exec will fail if some of the dependencies are not already installed.

Should I do

bundle install
bundle exec rake

on every build?

Or is there a better way?

Upvotes: 6

Views: 3294

Answers (1)

Jay Dorsey
Jay Dorsey

Reputation: 3662

The bin/setup script that ships with rails uses bundle check || bundle install as a pre-cursor step. That might be a good place to start.

I use bundle install --frozen on our pipelines; frozen makes sure no changes to Gemfile.lock occur. We use a cache, so I don't even bother with the bundle check step.

If you can provide more details about your setup (docker? kubernetes? a hosted provider?) someone might be able to recommend a caching strategy for bundler, if it's the bundle install time that's creating the question.

Typically though, for CI pipelines we always run bundle install --frozen early in our build, even if we have a caching mechanism setup. I've noticed in certain situations the executables aren't linked automatically when restoring form cache so this makes sure everything works. It's not slow by any means; with caching the bundle install --frozen step takes only a second or 2.

Upvotes: 4

Related Questions