【问题标题】:Capistrano asset precompile errorCapistrano 资产预编译错误
【发布时间】:2012-07-28 23:33:41
【问题描述】:

当我使用 capistrano 推送到我的生产服务器时,我收到此错误:

executing "cd /var/www/my_app/releases/20120731082050 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["my_app.com"]
[my_app.com] executing command
*** [err :: my_app.com] /usr/bin/ruby1.9.1 /var/www/my_app/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
*** [err :: my_app.com] 
command finished in 74149ms

尽管出现错误,预编译仍然有效。我试过跑步

cd /var/www/my_app/releases/20120731082050 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile 

在服务器上它可以工作,但它会打印到控制台:

/usr/bin/ruby1.9.1 /var/www/my_app/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets

与 capistrano 输出相匹配(请注意在原始调用中添加了“nondigest”。我知道这不是致命错误,因为它仍然有效,但我将如何阻止它打印此错误?

【问题讨论】:

  • 尝试将 --trace 放在末尾以获得完整的堆栈跟踪,即: cd /var/www/my_app/releases/20120731082050 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile - -trace

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 capistrano sprockets


【解决方案1】:

我刚刚用自己的代码覆盖了deploy:assets 任务:

namespace :deploy
  task :assets do
    run "cd #{current_path} && bundle exec rake assets:precompile RAILS_ENV=#{rails_env}"
  end
end

【讨论】:

    【解决方案2】:

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

    解决方案是根据您的命令添加-q

    例如executing "cd /var/www/my_app/releases/20120731082050 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets 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) }
              ],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多