Skip to content

Instantly share code, notes, and snippets.

@kathgironpe
Created October 24, 2010 15:05
Show Gist options
  • Select an option

  • Save kathgironpe/643582 to your computer and use it in GitHub Desktop.

Select an option

Save kathgironpe/643582 to your computer and use it in GitHub Desktop.
Rake task to update cached assets and upload to s3
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