0

I couldn't get cap to deploy my rails project because of a precompile error for the longest time. Found a script that cleared the error on the cap deploy, but NOW Rails in production is throwing a 500 and saying application.css isn't precompiled.

Here's the rundown:

Setup - Ruby 2.0.0p0, Rails 3.2.13, Twitter-Bootstrap, Capistrano deploy to VPS with Passenger and Nginx

Original command:

cap deploy

Error:

* executing "cd -- /var/www/scotch/releases/20130320194644 && /home/deploy/.rvm/gems/ruby-2.0.0-p0@global/bin/bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile && cp -- /var/www/scotch/shared/assets/manifest.yml /var/www/scotch/releases/20130320194644/assets_manifest.yml"
servers: ["198.211.112.227"]
[198.211.112.227] executing command
** [out :: 198.211.112.227] rake aborted!
** [out :: 198.211.112.227] FATAL:  role "deploy" does not exist

My deploy.rb file:

require "rvm/capistrano"
require "bundler/capistrano"
set :bundle_cmd, "/home/deploy/.rvm/gems/ruby-2.0.0-p0@global/bin/bundle"
set :bundle_dir, "/home/deploy/.rvm/gems/ruby-2.0.0-p0/gems"

set :rvm_ruby_string, :local
set :application, "scotch"
set :user, 'deploy'
set :domain, '198.211.112.227'
set :applicationdir, "/var/www/scotch"

set :scm, 'git'
set :repository,  "ssh://deploy@198.211.112.227/var/www/scotch.git"
#set :git_enable_submodules, 1 # if you have vendored rails
set :scm_passphrase, ""
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true

# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export

# additional settings
default_run_options[:pty] = true  # Forgo errors when deploying from windows
 ssh_options[:keys] = %w(/home/user/.ssh/id_rsa)            # If you are using ssh_keysset :chmod755, "app config db lib public vendor script script/* public/disp*"set :use_sudo, false

# Passenger
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

Capfile:

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

Application.rb includes:

config.assets.initialize_on_precompile = false

Per instructions found on StackOverflow: rake assets:precompile attempting to connect to database

Database.yml is setup for production database. Database migrates just fine etc.

Currently just followed this and added the script: Speed up assets:precompile with Rails 3.1/3.2 Capistrano deployment

Precompile works on VPS and locally ran with --trace:

rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile

And it deployed fine, but now my app is serving up the "We're sorry, BUT something went wrong." and my production.log is giving me this error:

ActionView::Template::Error (application.css isn't precompiled):
4:     %meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}

app/assets/stylesheets/application.css.scss

.content {
background-color: #eee;
padding: 20px;
margin: 0 -20px; /* negative indent the amount of the padding to maintain the grid system */
-webkit-border-radius: 0 0 6px 6px;
-moz-border-radius: 0 0 6px 6px;
 border-radius: 0 0 6px 6px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.15);
 box-shadow: 0 1px 2px rgba(0,0,0,.15);
 }

EDIT- SHOWING NEW ERROR: For some reason now it doesn't even get to that and my production.log file shows this even though rake db:migrate in production works fine and database.yml is all correct:

ActiveRecord::StatementInvalid (PG::Error: ERROR:  permission denied for relation     reviews
: SELECT  "reviews".* FROM "reviews"  LIMIT 30 OFFSET 0):
app/models/review.rb:10:in `search'
app/controllers/reviews_controller.rb:6:in `index'
Community
  • 1
  • 1
codelitt
  • 366
  • 2
  • 13
  • I would suggest to create user `deployer` , not `deploy` in your `deploy.rb` file. Rake task hangs on "role 'deploy' does not exist". – R Milushev Mar 20 '13 at 22:27
  • Can you post your `application.css` ? I think you have used HAML syntax in it. – R Milushev Mar 20 '13 at 22:36
  • @QumaraSixOneTour I was able to fix that with this script: http://stackoverflow.com/questions/9016002/speed-up-assetsprecompile-with-rails-3-1-3-2-capistrano-deployment The error I'm experiencing now is the very last one at the bottom of this post. I was "showing my work" with the error at the top. – codelitt Mar 20 '13 at 22:37
  • @QumaraSixOneTour I made an edit and posted it above – codelitt Mar 20 '13 at 22:43

1 Answers1

1

I would suggest to move your css code away from the manifest file application.css into (for example) custom.css.scss . In the manifest file you have to declare css assets , which you would like to use in your application , something like this:

*= require_self
*= require your_assets

More details about asset-pipeline management you can find in this Rails Guide.

R Milushev
  • 4,295
  • 3
  • 27
  • 35
  • Now I am getting a new error from the postgres database in my production.log file. I added it to the original post above. Checked my database.yml and everything is all good there with the postgres user. It's been bouncing back between these two types of errors in one way or another all day. I am so confused. precompile and db:migrate both work in production. I'm running with --trace to make sure. It all runs locally. – codelitt Mar 20 '13 at 23:05
  • It seems your database has different owner than stated in your `database.yml`. Do you remember how have you created your database on production ? – R Milushev Mar 20 '13 at 23:09
  • Yes. "sudo apt-get install postgresql" THEN "sudo -u postgres psql postgres" THEN and set my password to exactly what is in my database.yml file "\password postgres". I checked the password on the machine and in the production database.yml file. Everything matches. Username and password. PLUS rake db:migrate in production works as well. On my deploy the migrate and seed all went well. – codelitt Mar 20 '13 at 23:13
  • Try to change the owner of your db by ssh to your server, switch user to `postgres` , then on `psql` prompt :`ALTER TABLE sequencename OWNER TO rolename;` – R Milushev Mar 20 '13 at 23:16
  • Have you made something like `CREATE DATABASE your_production_db OWNER youruser;` on your `psql` on the server? – R Milushev Mar 20 '13 at 23:18
  • It worked!!!! Thank you so much man. What ended up working was A. changing the database.yml as sudo in my deployment so it didn't keep reverting. Then creating an entirely new database. Building the schema, seeding it, and migration. It's all good now. Thank you so much – codelitt Mar 21 '13 at 00:03
  • It makes me happy, really. – R Milushev Mar 21 '13 at 06:06