由于最长时间的预编译错误,我无法部署我的 rails 项目。找到了一个清除 cap deploy 错误的脚本,但现在生产中的 Rails 抛出 500 并说 application.css 没有预编译。
这是纲要:
设置 - Ruby 2.0.0p0、Rails 3.2.13、Twitter-Bootstrap、Capistrano 部署到 VPS 与乘客和 Nginx
原始命令:
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
帽文件:
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 trying to connect to database
Database.yml 是为生产数据库设置的。数据库迁移就好了等。
目前只是跟着这个并添加了脚本: 加速资产:使用 Rails 3.1/3.2 Capistrano 部署预编译
预编译在 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 在生产中工作正常并且 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'