2012-02-08 159 views
8

我的應用程序似乎被正確部署,但我得到這個錯誤:Capistrano編譯資產錯誤 - 資產:預編譯:nondigest?

 * 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 
+0

部署我的rails 3.1應用程序時,我完全一樣。我認爲這是隱藏在[sprocket rake任務](https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/assets.rake)的地方,但我沒有看到它。難道預編譯:assets:nondigest'任務會向stderr或其他東西發出警告,這是capistrano拾取的嗎? – HectorMalot 2012-02-09 10:52:07

+0

爲了說實話,這個非消化的東西有點超出了我的理解範圍(仍然包裹着預編譯的頭部:) - 但是我向一位朋友展示了這一點,他說這個......「我不認爲這些錯誤在所有 我認爲輸出結果搞砸了,認爲它的錯誤流,當它使用正常的輸出,只要部署完成你應該罰款,一個真正的錯誤停止執行 – fatfrog 2012-02-09 16:28:02

回答

1

我後來注意到,Capistrano的無法刪除舊版本中,我得到了一個錯誤:

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

我發現關於此錯誤此鏈接: http://www.mail-archive.com/[email protected]/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

7

先不要忘了添加下面

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

那麼創業板的冠文件只是在你的after_update_code加入這一行

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

這個工作對我罰款;)

歡呼聲,

Gregory HORION

+4

嘿夥計,我會建議你不要顯示你的ip在你的消息中,這可能會導致一些攻擊你的服務器;)歡呼 – metakungfu 2012-02-17 09:06:11

+0

Woops!:)得看看複製和粘貼! – fatfrog 2012-02-18 04:05:03

2

我有同樣的問題。我已將此添加到我的部署中。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) 
... 
1

下面是我工作:

1)添加RVM-Capistrano酒店您在CONFG的Gemfile

2)/部署,添加行:

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。)

0

你看到的信息就是rake assets:precompile輸出。

當您運行rake assets:precompile,如何避免違約輸出

的解決方案是添加-q behand你的命令

分析如下,如果你想看到:

# :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) } 
      ],