gpt4 book ai didi

ruby-on-rails - Rails 3.2.1, Assets 在部署时预编译两次?

转载 作者:行者123 更新时间:2023-12-04 14:04:28 25 4
gpt4 key购买 nike

我有这个 Capistrano 任务:

namespace :deploy do
task :precompile, :role => :app do
run "cd #{release_path}/ && RAILS_ENV=staging bundle exec rake assets:precompile --trace"
end
end

after "deploy:finalize_update", "deploy:precompile"

我知道有 load 'deploy/assets'但我试图了解这里发生了什么。

我正在部署到 亚马逊 EC2 m1.small 实例,显然有 50% cpu 窃取时间 , 通过 top 验证.
这会导致编译 Assets 的时间增加,但请看一下:
    [23.21.xxx.xx] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p125' -c 'cd /home/ubuntu/apps/myapp-rails/releases/20120227020245/ && RAILS_ENV=staging bundle exec rake assets:precompile --trace'
** [out :: 23.21.xxx.xx] ** Invoke assets:precompile (first_time)
** [out :: 23.21.xxx.xx] ** Execute assets:precompile
** [out :: 23.21.xxx.xx] /home/ubuntu/.rvm/rubies/ruby-1.9.3-p125/bin/ruby /home/ubuntu/apps/myapp-rails/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets --trace
** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:all (first_time)
** [out :: 23.21.xxx.xx] ** Execute assets:precompile:all
** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:primary (first_time)
** [out :: 23.21.xxx.xx] ** Invoke assets:environment (first_time)
** [out :: 23.21.xxx.xx] ** Execute assets:environment
** [out :: 23.21.xxx.xx] ** Invoke environment (first_time)
** [out :: 23.21.xxx.xx] ** Execute environment
** [out :: 23.21.xxx.xx] ** Invoke tmp:cache:clear (first_time)
** [out :: 23.21.xxx.xx] ** Execute tmp:cache:clear
** [out :: 23.21.xxx.xx] ** Execute assets:precompile:primary
** [out :: 23.21.xxx.xx] ** Invoke assets:precompile:nondigest (first_time)
** [out :: 23.21.xxx.xx] ** Invoke assets:environment (first_time)
** [out :: 23.21.xxx.xx] ** Execute assets:environment
** [out :: 23.21.xxx.xx] ** Invoke environment (first_time)
** [out :: 23.21.xxx.xx] ** Execute environment
** [out :: 23.21.xxx.xx] ** Invoke tmp:cache:clear (first_time)
** [out :: 23.21.xxx.xx] ** Execute tmp:cache:clear
** [out :: 23.21.xxx.xx] ** Execute assets:precompile:nondigest
command finished in 958131ms

除了由于某种原因花在预编译 Assets 上的疯狂时间之外,我可以说它编译了两次。为什么?

我正在使用 Rails 3.2.1。
有人可以对这里发生的事情提供一些见解吗?是故意的吗?
staging.rb

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

最佳答案

load 'deploy/assets'在部署的适当部分自动为您预编译 Assets ,因此您无需定义预编译任务。您可以删除预编译任务和 after "deploy:finalize_update", "deploy:precompile" .

https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/assets.rb

编辑:默认情况下,当您将摘要设置为 true 时,Rails 将创建指纹文件和非指纹文件。它实际上并不是两次运行整个预编译任务,它只是针对每种情况运行一个任务。

如果你想完全禁用生成非指纹文件,那么你可以覆盖 assets:precompile:all任务。

Rake::Task['assets:precompile:all'].clear
namespace :assets do
namespace :precompile do
task :all do
Rake::Task['assets:precompile:primary'].invoke
# ruby_rake_task("assets:precompile:nondigest", false) if Rails.application.config.assets.digest
end
end
end

注释掉的行是这里的第 66 行:

https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/assets.rake

关于ruby-on-rails - Rails 3.2.1, Assets 在部署时预编译两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9459369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com