Deploying bundled applications
Before deploying an app that uses Bundler, Add your
Gemfile
and Gemfile.lock to source control, but ignore the
.bundle folder, which is specific to each machine.
$ echo ".bundle" >> .gitignore
$ git add Gemfile Gemfile.lock .gitignore
$ git commit -m "Add Bundler support"
Once you have done that, there are two ways to deploy using Bundler:
manually or automatically.
Manual deployment
In your deploy script, after updating to the latest code, install your bundle to thevendor/bundle
directory, ensuring all your dependencies are met.
$ bundle install --deployment
Start your application servers as usual, and your application will use your bundled environment with the exact same gems you use in development.
If you have run bundle package, the cached
gems will be used automatically.
Automatic deployment with Capistrano
To pull in the Bundler Cap task, just add this to your
deploy.rb file:
require 'bundler/capistrano'
That's it! Running
cap deploy will now automatically run
bundle install on the remote server with deployment-friendly
options. A list of options that can be changed is available in the help
for the cap task. To see it, run cap -e bundle:install.
Automatic deployment with Vlad
There is a default Vlad task available. To make it available, add this line to the Vladdeploy.rb.
require 'bundler/vlad'
Once you have done that, the
vlad:bundle:install task will be
available for use. Make sure it is run as part of your deploy. For example:
task "vlad:deploy" => %w[
vlad:update vlad:bundle:install vlad:start_app vlad:cleanup
]
After deploying
Make sure to usebundle exec to run any executables
from gems in the bundle
$ bundle exec rake db:setup
Alternatively, you can use the
Learn More: Executables
--binstubs option on the
install command to generate executable binaries that can be used instead of
bundle exec.
Heroku
When you deploy to Heroku, Bundler will be run automatically as long as a Gemfile is present. If you check in your Gemfile.lock, Heroku will run`bundle install --deployment`. If you want to exclude certain groups using the --without option, you need to use `heroku config`.
$ heroku config:add BUNDLE_WITHOUT="test development" --app app_name
Edit this document on GitHub if you caught an error or noticed something was missing.