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/314ff159
is 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/current
to.bundle/depot/cache/314ff159
bundle install
is installing gems when both caches are cold. Otherwise, does nothing \o/- Tar and zip
.bundle/depot/cache/314ff159
into.bundle/depot/cache/314ff159.tar.gz
- Upload
314ff159.tar.gz
to 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_CACHE
Point to where you want to keep your local cache. Defaults to.bundle/depot/cache
BUNDLE_DEPOT_SCP_HOST
Activates remote cache. Sets the host the cache will be uploaded to.BUNDLE_DEPOT_SCP_USER
andBUNDLE_DEPOT_SCP_USER
The credentials for the SCP session.
Complete Example
#!/bin/sh
set -o errexit # abort after the first command that fails
fmt <<'EOF'
====================================================================================
Preparing Build Agent Environment
====================================================================================
EOF
gem install bundle_depot --bindir bin --no-rdoc --no-ri
fmt <<'EOF'
====================================================================================
Bundle it!
====================================================================================
EOF
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