【问题标题】:Capistrano compile assets error - assets:precompile:nondigest?Capistrano 编译资产错误 - 资产:预编译:非摘要?
【发布时间】:2012-02-08 22:44:09
【问题描述】:

我的应用似乎部署正确,但我收到此错误:

      * 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

【问题讨论】:

  • 我在部署我的 rails 3.1 应用程序时完全一样。我认为这隐藏在某处的sprockets rake task 中,但我没有看到。会不会是 precompile:assets:nondigest 任务向 stderr 或其他东西记录了警告,而这是被 capistrano 拾取的?
  • 老实说,这个非摘要的东西有点超出我的理解范围(我仍然在预编译:) - 但我把这个给朋友看了,他说......“我认为这些根本不是错误我认为输出以某种方式搞砸了,认为它是一个错误流,当它使用正常输出时,只要部署完成你应该没问题,真正的错误会停止执行

标签: deployment ruby-on-rails-3.1 capistrano


【解决方案1】:

首先别忘了在下面添加宝石

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

然后在你的 cap 文件中添加这一行到你的 after_update_code

run "cd #{release_path}; rake assets:precompile RAILS_ENV=production "

这对我来说很好;)

干杯,

格雷戈里·霍瑞恩

【讨论】:

  • 嘿伙计,我建议你不要在消息中显示你的 ip,这可能会导致对你的服务器的一些攻击 ;) 干杯
  • 糟糕! :) 必须注意复制和粘贴!
【解决方案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)
...

【讨论】:

    【解决方案3】:

    我后来注意到 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

    【讨论】:

      【解决方案4】:

      这对我有用:

      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的回复。)

      【讨论】:

        【解决方案5】:

        您看到的消息是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) }
                  ],
        

        【讨论】:

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