由于最长时间的预编译错误,我无法获得部署我的rails项目的上限。找到一个清除了cap部署错误的脚本,但生产中的NOW Rails抛出了500并且说application.css没有预编译。
这是纲要:
设置 - Ruby 2.0.0p0,Rails 3.2.13,Twitter-Bootstrap,Capistrano使用Passenger和Nginx部署到VPS
原始命令:
cap deploy
错误:
* 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
我的deploy.rb
文件:
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包括:
config.assets.initialize_on_precompile = false
根据StackOverflow上的说明:rake assets:precompile attempting to connect to database
Database.yml是为生产数据库设置的。数据库迁移得很好等。
目前只是按照这个并添加了脚本: Speed up assets:precompile with Rails 3.1/3.2 Capistrano deployment
预编译适用于VPS,并使用--trace:
进行本地运行rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
它部署得很好,但现在我的应用程序正在提供“我们很抱歉,但是出了点问题。”我的production.log给了我这个错误:
ActionView::Template::Error (application.css isn't precompiled):
4: %meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
应用程序/资产/样式表/ 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);
}
编辑 - 显示新错误: 由于某种原因现在它甚至没有达到这一点,我的production.log文件显示了这个,即使rake db:migrate in production工作正常,database.yml也正确:
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'
答案 0 :(得分:1)
我建议将您的css代码从清单文件application.css
移到(例如)custom.css.scss
。在清单文件中,您必须声明要在应用程序中使用的css
资产,如下所示:
*= require_self
*= require your_assets
有关资产管道管理的更多详细信息,请参阅this Rails Guide。