I’m trying to cache Ruby gems as part of a large project, but it doesn’t seem to be working. It seems to always install the bundler gems and takes a bunch of time. I do see inside of CircleCI that it’s saving the cache and restoring from it, but it doesn’t seem to work. I’m able to SSH into the build and see the gems in that directory. I feel like I’m making a simple mistake.
Here is my task with CircleCI. I have to use machine as this is only part of a longer task.
Hmm, odd. I can’t comment on Bundler (since I barely know what it is, I assume it’s your dependency manager) but that looks like it is nearly working. Perhaps not specifying a path means that all cached paths are restored? That said, I wonder if trying to add an explicit path would be worth a go, just in case?
Are the Gems used from the location you have specified? I don’t use Ruby, but in PHP they are brought inside the project itself.
If I login via SSH and run bundle install it detects that they are already installed, so it’s defo something to do with how it’s restoring the cache. At a loss
Can you run your bundle install in the build in verbose mode, so it can show you in console output why it is installing stuff that is already installed?
Also, prior to doing the install, try doing an ls -R /opt/circleci/.rvm/gems/ruby-2.3.1/gems/ in the build, to make sure the cache really has been restored.
It’s definitely present prior to running bundle install. Unless bundler is installing these gems elsewhere, or it just doesn’t link the two together. Running the gem location commands reveals the directory I’m caching.
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using public_suffix 3.0.2
Using addressable 2.5.2
Using bundler 1.16.1
Using mini_mime 1.0.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.2
Installing nokogiri 1.8.2 with native extensions # This is where it hangs
I wonder if this might be a Stack Overflow question in the making: “How does Bundler determine whether to re-install something or use the currently installed version?”