Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created April 2, 2013 22:13
Show Gist options
  • Select an option

  • Save kenmazaika/5296673 to your computer and use it in GitHub Desktop.

Select an option

Save kenmazaika/5296673 to your computer and use it in GitHub Desktop.
# 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