Created
March 8, 2011 18:53
-
-
Save gmgent/860764 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
| #!/usr/bin/env ruby | |
| require file.dirname(__FILE__) + /../config/environment' | |
| require 'aws/s3' | |
| require 'progressbar' | |
| #set up S3 config connect | |
| config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] | |
| bucket = config['bucket_name'] | |
| AWS::S3::Base.establish_connection!( | |
| :access_key_id => config['access_key_id'], | |
| :secret_access_key_id => config['secret_access_key_id'] | |
| ) | |
| files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png}')) | |
| #set up progress bar | |
| progressbar = ProgressBar.new('Uploading...', files.size) | |
| files.each do |file| | |
| unless File.directory?(file) | |
| #create an object key from the file name and revision | |
| key = file.gsub(/.*public\//, "#{REVISION}/") | |
| #upload to S3 | |
| #TODO set the right headers for gzipped objects | |
| AWS::S3::S3Object.store( | |
| key, open(file), bucket, | |
| :access => :public_read, :expires => 1.year.from_now | |
| ) | |
| #increment progressbar | |
| progressbar.inc | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment