2
votes

I am deploying Rails app using capistrano and locally compiling assets and copying them to server using rsync. This is what happens in precompile

desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, except: { no_release: true } do
  run "rm -f #{shared_path}/assets/manifest*"
  %x{RAILS_ENV=production bundle exec rake assets:precompile}
  %x{rsync -rave "ssh -i #{ssh_options[:keys][0]}" public/assets #{user}@#{domain}:#{shared_path}}
  %x{RAILS_ENV=production bundle exec rake assets:clean}
  %x{rm -rf public/assets}
end

Assets appear fine on the server after the deploy is complete but the rails app doesn't show the latest assets files. It shows the files from the last manifest file. I removed old manifest files by running run "rm -f #{shared_path}/assets/manifest*" in capistrano but the rails app doesnt pick up the new manifest. What am I missing and how can I force it to use the latest manifest file after deploying.

2
Every come up with a solution to this? I ran into similar behavior after upgrading from Rails 3 -> 4. The hack solution is to deploy twice. Not ideal :-/ - Ryan Angilly
Would also love to know if someone found a solution to this problem - xdotcommer
Same issue here. I've tried upgrading to the latest stable sprockets (2.12.3) and then using sprockets-rails (2.2.2) instead. Also tried running assets:clean on my server in hopes that there was some sort of cache. No luck! - steakchaser
FYI - Sprockets picks the first manifest file it can find. See line 50: github.com/sstephenson/sprockets/blob/master/lib/sprockets/… - steakchaser

2 Answers

2
votes

From what I can tell:

  1. Capistrano does nothing by default to remove prior versions of the manifest file
  2. Sprockets will just pick the first one if there are multiple
  3. Having multiple manifest files breaks Cap 2's deploy:assets:update_asset_mtimes task

What you need to do is:

  1. Add a step to your precompile flow to remove the manifest.*json file
  2. Make a copy of the manifest for each release placed at the root of the release_path named assets_manifest.json. Cap 2 needs this for :clean_expired and :rollback

I was able to fix this by removing the manifest*.json file prior to the deploy:assets:symlink task. The capistrano-local-precompile gem was what clued me in on this. See the :remove_manifest task and also reference issue #3, as it's not quite right.

0
votes

FWIW we solved this problem by setting an explicit manifest in our application.rb:

config.assets.manifest = File.join('config', '.sprockets-manifest.json')