application.css has already been required - ruby-on-rails

Dont know what happened. i have deployed code to my server 3 times today and now i get this error.
* ←[33mexecuting "cd -- /home/deployer/loadmax/releases/20140404020322 && bund
le exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp --
/home/deployer/loadmax/shared/assets/manifest.yml /home/deployer/loadmax/releas
es/20140404020322/assets_manifest.yml"←[0m
servers: ["108.235.52.160"]
[108.235.52.160] executing command
** [out :: 108.235.52.160] rake aborted!
** [out :: 108.235.52.160] /home/deployer/loadmax/releases/20140404020322/app/a
ssets/stylesheets/application.css has already been required
** [out :: 108.235.52.160]
** [out :: 108.235.52.160] Tasks: TOP => assets:precompile:primary
** [out :: 108.235.52.160] (See full trace by running task with --trace)
←[2;37mcommand finished in 51582ms←[0m
*** [←[34mdeploy:update_code←[0m] ←[34mrolling back←[0m
* ←[33mexecuting "rm -rf /home/deployer/loadmax/releases/20140404020322; true"
←[0m
servers: ["108.235.52.160"]
[108.235.52.160] executing command
←[2;37mcommand finished in 838ms←[0m
failed: "sh -c 'cd -- /home/deployer/loadmax/releases/20140404020322 && bundle e
xec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp -- /ho
me/deployer/loadmax/shared/assets/manifest.yml /home/deployer/loadmax/releases/2
0140404020322/assets_manifest.yml'" on 108.235.52.160
Here is the line assets_manifest.yml file
---
application.css: application-cbe5df2fd54e4a120dc4a78c89b723d3.css

Apparently Ruby mines added in several files that it thought i was missing

Related

rails capistrano having problems with rake db:migrate

I just ran rake db:migrate directly on my server with no problems:
$ pwd
/var/www/vhosts/example.com/current
$ rake db:migrate
Then i tried to run it via a capistrano task and i get an error. The task and output are below. Why does rake db:migrate not work via my capistrano task?
task
namespace :deploy do
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env}"
end
end
cap deploy:run_migrations
$ cap deploy:run_migrations
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121122011144)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121122011144/Rakefile:5:in `require'
** [out :: example.com] (See full trace by running task with --trace)
command finished in 390ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate'" on example.com
EDIT
$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
$ which rails
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rails
EDIT
When i added --trace to the db migrations, it looks like it's using /usr/lib/ruby/site_ruby/1.8/rake.rb, but from the looks of this:
$ which rake
/usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake
i would have expected it to use rake at /usr/local/rvm/gems/ruby-1.9.3-p125/bin/rake rather than /usr/lib/ruby/site_ruby/1.8/rake.rb.
cap deploy's output from the deploy:run_migrations task
* executing `deploy:run_migrations'
RUNNING DB MIGRATIONS
* executing "cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] (in /var/www/vhosts/example.com/releases/20121123184358)
** [out :: example.com] rake aborted!
** [out :: example.com] no such file to load -- rubygems
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/boot.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1:in `require'
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/config/application.rb:1
** [out :: example.com] /var/www/vhosts/example.com/releases/20121123184358/Rakefile:5:in `require'
** [out :: example.com] /var/www/vhosts/famnfo.com/releases/20121123184358/Rakefile:5
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1828:in `load_rakefile'
** [out :: example.com] /usr/lib/ruby/site_ruby/1.8/rake.rb:1900:in `run'
** [out :: example.com] /usr/bin/rake:8
command finished in 422ms
failed: "sh -c 'cd /var/www/vhosts/example.com/current; rake db:migrate RAILS_ENV=production --trace'" on example.com
EDIT
output after adding #Super Engineers code
* executing `bundle:install'
* executing "ls -x /var/www/vhosts/example.com/releases"
servers: ["example.com"]
[example.com] executing command
command finished in 572ms
* executing "cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
** [out :: example.com] You are trying to install in deployment mode after changing
** [out :: example.com] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: example.com] updated Gemfile.lock to version control.
** [out :: example.com]
** [out :: example.com] You have added to the Gemfile:
** [out :: example.com] * mysql2
** [out :: example.com] * therubyracer
** [out :: example.com] * rvm-capistrano
** [out :: example.com] * passenger
** [out :: example.com]
** [out :: example.com] You have deleted from the Gemfile:
** [out :: example.com] * mysql
command finished in 999ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/vhosts/example.com/releases/20121124160218; true"
servers: ["example.com"]
[example.com] executing command
command finished in 826ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.3-p125' -c 'cd /var/www/vhosts/example.com/releases/20121124160218 && bundle install --gemfile /var/www/vhosts/example.com/releases/20121124160218/Gemfile --path /var/www/vhosts/example.com/shared/bundle --deployment --quiet --without development test'" on example.com
EDIT
Entire deploy.rb file
require 'bundler/capistrano'
require 'rvm/capistrano'
# set environment
set :rails_env, "production"
# set the ruby version
set :rvm_ruby_string, 'ruby-1.9.3-p125'
set :rvm_type, 'webadmin'
# server username and password
set :user, 'super'
set :password, 'secret'
# subversion repo username and password
set :scm, :subversion
set :scm_username, "super"
set :scm_password, 'secret'
set :svnserver, "myreposerver"
set :repository, "myrepo"
# project info
set :server, ''
set :application, "FamNFo"
set :applicationdir, '/Volumes/Macintosh HD/Users/myname/Sites/example'
role :web, "example.com"
role :app, "example.com"
role :db, "example.com", :primary => true
set :use_sudo, true
# database config
#set :migrate_env, "#{rails_env}"
# specify the rvm type. We just want to use the system wide one since we're not currently specifying gemsets for each project
set :rvm_type, :system
# where to put the files
set :deploy_to, "/var/www/vhosts/example.com"
# fixes the "sorry, you must have a tty to run sudo" issue
default_run_options[:pty] = true
# precompiles the assets
load 'deploy/assets'
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
# restart the server
task :restart, :roles => :app do
run "/etc/init.d/http restart graceful"
end
# chmod the files
task :after_update_code, :roles => [:web, :db, :app] do
run "chmod 755 #{release_path}/public -R"
end
# install new gems
desc "run bundle install and ensure all gem requirements are met"
task :install do
run "cd #{current_path} && bundle install --without=test --no-update-sources --trace"
end
# run the db migrations
task :run_migrations, :roles => :db do
puts "RUNNING DB MIGRATIONS"
run "cd #{current_path}; rake db:migrate RAILS_ENV=#{rails_env} --trace"
end
# precompile assets
task :precompile_assets do
run "cd #{release_path}; bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
end
task :start do ; end
task :stop do ; end
# restart the server
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{sudo} /etc/init.d/httpd restart graceful"
end
end
# hook to run db migrations after code update
after("deploy:update", "deploy:run_migrations")
#after("deploy:update", "deploy:precompile_assets")
after "deploy:update", "deploy:install"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup" # leave the last 5 releases only
Its because of ruby conflict. I've faced same error. You will need to use rvm/capistrano gem. I'll paste some code from my cap file which will give you some idea about how to set the ruby version while deploying.
install the gem
gem install rvm-capistrano
in you deploy.rb file add these lines
require 'bundler/capistrano'
require 'rvm/capistrano'
set :rvm_ruby_string, "ruby-1.9.3-p125"
set :rvm_type, 'webadmin'
For more information you can visit this link rvm/capistrano
The relevant error here seems to be no such file to load -- rubygems.
Quite likely it is because of multiple ruby installations on the production server.
Check out this previous solution for a similar problem : https://stackoverflow.com/a/2896596/429758
Also, this thread on the capistrano mailing list is helpful: https://groups.google.com/forum/?fromgroups=#!topic/capistrano/JzVPRbQclY4
Are you using rvm/capistrano? With that you can specify the ruby version that you want to use on the server in your capistrano recipes. I suspect that when you run capistrano it's not using your rvm setup, when you login and run the rake task, your user is setup to use the rvm ruby version.

deploy:assets:precompile Issue

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.

capistrano cannot find previous release

I just deployed an old project using my capistrano and it deployed ok but I need to rollback. When I try to roll back using the command 'cap deploy:rollback' I get this error:
[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was before_update_code)
[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was after_update_code)
* executing `deploy:rollback'
* executing `deploy:rollback:revision'
* executing "ls -x /home/<my user>/<my project>/releases"
servers: ["www.my_webserver.com"]
[www.my_webserver.com] executing command
command finished
* executing "rm /home/<my user>/<my project>/current; ln -s /home/<my user>/<my project>/releases/20121023110110 /home/<my user>/<my project>/current"
servers: ["www.my_webserver.com"]
[www.my_webserver.com] executing command
command finished
triggering after callbacks for `deploy:rollback:revision'
* executing `bundler:install'
* executing "cd /home/<my user>/<my project>/releases/20121023112609 && bundle install"
servers: ["www.my_webserver.com"]
[www.my_webserver.com] executing command
** [out :: www.my_webserver.com] bash: line 0: cd: /home/<my user>/<my project>/releases/20121023112609: No such file or directory
command finished
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2' -c 'cd /home/<my user>/<my project>/releases/20121023112609 && bundle install'" on www.my_webserver.com
If I start 'cap shell' and have a quick look I cannot find the 20121023112609 directory which it's looking for.
cap> ls -x /home/<my user>/<my project>/releases
** [out :: www.my_webserver.com] 20120418231223 20120419004108 20120421030033 20120422072111 20120422101603
** [out :: www.my_webserver.com] 20120526035027 20120526113216 20120528100439 20120528102509 20120528135335
** [out :: www.my_webserver.com] 20120604090722 20120724142113 20121008114048 20121008114947 20121008125600
** [out :: www.my_webserver.com] 20121015121531 20121015122225 20121023110110 20121023111648
I can see my latest deploy is there but it's called '20121023111648' and the previous deploy which I want to revert back to is called '20121023110110'.
It seems like there is a time difference or something?
Look at your answer here railsless-deploy
cap deploy:rollback
Run the above command for rollback.

Capistrano deployment, asset pipeline, ruby-debug not found

I'm deploying my Rails 3.2.2, Ruby 1.9.3 app with Capistrano to a Linux server. When I'm running a cap deploy I get this error:
* executing `deploy:assets:precompile'
* executing "cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["example.com"]
[example.com] executing command
[example.com] sh -c 'cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'
** [out :: example.com] rake aborted!
** [out :: example.com] cannot load such file -- ruby-debug
** [out :: example.com]
** [out :: example.com] (See full trace by running task with --trace)
command finished in 8962ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/production/releases/20120418090209; true"
servers: ["example.com"]
[example.com] executing command
[example.com] sh -c 'rm -rf /var/www/production/releases/20120418090209; true'
command finished in 176ms
failed: "sh -c 'cd /var/www/production/releases/20120418090209 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on example.com
It says, that the ruby-debug gem was not found. But ruby-debug is not inside the production group in my Gemfile:
group :development, :test do
gem "steak"
gem "linecache19", :git => "git://github.com/mark-moseley/linecache", :require => "ruby-debug"
gem "ruby-debug-base19x", "~> 0.11.30.pre4"
gem "ruby-debug19"
gem "rails_best_practices"
gem "ruby_parser"
gem "reek"
gem "flog"
gem "jslint_on_rails", :git => "git://github.com/psionides/jslint_on_rails"
gem "jasmine-rails"
end
Cause the error gets thrown after the rake assets:precompile command, I think it has something todo with Capistrano and the load 'deploy/assets' call inside my Capfile:
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['config/deploy/recipes/*.rb','vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
When I remove this line, everything deploys fine, but (of course) the assets aren't found in production. And, if I run bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile directly on the server (inside the app dir) I get the same error.
So what should I do?
ruby-debug is obsolete. In ruby >= 1.9 you should use excellent debugger gem
see: https://github.com/cldwalker/debugger and http://railscasts.com/episodes/54-debugging-ruby-revised

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/

Resources