Created
October 24, 2010 15:05
-
-
Save kathgironpe/643582 to your computer and use it in GitHub Desktop.
Rake task to update cached assets and upload to s3
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
| namespace :cache do | |
| BUCKET = 'bucketname' | |
| desc "start aws" | |
| task :aws do | |
| require 'aws/s3' | |
| AWS::S3::Base.establish_connection!( | |
| access_key_id: 'key', | |
| secret_access_key: 'secret' | |
| ) | |
| end | |
| desc "update s3" | |
| task :s3=> :aws do | |
| prefix = '' | |
| files = Dir[ | |
| "./public/stylesheets/admin_all_packaged.css", | |
| "./public/stylesheets/splash_all_packaged.css", | |
| "./public/stylesheets/all_packaged.css", | |
| "./public/javascripts/admin_all_packaged.js", | |
| "./public/javascripts/splash_all_packaged.js", | |
| "./public/javascripts/all_packaged.js" | |
| ] | |
| files.each do |f| | |
| next if File.directory?(f) | |
| puts f | |
| key = f.gsub(/\.\/public/, prefix) | |
| puts " -> %s" % key | |
| AWS::S3::S3Object.store( | |
| key, File.open(f), BUCKET, | |
| :access => :public_read, 'Cache-Control' => 'max-age=315360000' | |
| ) | |
| end | |
| end | |
| desc "cache assets and update s3 for production" | |
| task :production do | |
| Rake::Task['asset:packager:delete_all'].invoke | |
| Rake::Task['asset:packager:build_all'].invoke | |
| Rake::Task['cached:s3'].invoke | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment