Skip to content

Instantly share code, notes, and snippets.

@coop
Created August 2, 2011 22:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save coop/1121443 to your computer and use it in GitHub Desktop.
Save coop/1121443 to your computer and use it in GitHub Desktop.
Deploy to S3 - Asset Pipeline, S3 and Heroku
namespace :deploy do
desc "Deploy to Heroku"
task :heroku do
Rake::Task["deploy:precompile_assets_and_upload_to_s3"].invoke
Rake::Task["deploy:push_heroku"].invoke
end
desc "Precompile assets and upload to s3"
task :precompile_assets_and_upload_to_s3 do
storage = Fog::Storage.new :provider => 'AWS', :aws_access_key_id => "123", :aws_secret_access_key => "123"
bucket = storage.directories.get('bucket_name')
assets_folder = bucket.files.get('assets/')
if assets_folder
assets_folder.destroy
puts "[Deleted] assets/"
end
bucket.files.create :key => 'assets/', :public => true
system "RAILS_ENV=production rake assets:precompile"
Dir.glob(File.join(Rails.root, 'public', 'assets', '*')).each do |file|
new_file = bucket.files.new :key => "assets/#{File.basename(file)}", :body => File.open(file), :public => true
if new_file.save
puts "[Uploaded] #{File.basename(file)}"
else
puts "[Failed Upload] #{File.basename(file)}"
end
end
end
desc "Push master branch to heroku remote"
task :push_heroku do
puts "[Deploying] Heroku"
`git push heroku master`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment