Bundle Install Tries to Use Cache File

Bundle install tries to use cache file

okay, first of all, you could solve all this issues easily by using rvm (user installation), see http://rvm.io, if that is not an option, you could try using project-specific gem paths.
for example i have the following bundler config file (~/.bundle/config)

---
BUNDLE_PATH: .bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"

which causes bundler to install all gems in a .bundle sub directory (inside your project folder, where you run bundle install). now, if you remember to use bundle exec for your bins (e.g. cap(istrano)), you're fine.

if you somehow f*cked up your bundler / cache, try deleting the .bundle folder (in your project folder)

Is it possible to bundle / install gems from a local cache?

You can add local directories to your Gemfile (example from the docs):

gem "nokogiri", :path => "~/sw/gems/nokogiri"

Alternatively, you can set up a local Git repository with the gems in it and write a Gemfile like this:

gem "gem1", :git    => "file:///tmp/gems",
:branch => "gem1"

Docker bundle install cache issues when updating gems

I cache the gems to a tar file in the application tmp directory. Then I copy the gems into a layer using the ADD command before doing the bundle install. From my Dockerfile.yml:

WORKDIR /home/app

# restore the gem cache. This only runs when
# gemcache.tar.bz2 changes, so usually it takes
# no time
ADD tmp/gemcache.tar.bz2 /var/lib/gems/

COPY Gemfile /home/app/Gemfile
COPY Gemfile.lock /home/app/Gemfile.lock
RUN gem update --system && \
gem update bundler && \
bundle install --jobs 4 --retry 5

Be sure you are sending the gem cache to your docker machine. My gemcache is 118MB, but since I am building locally it copies fast. My .dockerignore:

tmp
!tmp/gemcache.tar.bz2

You need to cache the gems from a built image, but initially you may not have an image. Create an empty cache like so (I have this in a rake task):

task :clear_cache do
sh "tar -jcf tmp/gemcache.tar.bz2 -T /dev/null"
end

After the image is built copy the gems to the gem cache. My image is tagged app. I create a docker container from the image, copy /var/lib/gems/2.2.0 into my gemcache using the docker cp command, and then delete the container. Here's my rake task:

task :cache_gems do
id = `docker create app`.strip
begin
sh "docker cp #{id}:/var/lib/gems/2.2.0/ - | bzip2 > tmp/gemcache.tar.bz2"
ensure
sh "docker rm -v #{id}"
end
end

On the subsequent image build the gemcache is copied to a layer before the bundle install is called. This takes some time, but it is faster than a bundle install from scratch.

Builds after that are even faster because the docker has cached the ADD tmp/gemcache.tar.bz2 /var/lib/gems/ layer. If there are any changes to Gemfile.lock only those changes are built.

There is no reason to rebuild the gem cache on each Gemfile.lock change. Once there are enough differences between the cache and the Gemfile.lock that a bundle install is slow you can rebuild the gem cache. When I do want to rebuild the gem cache it is a simple rake cache_gems command.

How Does Bundler Determine to Re-Install Something?

Solution was to use bundle install --path vendor/cache and cache the vendor/cache path instead.

how do I speed up a bundle install?

To avoid updating sources:

gem install my_gem --no-update-sources

You could setup a local gem repository, and specify local file paths for your gems in Gemfile.

gem 'my_gem', '1.0.0', :path => '/path/to/my_gem'

You could also set up a local rubygems server, which could be used through:

source 'http://127.0.0.1:8080' # your gem server



Related Topics



Leave a reply



Submit