The fingerprint of an asset varies between servers

I am deploying rails 3.2.14 application on 2 different servers with a load balancer in front of them. Assets are currently precompiled on the server (via capistrano deployment).

For some reason, the fingerprint from the application.js file is different between the two servers. The source file is identical. IF I remove //= require_tree .from application.js then they both magically have the same fingerprint.

I came across several posts that mention this problem but never touch the root cause:

I am trying to avoid pre-compiling assets locally as a way to solve this problem (at least for now ...).

+4
source share
1 answer

I was not able to easily get around this problem (i.e. I didn’t want to fully open the asset tree in my application.js application), so I ended up redefining the task deploy:assetsto compile the assets locally and clicking on 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
+1
source

All Articles