Synchronises Assets between Rails and S3.
Asset Sync is built to run with the new Rails Asset Pipeline feature of Rails 3.1. After you run bundle exec rake assets:precompile your assets will be synchronised to your S3 bucket, optionally deleting unused files and only uploading the files it needs to.
This was initially built and is intended to work on Heroku
Add the gem to your Gemfile
Generate the rake task and config files
rails g asset_sync:install
Configure config/environments/production.rb to use Amazon S3 as the asset host and ensure precompiling is enabled.
# config/environments/production.rb config.action_controller.asset_host = Proc.new do |source| request.ssl? 'https://my_bucket.s3.amazonaws.com' : 'http://my_bucket.s3.amazonaws.com' end
Add your Amazon S3 configuration details to
# config/asset_sync.yml development: access_key_id: 'MY_ACCESS_KEY' secret_access_key: 'MY_ACCESS_SECRET' bucket: "my_bucket" existing_remote_files: "keep" production: access_key_id: 'MY_ACCESS_KEY' secret_access_key: 'MY_ACCESS_SECRET' bucket: "my_bucket" existing_remote_files: "delete"
A rake task is installed with the generator to enhance the rails precompile task by automatically running after it:
# lib/tasks/asset_sync.rake Rake::Task["assets:precompile"].enhance do AssetSync::Assets.sync end
- Write some specs
- Add some before and after filters for deleting and uploading
- Provide more configuration options
Have borrowed ideas from:
MIT License. Copyright 2011 Rumble Labs Ltd. rumblelabs.com