I got the server with the configuration above.
This is the important part of my deploy.rb recipe:
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
require 'bundler/capistrano'
set :rvm_ruby_string, 'ruby-1.9.2-p290'
set :rvm_type, :system
set :bundle_flags, "--deployment"
set :default_environment, {
'PATH' => ENV['PATH'],
'RAILS_ENV' => ENV['RAILS_ENV']
}
set :stages, %w(staging production)
require 'capistrano/ext/multistage'
Running cap staging deploy
as is, leads to an error:
* executing "cd /mnt/data-store/project/releases/shared &&
bundle install --gemfile /mnt/data-store/project/releases/shared/Gemfile
--path /mnt/data-store/project/shared/bundle --deployment --without development test"
** [out :: localhost] The --deployment flag requires a Gemfile.lock.
Please make sure you have checked your Gemfile.lock into version control
before deploying.
... rolling back ...
failed: "env PATH=... RAILS_ENV=staging rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.2-p290' -c 'cd /mnt/data-store/project/releases/shared && bundle install --gemfile /mnt/data-store/project/releases/shared/Gemfile --path /mnt/data-store/project/shared/bundle --deployment --without development test'" on localhost
Gemfile and Gemfile.lock are in the source control. I ran bundle install
locally first to generate the .lock file. But the bundler/capistrano points to /mnt/data-store/project/releases/shared/Gemfile so I just copied manually both files there. I'm sure I'm doing it wrong here. I guess it should be copied automatically.
Executed deploy again (1) and it didn't fail on the bundle install, it even had
Your bundle is complete! It was installed into /mnt/data-store/project/shared/bundle
in the output.
BUT, one of my cap tasks executes a rake. The result of this is:
*Could not find bcrypt-ruby-3.0.1 in any of the sources
*Try running bundle install
.
Proceeding with my adventure, I discovered that once you have .bundle/config with
BUNDLE_PATH: /mnt/data-store/project/shared/bundle
It works.
I had this directory, probably created by bundler, under /mnt/data-store/releases/shared/
, so I copied manually to the rails root.
Now, rake/rails c work.
bundle show twitter
shows .../shared/bundle/ruby/1.9.1/gems/twitter-1.7.1
.
BUT, redeploying brings me back to (1), because the .bundle dir isn't there.
Concrete questions:
Thanks!
Look at this part in the deployment.rb file (Bundler code)
args = ["--gemfile #{File.join(context.fetch(:current_release), bundle_gemfile)}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
There's a key called :current_release
, this key is probably not being set correctly with Capistrano for some reason.
the :current_release
in bundler will point to the "shared" folder instead of the latest release (with the timestamp)
This is getting executed on before 'deploy:finalize_update'
.
What I would do in order to fix this is to add your own hook on this event.
before 'deploy:finalize_update', 'x:set_current_release'
And this is the actual method
task :set_current_release, :roles => :app do
set :current_release, latest_release
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With