BundleDepot
Utility for caching bundled gems.
Especially useful for CI servers that rely on clean build directories, or use
multiple build directories and need to run bundle install repeatedly.
How it works
bundle-depot fetch
bundle install --path .bundle/depot/current
bundle-depot store
This will:
- Create a SHA2 hash from the project's
Gemfile.lock(e.g. 314ff159) - If required, a folder
.bundle/depot/cache/314ff159is created. This is the local cache. - A remote location is checked for a file
314ff159.tar.gz. If available it is downloaded and unpacked. - A symlink is managed to point from
.bundle/depot/currentto.bundle/depot/cache/314ff159 bundle installis installing gems when both caches are cold. Otherwise, does nothing \o/- Tar and zip
.bundle/depot/cache/314ff159into.bundle/depot/cache/314ff159.tar.gz - Upload
314ff159.tar.gzto the remote cache
Whenever the Gemfile changes in subsequent runs this process will repeat
itself. .bundle/depot/current will point to the cache entry that contains the
most recent bundle gems.
Shared Cache on the local machine
This can be used to setup a shared cache on the same machine by configuring the
environent variable BUNDLE_DEPOT_CACHE.
export BUNDLE_DEPOT_CACHE=/var/lib/bundle_depot
bundle-depot fetch
bundle install --path .bundle/depot/current
bundle-depot store
Instead of using .bundle/depot/cache this will then use /var/lib/bundle_depot as
a shared cache folder.
Remote Caching
When a remote store is configured this sequence will check and update a remote cache location:
export BUNDLE_DEPOT_SCP_USER=upload
export BUNDLE_DEPOT_SCP_PASS=upload
export BUNDLE_DEPOT_SCP_HOST=cache.example.com
bundle-depot fetch
bundle install --path .bundle/depot/current
bundle-depot store
In addition to checking the local cache on the file system, this will check the existance of a zipped bundle on a remote location. Currently supported is a connection via SCP.
Configuration Options
BUNDLE_DEPOT_CACHEPoint to where you want to keep your local cache. Defaults to.bundle/depot/cacheBUNDLE_DEPOT_SCP_HOSTActivates remote cache. Sets the host the cache will be uploaded to.BUNDLE_DEPOT_SCP_USERandBUNDLE_DEPOT_SCP_USERThe credentials for the SCP session.
Complete Example
#!/bin/sh
set -o errexit # abort after the first command that fails
fmt "====================================================================================\n Preparing Build Agent Environment\n====================================================================================\n"
gem install bundle_depot --bindir bin --no-rdoc --no-ri
fmt "====================================================================================\n Bundle it! \n====================================================================================\n"
export BUNDLE_DEPOT_CACHE=/var/lib/bundle_depot
export BUNDLE_DEPOT_SCP_USER=upload
export BUNDLE_DEPOT_SCP_PASS=upload
export BUNDLD_DEPOT_SCP_HOST=cache.example.com
bin/bundle-depot fetch
bundle install --path .bundle/depot/current --frozen
bin/bundle-depot store
Installation
$ gem install bundle_depot
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request