Created
April 2, 2013 22:13
-
-
Save kenmazaika/5296673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # asset_sync gem seems to be incompatible with Rails4. This is | |
| # a very bare-bones s3 asset sync script. | |
| # RAILS_ENV=development bundle exec rake assets:upload_to_s3 | |
| namespace :assets do | |
| task :upload_to_s3 => :environment do | |
| require 'aws-sdk' | |
| config = YAML.load(File.open(Rails.root.join("config", "s3.yml")))[Rails.env.to_s] | |
| AWS.config(config) | |
| s3 = AWS::S3.new | |
| b = s3.buckets[config['asset_sync_bucket']] | |
| Dir['public/assets/*'].each do |file| | |
| basename = file.gsub(/\Apublic\/assets\//, "") | |
| # Grab prefix, strip trailing, and leading slashes. | |
| prefix = Rails.application.config.assets.prefix.gsub(/\A\/|\/\Z/, '') | |
| o = b.objects["#{prefix}/#{basename}"] | |
| o.write(:file => file, :acl => :public_read) | |
| puts "Uploaded #{file} to: #{o.public_url}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment