Capistrano编译资产错误 - 资产:预编译:非文化?

时间:2012-02-08 22:44:10

标签: 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 :: ip_address] /opt/ruby/bin/ruby /opt/ruby/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets

我在这里尝试过尝试编译资产的解决方案:http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/

在这里:http://railsmonkey.net/2011/08/deploying-rails-3-1-applications-with-capistrano/

在这里:http://dev.af83.com/2011/09/30/capistrano-rails-3-1-assets-can-be-tricky.html

这是我的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

5 个答案:

答案 0 :(得分:7)

首先不要忘记添加下面的宝石

group :production do
 gem 'therubyracer'
 gem 'execjs'
end

然后在你的cap文件中,只需在after_update_code

中添加这一行
run "cd #{release_path}; rake assets:precompile RAILS_ENV=production "

这对我来说很好;)

欢呼,

Gregory HORION

答案 1 :(得分:2)

我有同样的问题。我已将此添加到我的deploy.rb中(用于添加选项'--trace'):

namespace :deploy do
  namespace :assets do
    task :precompile, :roles => :web, :except => { :no_release => true } do
      run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} RAILS_GROUPS=assets assets:precompile --trace"
    end
  end
end

错误似乎只是注意:

*** [err :: my-server] ** Invoke assets:precompile (first_time)
...

答案 2 :(得分:1)

我后来注意到capistrano无法删除旧版本,我收到了一个错误:

*** [err :: ip_address] sudo: no tty present and no askpass program specified

我发现此链接有关此错误: http://www.mail-archive.com/capistrano@googlegroups.com/msg07323.html

我必须将此行添加到我的部署文件中:

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

答案 3 :(得分:1)

这对我有用:

1)将rvm-capistrano添加到您的Gemfile

2)在confg / deploy中,添加以下行:

require 'rvm/capistrano'
set :rvm_ruby_string, '1.9.2' # Set to your version number

3)您可能还需要设置:rvm_type和:rvm_bin_path。请参阅更详细的this Ninjahideout blog

4)apt-get / yum在您的服务器上安装nodejs

(请参阅我对此related Stackoverflow question的回复。)

答案 4 :(得分:0)

您看到的消息是rake assets:precompile的输出。

运行rake assets:precompile时,如何避免默认输出

解决方案是添加-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) }
          ],