服务器之间的资产指纹不同 [英] Asset fingerprint differs between servers
问题描述
我将Rails 3.2.14应用程序部署到2台不同的服务器上,并在它们前面安装了负载均衡器.目前正在通过Capistrano部署在服务器上预编译资产.
I am deploying my rails 3.2.14 application to 2 different servers with a load balancer in front of them. The assets are currently being precompiled on the server (via capistrano deployment).
由于某些原因,两个服务器之间的application.js文件的指纹不同.源文件是相同的.如果我从application.js中删除//= require_tree .
,那么它们都神奇地具有相同的指纹.
For some reason the fingerprint on the application.js file is different between the two servers. The source file is identical. IF I remove the //= require_tree .
from the application.js then they both magically have the same fingerprint.
我遇到过一些提到此问题的帖子,但从未真正解决根本原因:
I've come across a few posts that mention this issue, but never really address the root cause:
- https://github.com/sstephenson/sprockets/issues/158# issuecomment-1837340
- https://github.com/rails/rails/issues/2569# issuecomment-1879181
- https://github.com/sstephenson/sprockets/issues/158#issuecomment-1837340
- https://github.com/rails/rails/issues/2569#issuecomment-1879181
我正在尝试避免在本地预先编译资产,以解决此问题(至少目前是这样).
I'm trying to avoid pre-compiling the assets locally as a way to solve this issue (at least for now...).
推荐答案
我无法轻松解决此问题(即,不想在我的application.js中完全拼出资产树),所以我最终重写了deploy:assets
任务,以在本地编译资产并推送到群集中的每台服务器.
I was unable to easily work around this issue (i.e. did not want to fully spell out the assets tree in my application.js), so I ended up overriding the deploy:assets
task to compile assets locally and push to each server in my cluster.
namespace :deploy do
namespace :assets do
desc 'Run the precompile task locally and scp to server'
task :precompile, :roles => :web, :except => { :no_release => true } do
if releases.length <= 1 || capture("cd #{latest_release} && #{source.local.log(source.next_revision(current_revision))} vendor/assets/ app/assets/ | wc -l").to_i > 0
run_locally "bundle exec rake assets:precompile"
run_locally "cd public; tar -zcvf assets.tar.gz assets"
top.upload "public/assets.tar.gz", "#{shared_path}", :via => :scp
run "cd #{shared_path}; tar -zxvf assets.tar.gz"
run_locally "rm public/assets.tar.gz"
run_locally "bundle exec rake assets:clean"
else
logger.info 'Skipping asset pre-compilation because there were no asset changes'
end
end
end
end
这篇关于服务器之间的资产指纹不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!