0
votes

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://[email protected]/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'
1
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
Can you post your application.css ? I think you have used HAML syntax in it.R Milushev
@QumaraSixOneTour I was able to fix that with this script: stackoverflow.com/questions/9016002/… 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
@QumaraSixOneTour I made an edit and posted it abovecodelitt

1 Answers

1
votes

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.