Deployment Capistrano编译资产错误-资产:预编译:非编译?
我的应用程序似乎已正确部署,但出现以下错误:Deployment Capistrano编译资产错误-资产:预编译:非编译?,deployment,ruby-on-rails-3.1,capistrano,Deployment,Ruby On Rails 3.1,Capistrano,我的应用程序似乎已正确部署,但出现以下错误: * executing "cd /home/deploy/tomahawk/releases/20120208222225 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile" servers: ["ip_address"] [ip_address] executing command *** [err
* executing "cd /home/deploy/tomahawk/releases/20120208222225 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["ip_address"]
[ip_address] executing command
*** [err :: ip_address] /opt/ruby/bin/ruby /opt/ruby/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
我在这里尝试过编译资产的解决方案:
在这里:
在这里:
这是我的deploy.rb:
require "bundler/capistrano"
load 'deploy/assets'
set :default_environment, {
'PATH' => "/opt/ruby/bin/:$PATH"
}
set :application, "tomahawk"
set :repository, "repo_goes_here"
set :deploy_to, "/home/deploy/#{application}"
set :rails_env, 'production'
set :branch, "master"
set :scm, :git
set :user, "deploy"
set :runner, "deploy"
set :use_sudo, true
role :web, "my_ip"
role :app, "my_ip"
role :db, "my_ip", :primary => true
set :normalize_asset_timestamps, false
after "deploy", "deploy:cleanup"
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :domain do ; end
end
end
task :after_update_code do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
首先别忘了在下面添加宝石
group :production do
gem 'therubyracer'
gem 'execjs'
end
然后在您的cap文件中,只需在更新后的代码中添加这一行即可
run "cd #{release_path}; rake assets:precompile RAILS_ENV=production "
这对我很管用;)
干杯
Gregory HORION我后来注意到capistrano无法删除旧版本,我遇到了一个错误:
*** [err :: ip_address] sudo: no tty present and no askpass program specified
我找到了有关此错误的链接:
我必须将这一行添加到部署文件中:
default_run_options[:pty] = true
这也解决了我在上面遇到的奇怪错误
官方的解释,我不明白:)
没有默认的PTY。在2.1之前,Capistrano会为它执行的每个命令请求一个伪tty。这样做的副作用是导致用户的概要文件脚本无法加载。好吧,别再这样了!从2.1开始,Capistrano不再在每个命令上请求pty,这意味着您的.profile(或.bashrc,或任何内容)将正确加载到每个命令上!但是,请注意,有些系统已报告,当未分配pty时,某些命令将自动进入非交互模式。如果您没有看到像以前一样的命令提示,如svn或passwd,您可以通过向capfile添加以下行返回到以前的行为:default_run_options[:pty]=true我也有同样的问题。我已将其添加到我的deploy.rb(用于添加选项'--trace'): 错误似乎只是注意:
*** [err :: my-server] ** Invoke assets:precompile (first_time)
...
以下是对我有效的方法: 1) 将rvm capistrano添加到您的GEM文件中 2) 在confg/deploy中,添加以下行:
require 'rvm/capistrano'
set :rvm_ruby_string, '1.9.2' # Set to your version number
3) 您可能还需要设置:rvm_type和:rvm_bin_path。请看更多细节
4) apt get/yum在服务器上安装nodejs
(请参阅我的回复。)您看到的消息是
rake资产:precompile
的输出
运行rake资产:预编译时,如何避免默认输出
解决方案是添加-q
行为和您的命令
如果您想查看,请参见下面的分析:
# :gem_path/actionpack/lib/sprockets/assets.rake
namespace :assets do
# task entry, it will call invoke_or_reboot_rake_task
task :precompile do
invoke_or_reboot_rake_task "assets:precompile:all"
end
# it will call ruby_rake_task
def invoke_or_reboot_rake_task(task)
ruby_rake_task task
end
# it will call ruby
def ruby_rake_task(task, fork = true)
env = ENV['RAILS_ENV'] || 'production'
groups = ENV['RAILS_GROUPS'] || 'assets'
args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
ruby(*args)
end
end
# :gem_path/rake/file_utils.rb
module FileUtils
# it will call sh
def ruby(*args,&block)
options = (Hash === args.last) ? args.pop : {}
sh(*([RUBY] + args + [options]), &block)
end
# it will call set_verbose_option
# and if options[:verbose] == true, it do not output cmd
# but default of options[:verbose] is an object
def sh(*cmd, &block)
# ...
set_verbose_option(options)
# ...
Rake.rake_output_message cmd.join(" ") if options[:verbose]
# ...
end
# default of options[:verbose] is Rake::FileUtilsExt::DEFAULT, which is an object
def set_verbose_option(options) # :nodoc:
unless options.key? :verbose
options[:verbose] =
Rake::FileUtilsExt.verbose_flag == Rake::FileUtilsExt::DEFAULT ||
Rake::FileUtilsExt.verbose_flag
end
end
end
# :gem_path/rake/file_utils_ext.rb
module Rake
module FileUtilsExt
DEFAULT = Object.new
end
end
# :gem_path/rake/application.rb
# the only to solve the disgusting output when run `rake assets:precompile`
# is add a `-q` option.
['--quiet', '-q',
"Do not log messages to standard output.",
lambda { |value| Rake.verbose(false) }
],
['--verbose', '-v',
"Log message to standard output.",
lambda { |value| Rake.verbose(true) }
],
在部署我的rails 3.1应用程序时,我有完全相同的功能。我想那是藏在某处,但我没看到。是不是precompile:assets:nondigest
任务记录了对stderr的警告之类的东西,而这是由capistrano收集的?说实话,这个非编译的东西有点超出了我的理解范围(仍然围绕着precompile:)-但是我把它展示给了一个朋友,他说了这个。。。“我不认为这些都是错误,我认为输出有点混乱,认为它是一个错误流,当它使用正常的输出时,只要部署完成,你应该没事,一个真正的错误停止执行嘿,伙计,我建议你不要在消息中显示你的ip,这可能会导致对你的服务器的一些攻击;)干杯!:)我得看着那复制和粘贴!
# :gem_path/actionpack/lib/sprockets/assets.rake
namespace :assets do
# task entry, it will call invoke_or_reboot_rake_task
task :precompile do
invoke_or_reboot_rake_task "assets:precompile:all"
end
# it will call ruby_rake_task
def invoke_or_reboot_rake_task(task)
ruby_rake_task task
end
# it will call ruby
def ruby_rake_task(task, fork = true)
env = ENV['RAILS_ENV'] || 'production'
groups = ENV['RAILS_GROUPS'] || 'assets'
args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
ruby(*args)
end
end
# :gem_path/rake/file_utils.rb
module FileUtils
# it will call sh
def ruby(*args,&block)
options = (Hash === args.last) ? args.pop : {}
sh(*([RUBY] + args + [options]), &block)
end
# it will call set_verbose_option
# and if options[:verbose] == true, it do not output cmd
# but default of options[:verbose] is an object
def sh(*cmd, &block)
# ...
set_verbose_option(options)
# ...
Rake.rake_output_message cmd.join(" ") if options[:verbose]
# ...
end
# default of options[:verbose] is Rake::FileUtilsExt::DEFAULT, which is an object
def set_verbose_option(options) # :nodoc:
unless options.key? :verbose
options[:verbose] =
Rake::FileUtilsExt.verbose_flag == Rake::FileUtilsExt::DEFAULT ||
Rake::FileUtilsExt.verbose_flag
end
end
end
# :gem_path/rake/file_utils_ext.rb
module Rake
module FileUtilsExt
DEFAULT = Object.new
end
end
# :gem_path/rake/application.rb
# the only to solve the disgusting output when run `rake assets:precompile`
# is add a `-q` option.
['--quiet', '-q',
"Do not log messages to standard output.",
lambda { |value| Rake.verbose(false) }
],
['--verbose', '-v',
"Log message to standard output.",
lambda { |value| Rake.verbose(true) }
],