ruby-on-railsamazon-ec2capistranosprockets

Turbo Sprockets and capistrano


I recently added the turbo sprockets gem https://github.com/ndbroadbent/turbo-sprockets-rails3 to my rails application, I'm using capistrano to deploy to Amazon EC2.

I'm a little confused on how I can make this work. assets:precompile worked on my local machine, but on the amazon instance it didn't.

Long story short capistrano makes a new release directory for each deployment and the public/assets directory is empty, so every time it creates a new one and when running assets:precompile it precompiles all of the assets.

Should I precompile localy and add them to git or copy the public/assets directory from the last deployment before capistrano runs assets:precompile?

What would be the cleanest/best practice solution?

Or should I keep the compiled assets in a shared directory?


Solution

  • The simplest solution I could think of is using the shared/assets directory to store my assets and make a symbolic link to the the release public/assets directory before the assets are being compiled .

     task :assets_precompile do
       run "ln -s #{shared_path}/assets #{release_path}/public/assets"
       run "cd #{release_path} && RAILS_ENV=production bundle exec rake assets:precompile"
     end
    

    Edit: Anjan pointed out that if you use deploy:assets ( If you have load 'deploy/assets' in your Capfile ) this is done by default so that's a cleaner solution .