Asset fingerprint differs between servers

♀尐吖头ヾ 提交于 2020-01-14 12:37:07

问题


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

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

I'm trying to avoid pre-compiling the assets locally as a way to solve this issue (at least for now...).


回答1:


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


来源:https://stackoverflow.com/questions/20387082/asset-fingerprint-differs-between-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!