I was heavily struggling with my Capistrano Setup, when my Hoster migrated the server:
Capistrano3 deploy fails after migrating the server
One thing I ran into that used to work just fine on the old machine and now seems to be a mess is bundler:
I could successfully run bundler through Capistrano:
cap staging bundler:install
This resulted in the following command on the server
/usr/bin/env bundle install --binstubs \
/var/www/mydomain.com/subdomains/dev/shared/bin \
--path /var/www/mydomain.com/subdomains/dev/shared/bundle \
--without development test \
--deployment
But now when I ran my server cap staging deploy:start_passenger which results in the following:
/usr/bin/env passenger start --socket tmp/passenger.socket -e staging -d
Then I got the error in my log file, that Rake was missing:
Could not find rake-10.2.2 in any of the sources (Bundler::GemNotFound)
<pre> /var/www/mydomain.com/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/spec_set.rb:92:in `block in materialize'
What is very weird, is the fact that the ruby version 2.1.2(the one I really use) shows up with 2.1.0. I have no visible reference to2.1.0` in my project, and my Gemfile contains:
ruby '2.1.2'
Since RBENV is used on the server I can run rbenv versions which shows me:
system
* 2.1.2 (set by /var/www/mydomain.com/.rbenv/version)
So where does that weird 2.1.0 come from and how can I make sure that my server has all the dependencies it requires.
I finally managed to deploy my application on the new server.
These steps were required to do it. However since I fought with it for a few hours some of it might be redundant:
gem install bundler && rbenv rehash: This is required since bundler is one of the gems that I need outside of the Rails App context in terms of dependencies.
Another one is gem install passenger && rbenv rehash
I am now using https://github.com/capistrano/rbenv but for this I had to wipe RVM from my system, which was a step I wasn't too enthusiastic of doing.
I had to make sure the current symlink was created so I added this to the deploy.rb
after 'deploy:set_current_revision', 'deploy:symlink:release'
I had to delete some of the shared directories:
rm -fr bin
rm -fr shared/bundle/
rm -fr bundle
Related
I'm setting up the staging and production server on Ubuntu, deploy with Capistrano. Both server has pretty much the same setup. But for for some reason. I can access console on production server with rails c produciton. But when I try to access console on staging server using rails c staging
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0
Try: sudo apt-get install <selected package>
The only way to access console on my staging server is to do
bundle exec rails console staging
On staging
the rvm seems to be correct, I can see the ruby version I'm using.
the gemset that the application use is there.
the application is running fine. Just can't access console with 'rails c'
But for some reason, I can't access console with rails c. Any idea how to solve this issue?
I guess you didn't install rails globally. First, check your rails version you are currently using by bundle exec rails -v. Then, install rails globally by gem install rails -v <version>. This should solve your issue.
Run bundle install only makes rails available inside bundler. In most cases, this should be enough, because bundler helps prevent headaches of version conflicts.
A couple of questions to understand better the situation...
Have you tried running bundle install for the current ruby version set on rvm for that application on that server?
Have you updated the gems for another application/branch? sometimes that happens because the rails c command uses the latest gems available and bundle exec... locates and uses the gems tied to the Gemfile.lock.
The application should run fine because it uses the gems that the Gemfile.lock has listed.
I'm trying to make a new rails application with a intent not to install gems as system gem as possible.
At first I installed bundler as system gem, made a Gemfile which specified only rails and executed 'bundle install'. (In my opinion, bundler is OK to be a system gem...)
mkdir -p /opt/rails/rails_app
cd /opt/rails/rails_app
gem install bundler
bundle init
cp Gemfile /tmp
sed 's/#gem rails/gem rails/' /tmp/Gemfile > Gemfile
bundle config build.nokogiri --use-system-libraries
bundle install --path vendor/bundle
Rails was installed as a 'local gem' which is limitted within /opt/rails/rails_app.
Then I tried to make a rails application by 'rails new'.
bundle exec rails new . --skip-bundle
This caused replacing the Gemfile, so a message was shown like this.
Overwrite /opt/rails/rails_app/Gemfile? (enter "h" for help) [Ynaqdh]
Usually what should be done is only type 'y'. However, this time, I want to do that automatically for making a vagrant's provision script.
So I tried expect but it never worked. All results were either timeout or syntax error:
expect -c "
spawn bundle exec rails new . --skip-bundle --quiet
expect \"Overwrite /opt/rails/rails_app/Gemfile? (enter \"h\" for help) \[Ynaqdh\] \"
send \"y\r\"
"
I couldn't find where is wrong in this code and other solutions than using expect.
It looks like there is a skip_gemfile option in the rails generator
You can use bundle install --path [directory] to install you gems locally inside your app. Typicall you would use './vendor/bundle' as your directory.
I am working with Heroku on a win 7 - 32 bit system where I don't have admin privileges.
I have downloaded and installed the heroku toolbelt following http://community.webfaction.com/questions/11803/heroku-toolbelt with
cd ~
curl http://assets.heroku.com/heroku-client/heroku-client.tgz | tar zx
export PATH=$HOME/heroku-client/bin/:$PATH
following Leo's advice ,I've added ruby to the windows path to fix this
Now when I run:
$ heroku run bash --app MYAPP
I get:
f:/heroku-client/lib/heroku/updater.rb:164:in `spawn': Exec format error - "m:/heroku-client/bin/heroku" update (Errno::ENOEXEC)
from f:/heroku-client/lib/heroku/updater.rb:164:in `background_update!'
from f:/heroku-client/lib/heroku/updater.rb:144:in `inject_libpath'
from f:/heroku-client/bin/heroku:19:in `<main>'
I have added to the windows env variable path:
F:/heroku-client/bin/;f:/heroku-client/lib/heroku/
How can I fix this?
I had the same issues initially with ROR on Windows. (Everyone suggested me to move to LINUX/UNIX)
Still I managed to install it on Windows. Rather than installing the Heroku Toolbet (which breaks ruby and rails which is already installed) install the heroku gem along with foreman gem.
gem install heroku
gem install foreman
Then u can use it easily.
Install the Windows Heroku Toolbelt. It's self-contained and should work out of the box for you.
I'm a new user to Capistrano and using it to deploy a rails 3.1 app. There seems to be an issue with gem installation on the remote server.
I have the following questions:
It looks like cap runs bundle install on the gemfile? Are there any dependencies for this to work successfully? I have rvm and bundler on my server. Does it need rails installed already?
I have manually set the bundle_cmd in my deploy.rb like this:
set :bundle_cmd, '/usr/local/rvm/gems/ruby-1.9.2-p290/bin/bundle'
Should this be correct?
Is there a way to have confirmation on a cap deploy that ALL the required gems are there? Or what is the best way to debug a failed bundle install on the remote server? Can you call something like cap gem-list; was hoping something like cap invoke=gem list would do it but doesn't look like it.
Edit #1
I'm getting the following error:
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd /data/sites/myserver/apps/myapp/releases/20111204181321 && bundle install --gemfile /data/sites/myserver/apps/myapp/releases/20111204181321/Gemfile --path /data/sites/myserver/apps/myapp/shared/bundle --deployment --quiet --without development test'" on 173.230.xxx.xxx
If I go into a previous release, and run bundle install, it says that everything installed correctly which it didn't.
It says:
Your bundle is complete! It was installed into /data/sites/myserver/apps/myapp/shared/bundle
but if I go in there, there is nothing other than the ruby 1.9.1 which to the best of my knowledge I didn't install (using ruby 1.9.2-p290)
Is there a way in capistrono to specify it not to delete the deployed release so that I can debug that explicitly? Shoud I need to hardcode the path to my bundler in my deploy.rb script?
thx again
EDIT 2
If I go into the current release at:
/data/sites/myserver/apps/myapp/current
and run:
$ which bundle
/usr/local/rvm/gems/ruby-1.9.2-p290/bin//bundle
I get:
$ bundle install
/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0,rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /usr/local/rvm/gems/ruby-1.9.2-p290/bin/bundle:18:in `<main>'
You dont need to have rails installed already, but I do think that you need to have bundler installed. gem install bundler
You can use RVM and bundler integration from capistrano. In that case you dont have to set the path to bundler.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
require "bundler/capistrano" # Load RVM's capistrano plugin.
set :rvm_type, :system
set :rvm_ruby_string, '1.9.2#gemset_name'
You can use 'cap shell' to run commands through Capistrano on the server. You could use this to check the installation of all your gems. Use cap -T to see all possibilities.
On a side note, do you really need rvm gemsets for your app? I use RVM to install and update my rubies on my production server, but I let Bundler handle the separation of my gems. Since the default bundler settings in production put all your gems in vendor/bundle, this already separates your gems from each other. This works great with Capistrano too.
See a similar question and answer here. Some more information a capistrano/bundler/rvm/passenger setup can be find in this tutorial.
During capistrano deployment of a Rails3 app, I want my server to install gems, using Gemfile.lock, every time I deploy. And since my server does not have rvm and all.. All gems should be installed as system gems.
To install system gems, we need to put sudo gem install anygem or for bunder, we need to give command sudo bundle install inside our current directory of capistrano deployment structure.
Everytime, I deploy, my deployment breaks at the gems installation process. I need sudo bundle install to run. For that, I need a deployment hook for capistrano. The prebuilt ones that are supplied by bundler gem itself is not working for me. My confusion boils down to these three questions.
When should I invoke the sudo bundle install command in the deployment process - i mean after which capistrano task ?
For running sudo commands using capistrano, what declarations I should specify in my cap file ? Note - i already have pushed my public key as authorized keys in my server.
How should the bundle install hook be written in the cap file ?
Please help.
Adding require "bundler/capistrano" to your deploy.rb should just work. It should declare a folder to install gems to that do not require sudo access, regardless of rvm.
Is that still failing for you?
If you run bundle install --deployment you shouldn't need sudo access as the gems should be installed to vendor/bundle in your app rather than to the system itself.
i use that in my deploy.rb:
require "bundler/capistrano"
... deploy recipe
namespace :bundle do
desc "Install bundles into application"
task :install, :roles => [:app] do
run "cd #{current_path} && LC_ALL='en_US.UTF-8' bundle install --deployment --without test"
end
end
Then after normal deploy i run "cap bundle:install"
note: Using UTF-8 to prevent ruby1.9 ASCII chars problems.