Is it possible to cache gems, so that bundle install
will not install bunch of gems for every build? This takes 5 minutes on every build, that is too much.
I've added this to the circle.yml
config:
dependencies:
cache_directories:
- "/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/"
This is the common directory which is provided by bundle show gem_name
where all system gems are put.
After this addition system writes such log:
restoring cache v4/company/repo_name/dependency/circle-ci/42/mGWhlYQIxyOy0GZtt4QmCw__.tar.gz
restoring home/ubuntu/repo_name/vendor/bundle, home/ubuntu/.m2, home/ubuntu/.ivy2, home/ubuntu/.go_workspace, home/ubuntu/.gradle, home/ubuntu/.rvm/gems/ruby-2.1.2/gems
So, as far as I understand, it restores system gems and gems installed into vendor/bundle
, however, I still see this (and this takes a lot of time):
Installing rake 10.4.2
Installing i18n 0.7.0
Installing json 1.8.2
Installing minitest 5.5.1
...
instead of
using rake 10.4.2
using i18n 0.7.0
using json 1.8.2
using minitest 5.5.1
...
So, it seems, it should work, but it does not. What can be wrong?
The solution is simple: CircleCI runs some commands by default and caches gems also by default in vendor/bundle
, so there is no need to add anything to cache_directories
.
Among those default commands is bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
, that checks presence of gems in the cache directory and installs them if they are not there.
In my case I had project consisting of multiple applications (main application, common UI, API client and API mock) split into 4 different repos. Most of them needed bundle install
commands.
The only thing I had to do is to replace all my bundle install
commands (that always installs gems) with bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
. In such case all gems are installed only the first time I run tests and all the following builds use previously cached gems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With