Skip to content

Instantly share code, notes, and snippets.

@kerrizor
Created January 19, 2011 01:00
Show Gist options
  • Save kerrizor/785481 to your computer and use it in GitHub Desktop.
Save kerrizor/785481 to your computer and use it in GitHub Desktop.
Rake task to build sitemap and deploy to S3
desc "build and deploy sitemap"
task :refresh_sitemap => :environment do
s3_credentials = YAML.load_file("#{Rails.root.to_s}/config/amazon_s3.yml")[Rails.env].symbolize_keys!
# builds the sitemap and deploys to S3 without notifying search engines
Rake::Task["sitemap:refresh:no_ping"].invoke
AWS::S3::Base.establish_connection!(
:access_key_id => s3_credentials[:access_key_id],
:secret_access_key => s3_credentials[:secret_access_key]
)
Dir.glob("tmp/*xml.gz").each do |f|
filename = File.join(Rails.root, f)
AWS::S3::S3Object.store(File.basename(filename), open(filename), s3_credentials[:bucket], :access => :public_read)
puts " [uploaded to S3:#{s3_credentials[:bucket]}]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment