Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset fingerprint differs between servers

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

like image 218
steakchaser Avatar asked Nov 12 '22 17:11

steakchaser


1 Answers

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
like image 66
steakchaser Avatar answered Dec 11 '22 03:12

steakchaser