deploy:assets:precompile Issue - ruby-on-rails

I am trying to deploy a rails application to the rackspace server via capistrano. I have deployed many Rails application to Rackspace and Linode server and never encountered such weird issue. The capistrano is not deploying the application and below is the log :
executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/latty39/releases/20121023165957 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["50.56.183.16"]
[50.56.183.16] executing command
** [out :: 50.56.183.16] rake aborted!
** [out :: 50.56.183.16] cannot load such file -- Date
** [out :: 50.56.183.16]
** [out :: 50.56.183.16] (See full trace by running task with --trace)
command finished in 7454ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/latty39/releases/20121023165957; true"
servers: ["50.56.183.16"]
[50.56.183.16] executing command
command finished in 2001ms
failed: "sh -c 'cd /home/deployer/apps/latty39/releases/20121023165957 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on 50.56.183.16
I have no idea why this is failing. I have almost spent 3 hours on this thing and no success so far. Have search stackoverflow and other resources but no help.
Any help to resolve the issue will be highly appreciated
Thanks

I figured it out myself. I was having a custom rake task which was requiring ruby Date Class like:
require 'Date'
Removed it and all fixed. But I do not need to figure out why requiring the date class in production throws error.

Related

How to drop to a shell during a Capistrano deployment

Occasionally, an error will occur during a Capistrano deployment that doesn't provide enough output to troubleshoot. For example:
* executing "cd /apps/my_app/releases/20121019181838 && bundle exec rake RAILS_ENV=dev RAILS_GROUPS=assets assets:precompile"
servers: ["myserver.com"]
[myserver.com] executing command
*** [err :: myserver.com] rake aborted!
*** [err :: myserver.com] Connection refused - connect(2)
*** [err :: myserver.com]
*** [err :: myserver.com] Tasks: TOP => environment
*** [err :: myserver.com] (See full trace by running task with --trace)
command finished in 2388ms
*** [deploy:update_code] rolling back
* executing "rm -rf /apps/my_app/releases/20121019181838; true"
Something went wrong during the rake task, and it looks like it probably has something to do with the DB. But in order to troubleshoot this, I would need to recreate the conditions of the deploy; alas, the conditions have been rm -rf'ed.
Is there some way to make Capistrano drop to a (Cap or bash) shell here using a before or after hook? Is there an easy way to insert a --trace onto that rake task without overriding Capistrano classes? Other ideas?
I handle situations as such in the following ways:
When I can be fast enough I simply hit CTR+Z (it 'pauses' the cap process) and then I investigate things onsite (over ssh, or the cap console).
I set the debug (cap --debug) flag when running the task - which makes cap prompt me before each remote command execution, so I can investigate the situation before/after every step.
Both ways usually are sufficient for me to handle the most situations quite quickly. Hope they will also help you.

capistrano command works on server, but not locally

I'm getting this error when running this capistrano task (my own - cap deploy:show_pointers):
* executing `deploy:show_pointers'
* executing "cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers"
servers: ["mydomain.net"]
[mydomain.net] executing command
** [out :: mydomain.net] (in /home/mydomain/public_html/site_folders/rails/releases/20120521025150)
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
command finished in 1584ms
failed: "sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers'" on mydomain.net
However when I run
sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers
manually from the same dir that capistrano logs into, it works. I have capistrano set to NOT USE sudo, so that shouldn't be the issue, but it sounds like it might be, since the above command fails with sudo. I think this is a user issue, or maybe an environment var issue. Or I'm not sure what.
Any suggestsions. This is a task that is already a rake task, but it will help me not to have to log into the server every time I run it (and about 10 more like it).
Appreciate any help on this.
manually from the same dir that capistrano logs into, it works.
That doesn't say anything, Capistrano creates a non-login tty, which means that your profile, dot-files, etc are not run.
ssh root#example.de -t /bin/sh
This is a more reliable way to compare environments to Capistrano, (although, even this is a little more full-featured than what Capistrano is using.
Given these error messages, I have a couple ideas:
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
The app can't find the rake command. Have you tried to run bundle install on the remote machine as its recommending?
Another option might be to change the command to
cd /home/mydomain/public_html/site_folders/rails/current; bundle exec rake app:show_pointers
Using bundle exec might be recommended in front of the command depending on the ruby environment on the remote servers.
#dbra over on stack overflow has pointed out that I need the full path to rake.

Error deploying to rbenv with Capistrano

I'm new to Capistrano and having trouble debugging an error. Searching suggests this error could be an environment issue of picking up the wrong version of ruby (it's almost certainly not the referenced file as it works fine in test). Using a Capistrano task to dump the ruby version everything looks fine. Running the commands directly on the server works fine, too. I'm using rbenv on the server.
The error:
* executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/happenate/releases/20120424002545 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["happenate.com"]
[happenate.com] executing command
** [out :: happenate.com] rake aborted!
** [out :: happenate.com] /home/deployer/apps/happenate/releases/20120424002545/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
** [out :: happenate.com] ...sion_store :cookie_store, key: '_happenate_session'
** [out :: happenate.com] ^
Definitely some sort of ruby environment issue. After cleaning everything up with a proper rbenv environment, the error is gone.

Why do I get failed: "sh -c 'cd /var/www/releases...'" when deploying a Rails app?

I'm deploying to a Debian 6 server, with Apache, Passenger, Ruby1.9.1
When I run "cap deploy" or "cap deploy:migrations" I get this error:
[out :: ip.address] Could not find multi_json-1.0.3 in any of the sources
** [out :: ip.address] Run `bundle install` to install missing gems.
** [out :: ip.address]
command finished in 1037ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/releases/20111208004427; true"
servers: ["ip.address"]
[ip.address] executing command
command finished in 489ms
failed: "sh -c 'cd /var/www/releases/20111208004427 && /usr/bin/rake1.9.1 RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on ip.address
Note the run bundle install to install missing gems and failed sh -c ... part.
I already tried this export PATH=/var/lib/gems/1.9.1/bin:${PATH} and tried many other possible solutions but nothing seems to work.
By the way, NO rvm.
Make sure that your config/deploy.rb file is including Bundler's capistrano tasks with this line:
require 'bundler/capistrano'
This will tell it to run bundle install after updating your code, but before it runs other tasks like rake assets:precompile.
For reference for everybody else getting the same error. Found answer: http://www.pastbedti.me/2011/06/change-path-environment-with-rails-and-capistrano/

Could not find treetop-1.4.9 in any of the sources - cap deploy:migrate

I am running into an issue when trying to run migrations from capistrano (cap deploy:migrate).
latest => /var/www/site/releases/20110108002015
* executing "cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate"
servers: ["www.site.com"]
[www.site.com] executing command
** [out :: www.site.com] (in /var/www/site/releases/20110108002015)
** [out :: www.site.com] Could not find treetop-1.4.9 in any of the sources
** [out :: www.site.com] Try running `bundle install`.
command finished
failed: "sh -c 'cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate'" on www.site.com
The facts;
Rails 3.0.0
Ruby 1.9.2 via rvm
The treetop gem is installed, and if I ssh into the remote server and run the command that capistrano is attempting manually, it works without issue.
Anyone else run into this or a similar issue?
When you ssh onto the server and run the command, is it using the same user capistrano is deploying as? Often issues like this are due to the deploy users path not including the same folders as your path might.
Try using cap shell to run the command, then you can test it under the same conditions cap is under.

Resources