Capistrano 编译资产错误 - 资产:预编译:非摘要?

发布于 2025-01-03 23:36:07 字数 2078 浏览 1 评论 0原文

我的应用程序似乎部署正确,但出现此错误:

      * 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

My App seems to be deploying correctly but I'm getting this error:

      * 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

I've tried solutions here for trying to compile assets: http://lassebunk.dk/2011/09/03/getting-your-assets-to-work-when-upgrading-to-rails-3-1/

And Here: http://railsmonkey.net/2011/08/deploying-rails-3-1-applications-with-capistrano/

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

Here is my 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

森罗 2025-01-10 23:36:07

首先不要忘记在你的 cap 文件中添加下面的 gem

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

,只需在你的 after_update_code 中添加这一行,

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

这对我来说效果很好;)

干杯,

Gregory HORION

first don't forget to add the gem below

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

then in your cap file just add this line in your after_update_code

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

this worked fine for me ;)

cheers,

Gregory HORION

缪败 2025-01-10 23:36:07

我有同样的问题。我已将其添加到我的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)
...

I have the same problem. I have added this to my deploy.rb (for adding option '--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

And error seems to be just notice :

*** [err :: my-server] ** Invoke assets:precompile (first_time)
...
瞳孔里扚悲伤 2025-01-10 23:36:07

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

I later noticed that capistrano wasn't able to delete old releases, I got an error:

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

I found this link regarding this error:
http://www.mail-archive.com/[email protected]/msg07323.html

I had to add this line to my deploy file:

default_run_options[:pty] = true

This also solved the weird error I was getting above.

The official explanation, which I don't understand :)

No default PTY. Prior to 2.1, Capistrano would request a pseudo-tty for each command that it executed. This had the side-effect of causing the profile scripts for the user to not be loaded. Well, no more! As of 2.1, Capistrano no longer requests a pty on each command, which means your .profile (or .bashrc, or whatever) will be properly loaded on each command! Note, however, that some have reported on some systems, when a pty is not allocated, some commands will go into non-interactive mode automatically. If you’re not seeing commands prompt like they used to, like svn or passwd, you can return to the previous behavior by adding the following line to your capfile: default_run_options[:pty] = true

等数载,海棠开 2025-01-10 23:36:07

以下是对我有用的方法:

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。请参阅此 Ninjahideout 博客,了解更多信息细节。

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

(请参阅我对此的回复 相关 Stackoverflow 问题。)

Here's what worked for me:

1) Add rvm-capistrano to your Gemfile

2) in confg/deploy, add the lines:

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

3) You may also need to set :rvm_type and :rvm_bin_path. See this Ninjahideout blog that goes into more detail.

4) apt-get/yum install nodejs on your server

(See my reply to this related Stackoverflow question.)

喜你已久 2025-01-10 23:36:07

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

The message you see is the output of rake assets:precompile .

When you run rake assets:precompile, how to avoid default output

the solution is to add -q behand your command,

analysis is below, if you want to see:

# :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) }
          ],
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文